Ejemplo n.º 1
0
        private void DoTest()
        {
            // Create context
            XmlObjectFactory objectFactory = this.LoadContext();

            if (objectFactory == null)
            {
                // Context was invalid
                return;
            }

            // Validate values
            RabbitAdmin admin;

            if (StringUtils.HasText(this.adminObjectName))
            {
                admin = objectFactory.GetObject <RabbitAdmin>(this.adminObjectName);
            }
            else
            {
                admin = objectFactory.GetObject <RabbitAdmin>();
            }

            Assert.AreEqual(this.expectedAutoStartup, admin.AutoStartup);
            Assert.AreEqual(objectFactory.GetObject <IConnectionFactory>(), admin.RabbitTemplate.ConnectionFactory);

            if (this.initialisedWithTemplate)
            {
                Assert.AreEqual(objectFactory.GetObject <RabbitTemplate>(), admin.RabbitTemplate);
            }
        }
        public void RedisListener_DITest()
        {
            var testObject = _objectFactory.GetObject <IListener>(ListenerName);

            Assert.IsNotNull(testObject);
            Assert.That(testObject.GetType(), Is.EqualTo(typeof(RedisListener)));
        }
        public void MultiplePatterns()
        {
            IObjectFactory iof     = new XmlObjectFactory(new ReadOnlyXmlTestResource("RegularExpressionSetterTests.xml", GetType()));
            IPerson        advised = (IPerson)iof.GetObject("SettersAndReturnsThisAdvised");

            // Interceptor behind regexp advisor
            NopInterceptor nop = (NopInterceptor)iof.GetObject("NopInterceptor");

            Assert.AreEqual(0, nop.Count);

            int newAge = 12;

            // Not advised
            advised.Exceptional(null);
            Assert.AreEqual(0, nop.Count);

            // This is proxied
            advised.ReturnsThis();
            Assert.AreEqual(1, nop.Count);

            // Only setter is advised
            advised.SetAge(newAge);
            Assert.AreEqual(2, nop.Count);

            Assert.AreEqual(newAge, advised.GetAge());
            Assert.AreEqual(2, nop.Count);
        }
Ejemplo n.º 4
0
        public void PrototypeInstancesAreIndependent()
        {
            IObjectFactory objectFactory = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTests.xml", GetType()));
            // Initial count value set in object factory XML
            int INITIAL_COUNT = 10;


            // Check it works without AOP
            ISideEffectObject raw = (ISideEffectObject)objectFactory.GetObject("prototypeTarget");

            Assert.AreEqual(INITIAL_COUNT, raw.Count);
            raw.doWork();
            Assert.AreEqual(INITIAL_COUNT + 1, raw.Count);
            raw = (ISideEffectObject)objectFactory.GetObject("prototypeTarget");
            Assert.AreEqual(INITIAL_COUNT, raw.Count);

            // Now try with advised instances
            ISideEffectObject prototype2FirstInstance = (ISideEffectObject)objectFactory.GetObject("prototype");

            Assert.AreEqual(INITIAL_COUNT, prototype2FirstInstance.Count);
            prototype2FirstInstance.doWork();
            Assert.AreEqual(INITIAL_COUNT + 1, prototype2FirstInstance.Count);

            ISideEffectObject prototype2SecondInstance = (ISideEffectObject)objectFactory.GetObject("prototype");

            Assert.IsFalse(prototype2FirstInstance == prototype2SecondInstance, "Prototypes are not ==");
            Assert.AreEqual(INITIAL_COUNT, prototype2SecondInstance.Count);
            Assert.AreEqual(INITIAL_COUNT + 1, prototype2FirstInstance.Count);
        }
        public void Serialization()
        {
            IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("RegularExpressionSetterTests.xml", GetType()));
            IPerson        p   = (IPerson)iof.GetObject("SerializableSettersAdvised");
            // Interceptor behind regexp advisor
            NopInterceptor nop = (NopInterceptor)iof.GetObject("NopInterceptor");

            Assert.AreEqual(0, nop.Count);

            int newAge = 12;

            // Not advised
            Assert.AreEqual(0, p.GetAge());
            Assert.AreEqual(0, nop.Count);

            // This is proxied
            p.SetAge(newAge);
            Assert.AreEqual(1, nop.Count);
            p.SetAge(newAge);
            Assert.AreEqual(newAge, p.GetAge());
            // Only setter fired
            Assert.AreEqual(2, nop.Count);

            // Serialize and continue...
            p = (IPerson)SerializationTestUtils.SerializeAndDeserialize(p);
            Assert.AreEqual(newAge, p.GetAge());
            // Remembers count, but we need to get a new reference to nop...
            nop = (SerializableNopInterceptor)((IAdvised)p).Advisors[0].Advice;
            Assert.AreEqual(2, nop.Count);
            Assert.AreEqual("SerializableSettersAdvised", p.GetName());
            p.SetAge(newAge + 1);
            Assert.AreEqual(3, nop.Count);
            Assert.AreEqual(newAge + 1, p.GetAge());
        }
