public void ProxyInterceptsAddingAHandlerToAnEvent() { // arrange CallCountInterceptionBehavior interceptor = new CallCountInterceptionBehavior(); MBROWithAnEvent original = new MBROWithAnEvent(); MBROWithAnEvent intercepted = new InterceptingRealProxy(original, typeof(MBROWithAnEvent)) .GetTransparentProxy() as MBROWithAnEvent; ((IInterceptingProxy)intercepted).AddInterceptionBehavior(interceptor); // act intercepted.SomeEvent += (s, a) => { }; // assert Assert.AreEqual(1, interceptor.CallCount); }
public void ProxySendsOriginalWhenRaisingEvent() { // arrange CallCountInterceptionBehavior interceptor = new CallCountInterceptionBehavior(); MBROWithAnEvent original = new MBROWithAnEvent(); MBROWithAnEvent intercepted = new InterceptingRealProxy(original, typeof(MBROWithAnEvent)) .GetTransparentProxy() as MBROWithAnEvent; ((IInterceptingProxy)intercepted).AddInterceptionBehavior(interceptor); object sender = null; intercepted.SomeEvent += (s, a) => { sender = s; }; // act intercepted.TriggerIt(); // assert Assert.AreSame(original, sender); Assert.AreEqual(2, interceptor.CallCount); // adding + calling TriggerIt }