public void EqualsOnAdviceEqualAndInterfacesEqual() { TestIntroductionAdvice to1 = new TestIntroductionAdvice(); TestIntroductionAdvice to2 = new TestIntroductionAdvice(); to1.SetEqualsToObject(to2); to2.SetEqualsToObject(to1); DefaultIntroductionAdvisor a1 = new DefaultIntroductionAdvisor(to1); DefaultIntroductionAdvisor a2 = new DefaultIntroductionAdvisor(to2); bool result = a1.Equals(a2); Assert.IsTrue(result); }
public void EqualsOnAdviceEqualAndInterfacesEqual() { TestIntroductionAdvice to1 = new TestIntroductionAdvice(); TestIntroductionAdvice to2 = new TestIntroductionAdvice(); to1.SetEqualsToObject(to2); to2.SetEqualsToObject(to1); DefaultIntroductionAdvisor a1 = new DefaultIntroductionAdvisor(to1); DefaultIntroductionAdvisor a2 = new DefaultIntroductionAdvisor(to2); bool result = a1.Equals(a2); Assert.IsTrue(result); }
public void TestIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ITimeStampedIntroduction ts = MockRepository.GenerateMock<ITimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped) factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void TestAutomaticInterfaceRecognitionInDelegate() { IIntroductionAdvisor ia = new DefaultIntroductionAdvisor(new Test(EXPECTED_TIMESTAMP)); TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); pf.AddIntroduction(0, ia); ITimeStamped ts = (ITimeStamped)pf.GetProxy(); Assert.IsTrue(ts.TimeStamp == EXPECTED_TIMESTAMP); ((ITest)ts).Foo(); int age = ((ITestObject)ts).Age; }
/// <summary> /// 2 IntroductionAdvisors are considered equal if /// a) they are of the same type /// b) their introduction advices are equal /// c) they introduce the same interfaces /// </summary> public bool Equals(DefaultIntroductionAdvisor other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (other.GetType() != this.GetType()) { return(false); } return(Equals(other._introduction, _introduction) && Equals(other._interfaces, _interfaces)); }
public void testIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction)); ITimeStampedIntroduction ts = (ITimeStampedIntroduction) tsControl.Object; tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped) factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); tsControl.Verify(); }
public void TestIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(!(raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ITimeStampedIntroduction ts = A.Fake <ITimeStampedIntroduction>(); A.CallTo(() => ts.TimeStamp).Returns(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped)factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void TestIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(!(raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ITimeStampedIntroduction ts = MockRepository.GenerateMock <ITimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped)factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void TestIntroductionInterceptorWithInterfaceHierarchy() { TestObject raw = new TestObject(); Assert.IsTrue(!(raw is ISubTimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ISubTimeStampedIntroduction ts = MockRepository.GenerateMock <ISubTimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); // we must add introduction, not an advisor factory.AddIntroduction(advisor); object proxy = factory.GetProxy(); ISubTimeStamped tsp = (ISubTimeStamped)proxy; Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void testIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(!(raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction)); ITimeStampedIntroduction ts = (ITimeStampedIntroduction)tsControl.Object; tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped)factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); tsControl.Verify(); }
public void testIntroductionInterceptorWithInterfaceHierarchy() { TestObject raw = new TestObject(); Assert.IsTrue(!(raw is ISubTimeStamped)); ProxyFactory factory = new ProxyFactory(raw); IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction)); ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction)tsControl.Object; tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); // we must add introduction, not an advisor factory.AddIntroduction(advisor); object proxy = factory.GetProxy(); ISubTimeStamped tsp = (ISubTimeStamped)proxy; Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); tsControl.Verify(); }
public void IntroductionMustImplementIntroducedInterfaces() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(ICloneable)); Assert.Throws <ArgumentException>(() => advisor.ValidateInterfaces(), "Introduction [Spring.Aop.Support.DefaultIntroductionAdvisorTests+TestIntroductionAdvice] does not implement interface 'System.ICloneable' specified in introduction advice."); }
public void BaseInterfacesAreValid() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(IBaseInterface)); advisor.ValidateInterfaces(); }
public void IntroductionMustImplementIntroducedInterfaces() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(ICloneable)); advisor.ValidateInterfaces(); }
public void testNullTarget() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(null, typeof(ITimeStamped)); }
public void testIntroductionInterceptorWithInterfaceHierarchy() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ISubTimeStamped)); ProxyFactory factory = new ProxyFactory(raw); IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction)); ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction) tsControl.Object; tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); // we must add introduction, not an advisor factory.AddIntroduction(advisor); object proxy = factory.GetProxy(); ISubTimeStamped tsp = (ISubTimeStamped) proxy; Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); tsControl.Verify(); }
public void CanAddAndRemoveIntroductionsOnSingleton() { try { ITimeStamped ts = (ITimeStamped)factory.GetObject("test1"); Assert.Fail("Shouldn't implement ITimeStamped before manipulation"); } catch (InvalidCastException) { } ProxyFactoryObject config = (ProxyFactoryObject)factory.GetObject("&test1"); long time = 666L; TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(); ti.TimeStamp = new DateTime(time); IIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped)); // add to front of introduction chain int oldCount = config.Introductions.Length; config.AddIntroduction(0, advisor); Assert.IsTrue(config.Introductions.Length == oldCount + 1); ITimeStamped ts2 = (ITimeStamped)factory.GetObject("test1"); Assert.IsTrue(ts2.TimeStamp == new DateTime(time)); // Can remove config.RemoveIntroduction(advisor); Assert.IsTrue(config.Introductions.Length == oldCount); // Existing reference will still work object o = ts2.TimeStamp; // But new proxies should not implement ITimeStamped try { ts2 = (ITimeStamped)factory.GetObject("test1"); Assert.Fail("Should no longer implement ITimeStamped"); } catch (InvalidCastException) { // expected... } // Now check non-effect of removing interceptor that isn't there oldCount = config.Advisors.Length; config.RemoveAdvice(new DebugAdvice()); Assert.IsTrue(config.Advisors.Length == oldCount); ITestObject it = (ITestObject)ts2; DebugAdvice debugInterceptor = new DebugAdvice(); config.AddAdvice(0, debugInterceptor); object foo = it.Spouse; Assert.AreEqual(1, debugInterceptor.Count); config.RemoveAdvice(debugInterceptor); foo = it.Spouse; // not invoked again Assert.IsTrue(debugInterceptor.Count == 1); }
public void DoesNotCacheWithDifferentInterfaces() { ProxyFactory advisedSupport = new ProxyFactory(new TestObject()); CreateAopProxy(advisedSupport); advisedSupport = new ProxyFactory(new TestObject()); advisedSupport.AddInterface(typeof(IPerson)); CreateAopProxy(advisedSupport); AssertAopProxyTypeCacheCount(2); // Same with Introductions advisedSupport = new ProxyFactory(new TestObject()); TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(); ti.TimeStamp = new DateTime(666L); IIntroductionAdvisor introduction = new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped)); advisedSupport.AddIntroduction(introduction); CreateAopProxy(advisedSupport); AssertAopProxyTypeCacheCount(3); }
public void IntroductionMustImplementIntroducedInterfaces() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(ICloneable)); advisor.ValidateInterfaces(); }
public void BailsIfInterfaceTypeIsNotAnInterface() { DefaultIntroductionAdvisor a = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), this.GetType()); }
public void TestAutomaticInterfaceRecognitionInDelegate() { IIntroductionAdvisor ia = new DefaultIntroductionAdvisor(new Test(EXPECTED_TIMESTAMP)); TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); pf.AddIntroduction(0, ia); ITimeStamped ts = (ITimeStamped) pf.GetProxy(); Assert.IsTrue(ts.TimeStamp == EXPECTED_TIMESTAMP); ((ITest) ts).Foo(); int age = ((ITestObject) ts).Age; }
/// <summary> /// 2 IntroductionAdvisors are considered equal if /// a) they are of the same type /// b) their introduction advices are equal /// c) they introduce the same interfaces /// </summary> public bool Equals(DefaultIntroductionAdvisor other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; if (other.GetType() != this.GetType()) return false; return Equals(other._introduction, _introduction) && Equals(other._interfaces, _interfaces); }
public void AddAndRemoveEventHandlerThroughIntroduction() { TestObject target = new TestObject(); DoubleClickableIntroduction dci = new DoubleClickableIntroduction(); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(dci); CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice(); target.Name = "SOME-NAME"; ProxyFactory pf = new ProxyFactory(target); pf.AddIntroduction(advisor); pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice)); object proxy = pf.GetProxy(); ITestObject to = proxy as ITestObject; Assert.IsNotNull(to); Assert.AreEqual("SOME-NAME", to.Name); IDoubleClickable doubleClickable = proxy as IDoubleClickable; // add event handler through introduction doubleClickable.DoubleClick += new EventHandler(OnClick); OnClickWasCalled = false; doubleClickable.FireDoubleClickEvent(); Assert.IsTrue(OnClickWasCalled); Assert.AreEqual(3, countingBeforeAdvice.GetCalls()); // remove event handler through introduction doubleClickable.DoubleClick -= new EventHandler(OnClick); OnClickWasCalled = false; doubleClickable.FireDoubleClickEvent(); Assert.IsFalse(OnClickWasCalled); Assert.AreEqual(5, countingBeforeAdvice.GetCalls()); }
public void IntroductionMustImplementIntroducedInterfaces() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(ICloneable)); Assert.Throws<ArgumentException>(() => advisor.ValidateInterfaces(), "Introduction [Spring.Aop.Support.DefaultIntroductionAdvisorTests+TestIntroductionAdvice] does not implement interface 'System.ICloneable' specified in introduction advice."); }
public void testNullTarget() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(null, typeof(ITimeStamped)); }
public void BaseInterfacesAreValid() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(IBaseInterface)); advisor.ValidateInterfaces(); }
public void TestIntroductionInterceptorWithInterfaceHierarchy() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ISubTimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ISubTimeStampedIntroduction ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); // we must add introduction, not an advisor factory.AddIntroduction(advisor); object proxy = factory.GetProxy(); ISubTimeStamped tsp = (ISubTimeStamped) proxy; Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void BailsIfInterfaceTypeIsNotAnInterface() { DefaultIntroductionAdvisor a = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), this.GetType()); }