Ejemplo n.º 6
0
        public void Write()
        {
            IResource      input   = new FileSystemResource("Objects.xml");
            IObjectFactory factory = new XmlObjectFactory(input);
            //是否包含以某个名称命名的对象
            var isContainsObject = factory.ContainsObject("aaaa");
            //返回以指定名称命名的对象
            var objectA = factory.GetObject <IDao>("dao");
            var objectB = factory.GetObject("dao", typeof(IDao));
            //索引器返回以指定名称命名的对象
            var objectC = factory["dao"] as IDao;
            //是否为单例模式
            var isSingleton = factory.IsSingleton("dao");
            //获取别名
            IList <string> aliases = factory.GetAliases("dao");

            factory.ConfigureObject(new TestInject(), "dao");



            Console.WriteLine("isContainsObject值为{0}", isContainsObject);
            Console.WriteLine("objectA值为{0}", objectA);
            Console.WriteLine("objectB值为{0}", objectB);
            Console.WriteLine("objectC值为{0}", objectC);
            Console.WriteLine("isSingleton值为{0}", isSingleton);
            Console.WriteLine("aliases值为{0}", string.Join(",", aliases));
        }
Ejemplo n.º 7
0
        public void RedisProducer_DITest()
        {
            var testObject = _objectFactory.GetObject <IProducer>(ProducerName);

            Assert.IsNotNull(testObject);
            Assert.That(testObject.GetType(), Is.EqualTo(typeof(RedisProducer)));
            Assert.That(testObject.Queue.GetType(), Is.EqualTo(typeof(RedisQueue)));
            Assert.That(testObject.Connection.GetType(), Is.EqualTo(typeof(RedisConnection)));
        }
Ejemplo n.º 8
0
        public void RedisMessaging_DIInitTest()
        {
            var producer = _objectFactory.GetObject <IProducer>(ProducerName);
            var consumer = _objectFactory.GetObject <IContainer>(ConsumerName);

            consumer.Init();
            Assert.IsTrue(producer.Connection.IsConnected);
            Assert.IsTrue(consumer.Connection.IsConnected);
        }
Ejemplo n.º 9
0
        public void GetObjectTypeWithNoTargetOrTargetSource()
        {
            IObjectFactory bf =
                new XmlObjectFactory(new ReadOnlyXmlTestResource("proxyFactoryTargetSourceTests.xml", GetType()));

            bf.GetObject("noTarget");
            IFactoryObject pfb = (ProxyFactoryObject)bf.GetObject("&noTarget");

            Assert.IsTrue(typeof(ITestObject).IsAssignableFrom(pfb.ObjectType), "Has correct object type");
        }
        public void RedisQueueSentienl_AddTest()
        {
            var sentinel = _objectFactory.GetObject <RedisQueueSentinel>(SentinelName);
            var list     = new List <RedisValue> {
                "hey"
            };

            sentinel.Add(QueueName, list);
            Assert.That(sentinel.ProcessingMessages.ContainsKey(new KeyValuePair <string, RedisValue>(QueueName, "hey")));
        }
        public void ViaXMLAndConfigSection()
        {
            IResource        resource         = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
            XmlObjectFactory xbf              = new XmlObjectFactory(resource);
            PropertyPlaceholderConfigurer ppc = (PropertyPlaceholderConfigurer)xbf.GetObject("ConfigSectionPlaceholderConfigurer");

            Assert.IsNotNull(ppc);
            ppc.PostProcessObjectFactory(xbf);

            Assert.AreEqual("name from section", ((TestObject)xbf.GetObject("Test3")).Name);
            Assert.AreEqual("name from sectiongroup/section", ((TestObject)xbf.GetObject("Test4")).Name);
        }
        public void ViaXML()
        {
            IResource        resource         = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
            XmlObjectFactory xbf              = new XmlObjectFactory(resource);
            PropertyPlaceholderConfigurer ppc = (PropertyPlaceholderConfigurer)xbf.GetObject("PlaceholderConfigurer");

            Assert.IsNotNull(ppc);
            ppc.PostProcessObjectFactory(xbf);
            TestObject to = (TestObject)xbf.GetObject("Test1");

            Assert.AreEqual("A DefName", to.Name);
        }
