public void CreateHandler_WhenInstanceIsOfCorrectType_ReturnsAHandlerThatYieldsTheInstance() { string instance = ""; var instanceHandlerFactory = new InstanceHandlerFactory(instance); var dependencyResolver = MockRepository.GenerateStub <IObjectDependencyResolver>(); var contractType = typeof(string); var objectType = typeof(string); IHandler handler = instanceHandlerFactory.CreateHandler(dependencyResolver, contractType, objectType, new PropertySet()); Assert.AreSame(instance, handler.Activate()); }
public void CreateHandler_WhenInstanceIsNotOfRequestedType_Throws() { string instance = ""; var instanceHandlerFactory = new InstanceHandlerFactory(instance); var dependencyResolver = MockRepository.GenerateStub <IObjectDependencyResolver>(); var contractType = typeof(int); // not a string as the instance is var objectType = typeof(int); var ex = Assert.Throws <RuntimeException>(() => instanceHandlerFactory.CreateHandler(dependencyResolver, contractType, objectType, new PropertySet())); Assert.AreEqual("Could not satisfy contract of type 'System.Int32' using pre-manufactured instance of type 'System.String'.", ex.Message); }