Пример #1
0
        public void GetTypeConfiguration_TwoInterfacesWithTheSameNameUsingCastleProxy_ReturnsEachCorrectly()
        {
            //Arrange
            string contextName = "testContext";
            bool   isDefault   = true;
            var    type        = typeof(NS1.ProxyTest1);
            var    service     = Substitute.For <IAbstractService>();
            var    task        = new CreateInterfaceTask(new LazyLoadingHelper());

            #region CreateTypes

            Context context = Context.Create(Substitute.For <IDependencyResolver>());
            context.Config = new Config();
            AbstractTypeCreationContext abstractTypeCreationContext1 = new TestTypeCreationContext();
            abstractTypeCreationContext1.Options = new TestGetOptions()
            {
                Type = typeof(NS1.ProxyTest1)
            };

            var configuration1 = Substitute.For <AbstractTypeConfiguration>();
            configuration1.Type = typeof(NS1.ProxyTest1);

            ObjectConstructionArgs args1 = new ObjectConstructionArgs(context, abstractTypeCreationContext1, configuration1, service);

            AbstractTypeCreationContext abstractTypeCreationContext2 = new TestTypeCreationContext();

            abstractTypeCreationContext2.Options = new TestGetOptions()
            {
                Type = typeof(NS2.ProxyTest1)
            };
            var configuration2 = Substitute.For <AbstractTypeConfiguration>();
            configuration2.Type = typeof(NS2.ProxyTest1);

            ObjectConstructionArgs args2 = new ObjectConstructionArgs(context, abstractTypeCreationContext2, configuration2, service);

            //Act
            task.Execute(args1);
            task.Execute(args2);

            #endregion

            context.GetTypeConfigurationFromType <StubAbstractTypeConfiguration>(typeof(NS1.ProxyTest1));
            context.GetTypeConfigurationFromType <StubAbstractTypeConfiguration>(typeof(NS2.ProxyTest1));


            //Act
            var config1 = context.GetTypeConfigurationFromType <StubAbstractTypeConfiguration>(args1.Result.GetType());
            var config2 = context.GetTypeConfigurationFromType <StubAbstractTypeConfiguration>(args2.Result.GetType());

            //Assert
            Assert.AreEqual(typeof(NS1.ProxyTest1), config1.Type);
            Assert.AreEqual(typeof(NS2.ProxyTest1), config2.Type);
        }
        public void InstantiageObject_AllRunnersSetup_ObjectReturned()
        {
            //Assign

            var resolver = Substitute.For <IDependencyResolver>();

            var context = Context.Create(resolver);

            var configTask = Substitute.For <AbstractConfigurationResolverTask>();
            var objTask    = Substitute.For <AbstractObjectConstructionTask>();

            resolver.ConfigurationResolverFactory.GetItems().Returns(new[] { configTask });
            resolver.ObjectConstructionFactory.GetItems().Returns(new [] { objTask });

            configTask.When(x => x.Execute(Arg.Any <ConfigurationResolverArgs>()))
            .Do(x => x.Arg <ConfigurationResolverArgs>().Result = Substitute.For <AbstractTypeConfiguration>());

            var expected = new object();

            objTask.When(x => x.Execute(Arg.Any <ObjectConstructionArgs>()))
            .Do(x => x.Arg <ObjectConstructionArgs>().Result = expected);

            var service = new StubAbstractService(context);

            var typeContext = new TestTypeCreationContext();

            typeContext.Options = new TestGetOptions()
            {
                Type = typeof(object)
            };

            //Act
            var result = service.InstantiateObject(typeContext);

            //Assert
            Assert.AreEqual(expected, result);
        }