Ejemplo n.º 13
0
        public void ViaXML()
        {
            IResource                  resource = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
            XmlObjectFactory           xbf      = new XmlObjectFactory(resource);
            PropertyOverrideConfigurer poc      = (PropertyOverrideConfigurer)xbf.GetObject("OverrideConfigurer");

            Assert.IsNotNull(poc);
            poc.PostProcessObjectFactory(xbf);
            TestObject to = (TestObject)xbf.GetObject("Test2");

            Assert.AreEqual("Overriden Name", to.Name);
        }
Ejemplo n.º 14
0
        public void GetObjectTypeWithTargetViaTargetSource()
        {
            IObjectFactory bf = new XmlObjectFactory(
                new ReadOnlyXmlTestResource("proxyFactoryTargetSourceTests.xml",
                                            GetType()));
            ITestObject tb = (ITestObject)bf.GetObject("viaTargetSource");

            Assert.IsTrue(tb.Name.Equals("Adam"));
            ProxyFactoryObject pfb = (ProxyFactoryObject)bf.GetObject("&viaTargetSource");

            Assert.IsTrue(typeof(ITestObject).IsAssignableFrom(pfb.ObjectType), "Has correct object type");
        }
Ejemplo n.º 15
0
        public void RedisContainer_DITest()
        {
            var testObject = _objectFactory.GetObject <IContainer>(ContainerName);

            testObject.Init();

            Assert.IsNotNull(testObject);
            Assert.That(testObject.GetType(), Is.EqualTo(typeof(RedisContainer)));
            Assert.That(testObject.Connection.GetType(), Is.EqualTo(typeof(RedisConnection)));
            Assert.That(testObject.Channels.First().GetType(), Is.EqualTo(typeof(RedisChannel)));
            Assert.That(testObject.Channels.Count(), Is.EqualTo(5));
        }
Ejemplo n.º 16
0
        public void FactoryWrapsObjectInSingletonTargetSource()
        {
            IObjectFactory bf = new XmlObjectFactory(
                new ReadOnlyXmlTestResource("proxyFactoryTargetSourceTests.xml",
                                            GetType()));
            ITestObject tb = (ITestObject)bf.GetObject("viaTargetSource");

            Assert.IsTrue(tb.Name.Equals("Adam"));
            ProxyFactoryObject pfb = (ProxyFactoryObject)bf.GetObject("&viaTargetSource");

            Assert.IsTrue(typeof(ITestObject).IsAssignableFrom(pfb.ObjectType), "Has correct object type");
            Assert.AreEqual(typeof(SingletonTargetSource), pfb.TargetSource.GetType(), "Incorrect target source, expected singleton");
        }
        private void  Functionality(System.String name)
        {
            ISideEffectObject pooled = (ISideEffectObject)objectFactory.GetObject(name);

            Assert.AreEqual(INITIAL_COUNT, pooled.Count);
            pooled.doWork();
            Assert.AreEqual(INITIAL_COUNT + 1, pooled.Count);

            pooled = (ISideEffectObject)objectFactory.GetObject(name);
            // Just check that it works--we can't make assumptions
            // about the count
            pooled.doWork();
            //Assert.AreEqual(INITIAL_COUNT + 1, pooled.Count );
        }
        public void SingletonProxyWithPrototypeTarget()
        {
            TestObjectImpl.constructionCount = 0;
            IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTarget.xml", GetType()));

            for (int i = 0; i < 10; i++)
            {
                TestObject to = (TestObject)iof.GetObject("testObjectSingleton");
                to.DoSomething();
            }
            TestInterceptor interceptor = (TestInterceptor)iof.GetObject("testInterceptor");

            Assert.AreEqual(1, TestObjectImpl.constructionCount);
            Assert.AreEqual(10, interceptor.invocationCount);
        }
