public void ValidSwaps() { ISideEffectObject target1 = (ISideEffectObject)ObjectFactory.GetObject("target1"); ISideEffectObject target2 = (ISideEffectObject)ObjectFactory.GetObject("target2"); ISideEffectObject proxied = (ISideEffectObject)ObjectFactory.GetObject("swappable"); // assertEquals(target1, ((Advised) proxied).getTarget()); Assert.AreEqual(target1.Count, proxied.Count); proxied.doWork(); Assert.AreEqual(INITIAL_COUNT + 1, proxied.Count); HotSwappableTargetSource swapper = (HotSwappableTargetSource)ObjectFactory.GetObject("swapper"); Object old = swapper.Swap(target2); Assert.AreEqual(target1, old, "Correct old target was returned"); // TODO should be able to make this assertion: need to fix target handling // in AdvisedSupport //assertEquals(target2, ((Advised) proxied).getTarget()); Assert.AreEqual(20, proxied.Count); proxied.doWork(); Assert.AreEqual(21, target2.Count); // Swap it back swapper.Swap(target1); Assert.AreEqual(target1.Count, proxied.Count); }
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 virtual void NewThreadHasOwnInstance() { ISideEffectObject apartment = (ISideEffectObject)ObjectFactory.GetObject("apartment"); log.Debug(String.Format("got object; hash code: {0}", apartment.GetHashCode())); Assert.AreEqual(INITIAL_COUNT, apartment.Count); apartment.doWork(); apartment.doWork(); apartment.doWork(); Assert.AreEqual(INITIAL_COUNT + 3, apartment.Count); Runner r = new Runner(this); Thread t = new Thread(new ThreadStart(r.Run)); t.Start(); t.Join(); Assert.IsNotNull(r); // Check it didn't affect the other thread's copy Assert.AreEqual(INITIAL_COUNT + 3, apartment.Count); // When we use other thread's copy in this thread // it should behave like ours Assert.AreEqual(INITIAL_COUNT + 3, r.mine.Count); // Bound to two threads Assert.AreEqual(2, ((IThreadLocalTargetSourceStats)apartment).Objects); }
public virtual void Run() { log.Debug("getting object"); this.mine = (ISideEffectObject)factory.ObjectFactory.GetObject("apartment"); log.Debug(String.Format("got object; hash code: {0}", this.mine.GetHashCode())); Assert.AreEqual(ThreadLocalTargetSourceTests.INITIAL_COUNT, mine.Count); mine.doWork(); Assert.AreEqual(ThreadLocalTargetSourceTests.INITIAL_COUNT + 1, mine.Count); }
public virtual void ReuseInSameThread() { ISideEffectObject apartment = (ISideEffectObject)ObjectFactory.GetObject("apartment"); Assert.AreEqual(INITIAL_COUNT, apartment.Count); apartment.doWork(); Assert.AreEqual(INITIAL_COUNT + 1, apartment.Count); apartment = (ISideEffectObject)ObjectFactory.GetObject("apartment"); Assert.AreEqual(INITIAL_COUNT + 1, apartment.Count); }
public virtual void UseDifferentManagedInstancesInSameThread() { ISideEffectObject apartment = (ISideEffectObject)ObjectFactory.GetObject("apartment"); Assert.AreEqual(INITIAL_COUNT, apartment.Count); apartment.doWork(); Assert.AreEqual(INITIAL_COUNT + 1, apartment.Count); ITestObject test = (ITestObject)ObjectFactory.GetObject("threadLocal2"); Assert.AreEqual("Rod", test.Name); Assert.AreEqual("Kerry", test.Spouse.Name); }
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 virtual void CanGetStatsViaMixinIfThereIsAnInterceptorTakingCareOfThem() { IThreadLocalTargetSourceStats stats = (IThreadLocalTargetSourceStats)ObjectFactory.GetObject("apartment"); Assert.AreEqual(0, stats.Invocations); ISideEffectObject apartment = (ISideEffectObject)ObjectFactory.GetObject("apartment"); apartment.doWork(); Assert.AreEqual(1, stats.Invocations); Assert.AreEqual(0, stats.Hits); apartment.doWork(); Assert.AreEqual(2, stats.Invocations); Assert.AreEqual(1, stats.Hits); // Only one thread so only one object can have been bound Assert.AreEqual(1, stats.Objects); }
public virtual void ConfigMixin() { ISideEffectObject pooled = (ISideEffectObject)objectFactory.GetObject("pooledWithMixin"); Assert.AreEqual(INITIAL_COUNT, pooled.Count); PoolingConfig conf = (PoolingConfig)objectFactory.GetObject("pooledWithMixin"); // TODO one invocation from setup // assertEquals(1, conf.getInvocations()); pooled.doWork(); // assertEquals("No objects active", 0, conf.getActive()); Assert.AreEqual(25, conf.MaxSize, "Correct target source"); // assertTrue("Some free", conf.getFree() > 0); //assertEquals(2, conf.getInvocations()); Assert.AreEqual(25, conf.MaxSize); }
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); }
public virtual void Run () { log.Debug ("getting object"); this.mine = (ISideEffectObject) factory.ObjectFactory.GetObject ("apartment"); log.Debug (String.Format ("got object; hash code: {0}", this.mine.GetHashCode ())); Assert.AreEqual (ThreadLocalTargetSourceTests.INITIAL_COUNT, mine.Count); mine.doWork (); Assert.AreEqual (ThreadLocalTargetSourceTests.INITIAL_COUNT + 1, mine.Count); }