public void FinalizeInstanceWithDependencyDefined()
        {
            ObjectActivatorTests.TestActivator <IActivatorTest, ActivatorTest>(container =>
            {
                // Arrange...
                // ... register more items into the container...
                var newBuilder = new ContainerBuilder();
                newBuilder
                .RegisterType <ActivatorWithDependencyTest>()
                .As <IDependentActivatorTest>();
                newBuilder
                .RegisterType <ObjectPortal <IDependentActivatorTest> >()
                .As <IObjectPortal <IDependentActivatorTest> >();
                // ... append new registrations to the container given by the TestActivator Action...
                newBuilder.Update(container);
                // ... still arranging...
                var activator = new ObjectActivator(container);
                var obj       = activator.CreateInstance(typeof(IDependentActivatorTest));
                activator.InitializeInstance(obj);

                // Act...
                activator.FinalizeInstance(obj);

                // Assert...
                ActivatorWithDependencyTest target = (ActivatorWithDependencyTest)obj;
                var aDependency = target.GetType().GetProperty("ADependency", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(target, null);
                Assert.IsNull(aDependency);
            });
        }
 public void CreateInstanceWithInterfaceTypeForAReadOnlyItem()
 {
     ObjectActivatorTests.TestActivator <IActivatorROTest, ActivatorROTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var result    = activator.CreateInstance(typeof(IActivatorROTest));
         Assert.IsInstanceOfType(result, typeof(IActivatorROTest));
     });
 }
 public void CreateInstanceWithInterfaceType()
 {
     ObjectActivatorTests.TestActivator <IDependentActivatorTest, ActivatorWithDependencyTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var result    = activator.CreateInstance(typeof(IDependentActivatorTest));
         Assert.IsInstanceOfType(result, typeof(IDependentActivatorTest));
     });
 }
 public void CreateInstanceOfInterfaceImplementedByAChildType()
 {
     ObjectActivatorTests.TestActivator <IChildType, ChildType>(container =>
     {
         var activator = new ObjectActivator(container);
         var obj       = activator.CreateInstance(typeof(IObjectPortal <IChildType>));
         Assert.IsInstanceOfType(obj, typeof(IObjectPortal <IChildType>));
     });
 }
 public void FinalizeInstanceForNullType()
 {
     ObjectActivatorTests.TestActivator <IActivatorTest>(container =>
     {
         var activator = new ObjectActivator(container);
         activator.FinalizeInstance(null);
         Assert.Fail("Expected an exception.");
     });
 }
 public void CreateInstanceWithConcreteType()
 {
     ObjectActivatorTests.TestActivator(container =>
     {
         var activator = new ObjectActivator(container);
         var result    = activator.CreateInstance(typeof(ActivatorTest));
         Assert.IsInstanceOfType(result, typeof(IActivatorTest));
     });
 }
        public void CreateInstanceWhenRequestedTypeIsNull()
        {
            Action obj = (() => ObjectActivatorTests.TestActivator(container =>
            {
                new ObjectActivator(container).CreateInstance(null);
            }));

            obj.Invoke();
            Assert.Fail("An exception was expected.");
        }
 public void CreateInstanceOfInterfaceNotImplementedByAnyConcreteClass()
 {
     try
     {
         ObjectActivatorTests.TestActivator(container =>
         {
             var activator = new ObjectActivator(container);
             var obj       = activator.CreateInstance(typeof(ImplementedByNobodyInDifferentAssembly));
         });
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOfType(ex, typeof(ConcreteTypeResolutionException));
     }
 }
 public void CreateInstanceOfInterfaceMappingToSeveralConcreteClasses()
 {
     ObjectActivatorTests.TestActivator <ImplementedMultipleByTypeInDifferentAssembly, ActivatorTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var obj       = activator.CreateInstance(typeof(ImplementedMultipleByTypeInDifferentAssembly));
         Assert.IsInstanceOfType(obj, typeof(ImplementedMultipleByTypeInDifferentAssembly));
     });
     ObjectActivatorTests.TestActivator <ImplementedMultipleByTypeInDifferentAssembly, ActivatorWithDependencyTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var obj       = activator.CreateInstance(typeof(ImplementedMultipleByTypeInDifferentAssembly));
         Assert.IsInstanceOfType(obj, typeof(ImplementedMultipleByTypeInDifferentAssembly));
     });
 }
 public void InitializeInstanceWithDependencyNotDefined()
 {
     try
     {
         ObjectActivatorTests.TestActivator <IDependentActivatorTest, ActivatorWithDependencyTest>(container =>
         {
             var activator = new ObjectActivator(container);
             var obj       = activator.CreateInstance(typeof(IDependentActivatorTest));
             activator.InitializeInstance(obj);
         });
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOfType(ex, typeof(IoCRegistrationException));
     }
 }
        public void CreateInstanceOfInterfaceImplementedByCommand()
        {
            ObjectActivatorTests.TestActivator <ICommandExample, CommandExample>(container =>
            {
                ApplicationContext.DataPortalActivator = new ObjectActivator(container);
                var cmd = DataPortal.Create <ICommandExample>();

                Assert.AreEqual(0, cmd.FirstValue);
                Assert.AreEqual(0, cmd.SecondValue);
                Assert.IsFalse(cmd.Result);

                cmd.FirstValue  = 100;
                cmd.SecondValue = 200;
                var result      = cmd.Execute();

                Assert.AreEqual(300, cmd.CalculationResult);
                Assert.AreEqual(100, cmd.FirstValue);
                Assert.AreEqual(200, cmd.SecondValue);
                Assert.IsTrue(cmd.Result);
                Assert.IsTrue(result);
            });
        }