Ejemplo n.º 19
0
        public void NotAccessibleInterfaceProxying()
        {
            const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
                <objects xmlns='http://www.springframework.net'>
                <object id='MyProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'>
                    <property name='ProxyInterfaces'>
                        <list>
                            <value>Spring.Aop.Framework.HelperInterface2, Spring.Aop.Tests</value>
                        </list>
                    </property>
                    <property name='TargetName' value='MyTarget' />
                    <property name='InterceptorNames'>
                        <list>
                            <value>MyInterceptor</value>
                        </list>
                    </property>
                </object>
                <object id='MyTarget' type='Spring.Aop.Framework.HelperClassForNotAccessibleInterfaceProxyingTest, Spring.Aop.Tests'/>
	            <object id='MyInterceptor' type='Spring.Aop.Interceptor.NopInterceptor'/>
               </objects>";


            MemoryStream     stream        = new MemoryStream(new UTF8Encoding().GetBytes(xml));
            IResource        resource      = new InputStreamResource(stream, "Test ProxyFactoryObject");
            XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);

            HelperInterface2 hc = (HelperInterface2)objectFactory.GetObject("MyProxy");

            Console.WriteLine(hc.SecondDoSomething());
        }
Ejemplo n.º 20
0
        public void AnObjectCanBeInjectedFromCodeIntoTheContext()
        {
            string           inject  = @"
<objects xmlns='http://www.springframework.net' 
		xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
		xsi:schemaLocation='http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd'>

    <object 
        name='inject' 
        type='Spring.Services.WindowsService.Common.Deploy.FileSystem.Inject' 
        singleton='false'>
      <property name='Application'>
        <ref object='app'/>
      </property>
    </object>
</objects>
";
            XmlObjectFactory factory = new XmlObjectFactory(new InputStreamResource(new MemoryStream(Encoding.Default.GetBytes(inject)), ""));
            IApplication     app     = new Application("foo");

            factory.RegisterSingleton("app", app);
            Inject injected = (Inject)factory.GetObject("inject");

            Assert.IsNotNull(injected);
            Assert.IsNotNull(injected.Application);
            Assert.AreEqual(app, injected.Application);
        }
Ejemplo n.º 21
0
    public IController CreateController(RequestContext context, Type controllerType)
    {
        IResource      input   = new FileSystemResource(context.HttpContext.Request.MapPath("Resource\\objects.xml"));
        IObjectFactory factory = new XmlObjectFactory(input);

        return((IController)factory.GetObject(controllerType.Name));
    }
        public void SetsConventionsCorrectly()
        {
            string xml               = @"<?xml version='1.0' encoding='UTF-8' ?>
                            <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>  
                                <mongo:convention-profile
	                                default-value='Spring.Data.MongoDb.Config.DefaultValueConvention, Spring.Data.MongoDb.Tests'
	                                element-name='Spring.Data.MongoDb.Config.ElementNameConvention, Spring.Data.MongoDb.Tests'
	                                extra-elements-member='Spring.Data.MongoDb.Config.ExtraElementsMemberConvention, Spring.Data.MongoDb.Tests'
	                                id-generator='Spring.Data.MongoDb.Config.IdGeneratorConvention, Spring.Data.MongoDb.Tests'
	                                id-member='Spring.Data.MongoDb.Config.IdMemberConvention, Spring.Data.MongoDb.Tests'
	                                ignore-extra-elements='Spring.Data.MongoDb.Config.IgnoreExtraElementsConvention, Spring.Data.MongoDb.Tests'
	                                ignore-if-default='Spring.Data.MongoDb.Config.IgnoreIfDefaultConvention, Spring.Data.MongoDb.Tests'
	                                ignore-if-null='Spring.Data.MongoDb.Config.IgnoreIfNullConvention, Spring.Data.MongoDb.Tests'
	                                member-finder='Spring.Data.MongoDb.Config.MemberFinderConvention, Spring.Data.MongoDb.Tests'
	                                serialization-options='Spring.Data.MongoDb.Config.SerializationOptionsConvention, Spring.Data.MongoDb.Tests' />
                            </objects>";
            var    factory           = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));
            var    conventionProfile = factory.GetObject <ConventionProfile>("MongoConventionProfile");

            Assert.That(conventionProfile, Is.Not.Null);
            Assert.That(conventionProfile.DefaultValueConvention, Is.TypeOf <DefaultValueConvention>());
            Assert.That(conventionProfile.ElementNameConvention, Is.TypeOf <ElementNameConvention>());
            Assert.That(conventionProfile.ExtraElementsMemberConvention, Is.TypeOf <ExtraElementsMemberConvention>());
            Assert.That(conventionProfile.IdGeneratorConvention, Is.TypeOf <IdGeneratorConvention>());
            Assert.That(conventionProfile.IdMemberConvention, Is.TypeOf <IdMemberConvention>());
            Assert.That(conventionProfile.IgnoreExtraElementsConvention, Is.TypeOf <IgnoreExtraElementsConvention>());
            Assert.That(conventionProfile.IgnoreIfDefaultConvention, Is.TypeOf <IgnoreIfDefaultConvention>());
            Assert.That(conventionProfile.IgnoreIfNullConvention, Is.TypeOf <IgnoreIfNullConvention>());
            Assert.That(conventionProfile.MemberFinderConvention, Is.TypeOf <MemberFinderConvention>());
            Assert.That(conventionProfile.SerializationOptionsConvention, Is.TypeOf <SerializationOptionsConvention>());
        }
