public void given_instantiated_Sut_when_Create_is_called_without_parameters_then_valid_instance_is_returned() { // Arrange var unityContainer = new UnityContainer(); unityContainer .RegisterAutoFactory<ISomeInstanceFactory, SomeInstanceFactory>() .UsingConcreteType<SomeInstance>(); // Act var factory = unityContainer.Resolve<ISomeInstanceFactory>(); 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 .RegisterAutoFactory<ITest1Factory, Test1Factory>() .UsingConcreteType<TestClass1>(); const string TestValue = "TestValue"; // Act var factory = unityContainer.Resolve<ITest1Factory>(); 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_2_and_3_on_resulting_TestClass_matches_specified_values() { // Arrange using (var unityContainer = new UnityContainer()) { unityContainer .RegisterAutoFactory<ITest2Factory, TestClass2Factory>() .UsingConcreteType<TestClass2>(); const string TestValue = "TestValue"; ISomeInstance someInstance = new SomeInstance(); unityContainer.RegisterType<ISomeService, SomeService>(new ContainerControlledLifetimeManager()); // Act var factory = unityContainer.Resolve<ITest2Factory>(); var testClass = factory.Create(TestValue, someInstance, string.Empty); // Assert Assert.AreEqual(TestValue, testClass.TestProperty1); Assert.AreEqual(someInstance, testClass.TestProperty2); Assert.AreEqual(unityContainer.Resolve<ISomeService>(), testClass.InjectedService); } }