public void given_instantiated_Sut_when_Create_is_called_without_parameters_then_valid_instance_is_returned() { // Arrange var unityContainer = new UnityContainer(); unityContainer.RegisterAutoFactoryFor <ISomeInstance, SomeInstance>().WithoutParameters(); // Act var factory = unityContainer.Resolve <IUnityFactory <ISomeInstance> >(); var testClass = factory.Create(); // Assert Assert.IsInstanceOf <SomeInstance>(testClass); }
public void given_instantiated_Sut_when_Create_is_called_with_one_parameter_then_TestProperty1_on_resulting_TestClass_matches_specified_value() { // Arrange var unityContainer = new UnityContainer(); unityContainer.RegisterAutoFactoryFor <ITest1, TestClass1>().WithParam <string>(); const string TestValue = "TestValue"; // Act var factory = unityContainer.Resolve <IUnityFactory <string, ITest1> >(); var testClass = factory.Create(TestValue); // Assert Assert.AreEqual(TestValue, testClass.TestProperty1); }
public void given_instantiated_Sut_when_Create_is_called_with_two_parameters_then_TestProperty1_and_2_on_resulting_TestClass_matches_specified_values() { // Arrange using (var unityContainer = new UnityContainer()) { unityContainer.RegisterAutoFactoryFor <ITest2, TestClass2>().WithParams <string, ISomeInstance>(); const string TestValue = "TestValue"; ISomeInstance someInstance = new SomeInstance(); unityContainer.RegisterType <ISomeService, SomeService>(new ContainerControlledLifetimeManager()); // Act var factory = unityContainer.Resolve <IUnityFactory <string, ISomeInstance, ITest2> >(); var testClass = factory.Create(TestValue, someInstance); // Assert Assert.AreEqual(TestValue, testClass.TestProperty1); Assert.AreEqual(someInstance, testClass.TestProperty2); Assert.AreEqual(unityContainer.Resolve <ISomeService>(), testClass.InjectedService); } }