Ejemplo n.º 23
0
        public virtual void MultiThreadedTest()
        {
            multiThreadedTestFailed = false;

            this.ObjectFactory = new XmlObjectFactory(
                new ReadOnlyXmlTestResource("threadLocalTests.xml", GetType()));
            log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            // Initialize property.
            IMultiThreadInterface mtObject = (IMultiThreadInterface)ObjectFactory.GetObject("mtTest");

            // Start threads.
            ArrayList threads = new ArrayList();

            for (int i = 0; i < 100; i++)
            {
                Thread thread = new Thread(new ParameterizedThreadStart(CheckName));
                threads.Add(thread);
                thread.Start(mtObject);
            }

            // Wait for threads to end.
            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            Assert.IsFalse(multiThreadedTestFailed);
        }
Ejemplo n.º 24
0
        public void RedisConnection_DI_Test()
        {
            var testObject = _objectFactory.GetObject <IConnection>("strongConnection");

            Assert.IsNotNull(testObject);
            Assert.That(testObject.GetType(), Is.EqualTo(typeof(RedisConnection)));
        }
Ejemplo n.º 25
0
        public void ErrorTests()
        {
            const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
            <objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
                <object id='ccAmex' type='Oragon.Spring.Validation.Validators.Amex, Oragon.Spring.Core'/>
                <v:validator id='ccValidator' test='Creditcard' type='Oragon.Spring.Validation.Validators.CreditCardValidator, Oragon.Spring.Core'>
                    <v:property name='CardType' ref='ccAmex'/>
                    <v:message id='errorKey' providers='validationSummary' />
                </v:validator>
            </objects>";

            MemoryStream stream   = new MemoryStream(new UTF8Encoding().GetBytes(xml));
            IResource    resource = new InputStreamResource(stream, "ccValidator");

            XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);

            IValidationErrors errors    = new ValidationErrors();
            Contact           contact   = new Contact();
            IValidator        validator = (IValidator)objectFactory.GetObject("ccValidator");

            contact.Creditcard = "378282246310";
            bool result = validator.Validate(contact, errors);

            Assert.IsNotNull(errors.GetErrors("validationSummary"));
            Assert.IsFalse(result);
        }
Ejemplo n.º 26
0
        public void RedisChannel_HandleErrorRetryRequeueTest()
        {
            _channel = _objectFactory.GetObject <IChannel>(ChannelName) as RedisChannel;
            var connection        = _channel.Container.Connection as RedisConnection;
            var _redis            = connection.Multiplexer;
            var messageQueueItems = _redis.GetDatabase().ListLength(_channel.MessageQueue.Name);
            var e = new TimeoutException();
            var m = new KeyValuePair <string, object>("Requeue Key:", "{\"Message\":\"Requeue Message\"}");


            _channel.HandleException(e, m);


            Assert.That(_redis.GetDatabase().ListLength(_channel.MessageQueue.Name), Is.EqualTo(messageQueueItems + 1));
            Assert.That(
                _redis.GetDatabase()
                .ListGetByIndex(_channel.MessageQueue.Name, _redis.GetDatabase().ListLength(_channel.MessageQueue.Name) - 1)
                .ToString(), Is.EqualTo(m.ToString()));
        }
