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);
            });
        }
예제 #2
0
        public void FinalizeInstanceWhenObjIsNotScoped()
        {
            var target    = new Target();
            var activator = new ObjectActivator(
                new ContainerBuilder().Build(), new ActivatorCallContext());

            activator.InitializeInstance(target);
            activator.FinalizeInstance(target);
        }
예제 #3
0
        public void InitializeInstanceWhenObjIsScoped()
        {
            var list    = Mock.Of <IList>();
            var builder = new ContainerBuilder();

            builder.RegisterInstance(list).As <IList>();

            var target = new DependentTarget();

            var activator = new ObjectActivator(builder.Build(), new ActivatorCallContext());

            activator.InitializeInstance(target);

            Assert.AreSame(list, target.List);
        }
 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));
     }
 }