public void given_instantiated_Sut_when_Create_is_called_without_parameters_then_valid_instance_is_returned()
        {
            // Arrange
            var unityContainer = new UnityContainer();

            unityContainer
                .RegisterTypedFactory<ISomeInstanceFactory>()
                .ForConcreteType<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_two_parameters_and_parameter_2_is_null_then_object_is_resolved_correctly()
        {
            // Arrange
            using (var unityContainer = new UnityContainer())
            {
                unityContainer
                    .RegisterTypedFactory<ITest2Factory>()
                    .ForConcreteType<TestClass2>();

                const string TestValue = "TestValue";

                unityContainer.RegisterType<ISomeService, SomeService>(new ContainerControlledLifetimeManager());

                // Act
                var factory = unityContainer.Resolve<ITest2Factory>();
                var testClass2 = factory.Create(string.Empty, null, TestValue);

                // Assert
                Assert.IsNull(testClass2.TestProperty2);
                Assert.IsEmpty(testClass2.TestProperty1);
                Assert.AreSame(TestValue, testClass2.TestProperty3);
            }
        }
        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
                    .RegisterTypedFactory<ITest2Factory>()
                    .ForConcreteType<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);
            }
        }
        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
                .RegisterTypedFactory<ITest1Factory>()
                .ForConcreteType<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_one_parameter_with_non_matching_parameter_name_then_ConstructorArgumentsMismatchException_is_thrown()
        {
            // Arrange
            var unityContainer = new UnityContainer();

            unityContainer
                .RegisterTypedFactory<ITest2Factory>()
                .ForConcreteType<TestClass2NonMatchingName>();

            const string TestValue = "TestValue";
            ISomeInstance someInstance = new SomeInstance();

            // Act
            var factory = unityContainer.Resolve<ITest2Factory>();
            factory.Create(TestValue, someInstance, string.Empty);
        }
        public void given_instantiated_Sut_when_Create_is_called_with_one_of_the_parameters_not_resolvable_then_ResolutionFailedException_is_thrown()
        {
            // Arrange
            using (var unityContainer = new UnityContainer())
            {
                unityContainer
                    .RegisterTypedFactory<ITest2Factory>()
                    .ForConcreteType<TestClass2>();

                ISomeInstance someInstance = new SomeInstance();

                // Act
                var factory = unityContainer.Resolve<ITest2Factory>();
                var testClass2 = factory.Create(null, someInstance, string.Empty);

                // Assert
                Assert.AreSame(someInstance, testClass2.TestProperty2);
                Assert.IsNull(testClass2.TestProperty1);
                Assert.AreSame(string.Empty, testClass2.TestProperty3);
            }
        }
        public void given_instantiated_Sut_when_Create_is_called_with_Type_parameter_then_Type_value_is_passed_correctly()
        {
            // Arrange
            using (var unityContainer = new UnityContainer())
            {
                unityContainer
                    .RegisterTypedFactory<ITest4Factory>()
                    .ForConcreteType<TestClass4>();

                // Act
                var factory = unityContainer.Resolve<ITest4Factory>();
                var test4 = factory.Create(typeof(decimal));

                // Assert
                Assert.AreEqual(typeof(decimal), test4.TypeParam);
            }
        }
        public void given_instantiated_Sut_when_Create_is_called_and_ArgumentException_is_thrown_by_the_constructor_then_exception_is_rethrown_unwrapped_from_ResolutionFailedException()
        {
            // Arrange
            using (var unityContainer = new UnityContainer())
            {
                unityContainer
                    .RegisterTypedFactory<ISomeInstanceFactory>()
                    .ForConcreteType<FaultyTestClass>();

                // Act
                var factory = unityContainer.Resolve<ISomeInstanceFactory>();
                factory.Create();
            }
        }
        public void given_factory_with_collection_ensure_collection_returns_correctly()
        {
            // Arrange
            using (var unityContainer = new UnityContainer())
            {
                unityContainer
                    .RegisterTypedFactory<ICollectionTestFactory>()
                    .ForConcreteType<ITest1>();

                const string TestValue = "TestValue";

                unityContainer.RegisterType<ITest1, TestClass1>("Test");

                // Act
                var factory = unityContainer.Resolve<ICollectionTestFactory>();
                var results = factory.All(TestValue);

                // Assert
                Assert.AreEqual(1, results.Count);
                Assert.AreEqual(TestValue, results.Select(x => x.TestProperty1).Distinct().Single());
            }
        }
        public void given_instantiated_Sut_when_Create_is_called_with_two_parameters_and_parameter_2_is_null_then_ArgumentNullException_is_thrown()
        {
            // Arrange
            using (var unityContainer = new UnityContainer())
            {
                unityContainer
                    .RegisterTypedFactory<ITest2Factory>()
                    .ForConcreteType<TestClass2>();

                const string TestValue = "TestValue";
                ISomeInstance someInstance = null;

                unityContainer.RegisterType<ISomeService, SomeService>(new ContainerControlledLifetimeManager());

                // Act
                var factory = unityContainer.Resolve<ITest2Factory>();
                factory.Create(string.Empty, someInstance, TestValue);
            }
        }