Ejemplo n.º 27
0
        public void CanAddThrowsAdviceWithoutAdvisor()
        {
            IObjectFactory f = new XmlObjectFactory(new ReadOnlyXmlTestResource("throwsAdvice.xml", GetType()));

            ThrowsAdviceInterceptorTests.MyThrowsHandler th =
                (ThrowsAdviceInterceptorTests.MyThrowsHandler)f.GetObject("throwsAdvice");
            CountingBeforeAdvice cba = (CountingBeforeAdvice)f.GetObject("countingBeforeAdvice");

            Assert.AreEqual(0, cba.GetCalls());
            Assert.AreEqual(0, th.GetCalls());
            ThrowsAdviceInterceptorTests.IEcho echo = (ThrowsAdviceInterceptorTests.IEcho)f.GetObject("throwsAdvised");
            echo.A = 12;
            Assert.AreEqual(1, cba.GetCalls());
            Assert.AreEqual(0, th.GetCalls());
            Exception expected = new Exception();

            try
            {
                echo.EchoException(1, expected);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.AreEqual(expected, ex);
            }
            // No throws handler method: count should still be 0
            Assert.AreEqual(0, th.GetCalls());

            // Handler knows how to handle this exception
            expected = new HttpException();
            try
            {
                echo.EchoException(1, expected);
                Assert.Fail();
            }
            catch (HttpException ex)
            {
                Assert.AreEqual(expected, ex);
            }
            // One match
            Assert.AreEqual(1, th.GetCalls("HttpException"));
        }
Ejemplo n.º 28
0
        public void GetObjectTypeWithDirectTarget()
        {
            IObjectFactory bf = new XmlObjectFactory(
                new ReadOnlyXmlTestResource("proxyFactoryTargetSourceTests.xml",
                                            GetType()));

            // We have a counting before advice here
            CountingBeforeAdvice cba = (CountingBeforeAdvice)bf.GetObject("countingBeforeAdvice");

            Assert.AreEqual(0, cba.GetCalls());

            ITestObject tb = (ITestObject)bf.GetObject("directTarget");

            Assert.IsTrue(tb.Name.Equals("Adam"));
            Assert.AreEqual(1, cba.GetCalls());

            ProxyFactoryObject pfb = (ProxyFactoryObject)bf.GetObject("&directTarget");

            Assert.IsTrue(typeof(ITestObject).IsAssignableFrom(pfb.ObjectType), "Has correct object type");
        }
Ejemplo n.º 29
0
        public void RedisQueue_DI_Test()
        {
            const string name       = "myRedisQ";
            const int    ttl        = 10000;
            var          testObject = _objectFactory.GetObject <IQueue>("myQueue");

            Assert.IsNotNull(testObject);
            Assert.That(testObject.GetType(), Is.EqualTo(typeof(RedisQueue)));
            Assert.That(testObject.Name, Is.EqualTo(name));
            Assert.That(testObject.TTL, Is.EqualTo(ttl));
        }
        public void PrototypeAndSingletonBehaveDifferently()
        {
            int               initialCount = 10;
            IObjectFactory    of           = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTargetSourceTests.xml", GetType()));
            ISideEffectObject singleton    = (ISideEffectObject)of.GetObject("singleton");

            Assert.AreEqual(initialCount, singleton.Count);
            singleton.doWork();
            Assert.AreEqual(initialCount + 1, singleton.Count);

            ISideEffectObject prototype = (ISideEffectObject)of.GetObject("prototype");

            Assert.AreEqual(initialCount, prototype.Count);
            singleton.doWork();
            Assert.AreEqual(initialCount, prototype.Count);

            ISideEffectObject prototypeByName = (ISideEffectObject)of.GetObject("prototypeByName");

            Assert.AreEqual(initialCount, prototypeByName.Count);
            singleton.doWork();
            Assert.AreEqual(initialCount, prototypeByName.Count);
        }