Skip to content

Instantly share code, notes, and snippets.

@michelgrootjans
Last active August 29, 2015 14:04
Agatha polymorphic RequestHandler Test
using System;
using System.Linq;
using Agatha.Common;
using Agatha.Common.InversionOfControl;
using Agatha.Common.WCF;
using Agatha.ServiceLayer;
using Agatha.StructureMap;
using Xunit;
namespace Tests.RequestProcessorTests.RequestResponse
{
public class PloymorphicRequestHandlerTests
{
private readonly IRequestProcessor processor;
public PloymorphicRequestHandlerTests()
{
IoC.Container = null;
KnownTypeProvider.ClearAllKnownTypes();
var container = Activator.CreateInstance<Container>();
var configuration = new ServiceLayerConfiguration(GetType().Assembly, GetType().Assembly, container);
configuration.Initialize();
processor = container.Resolve<IRequestProcessor>();
}
[Fact] // succeeds
public void WorksForParentRequest()
{
var responses = processor.Process(new Request[] { new ParentRequest() });
Assert.True(responses.OfType<TestResponse>().Any());
}
[Fact] // fails
public void WorksForChildRequest()
{
var responses = processor.Process(new Request[] { new ChildRequest() });
Assert.True(responses.OfType<TestResponse>().Any());
}
}
public class ParentRequest : Request{ }
public class ChildRequest : ParentRequest { }
public class TestResponse : Response {}
public class TestRequestHandler : RequestHandler<ParentRequest, TestResponse>
{
public override Response Handle(ParentRequest request)
{
return new TestResponse();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment