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); }
/// <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 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; }
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 BaseInterfacesAreValid() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(IBaseInterface)); advisor.ValidateInterfaces(); }
public void IntroductionMustImplementIntroducedInterfaces() { DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(ICloneable)); Assert.Throws <ArgumentException>(() => advisor.ValidateInterfaces(), "Introduction [Oragon.Spring.Aop.Support.DefaultIntroductionAdvisorTests+TestIntroductionAdvice] does not implement interface 'System.ICloneable' specified in introduction advice."); }