Ejemplo n.º 1
0
        public void BasicBeforeVirtualMethodStateful()
        {
            lock (Interception.Handle)
            {
                var _method = Metadata <Virtual> .Method(_Virtual => _Virtual.Method(Argument <int> .Value, Argument <int> .Value));

                var _instance = new Virtual();
                Interception.Initialize();
                _instance.Method(2, 3);
                Assert.AreEqual(Interception.Done, false);
                Aspect.Weave <Before.Interceptor.Parameterized>(_method);
                Interception.Initialize();
                var _return = _instance.Method(2, 3);
                Assert.AreEqual(_return, 1);
                Assert.AreEqual(Interception.Done, true);
                Assert.AreEqual(Interception.Instance, _instance);
                Assert.AreEqual(Interception.Arguments.Length, 2);
                Assert.AreEqual(Interception.Arguments[0], 2);
                Assert.AreEqual(Interception.Arguments[1], 3);
                Aspect.Release <Before.Interceptor.Parameterized>(_method);
                Interception.Initialize();
                _instance.Method(2, 3);
                Assert.AreEqual(Interception.Done, false);
            }
        }
Ejemplo n.º 2
0
        public void BasicBeforeVirtualMethod()
        {
            lock (Interception.Handle)
            {
                var _method = Metadata <Virtual> .Method(_Instance => _Instance.Method(Argument <int> .Value, Argument <int> .Value));

                var _instance = new Virtual();
                Interception.Initialize();
                _instance.Method(2, 3);
                Assert.AreEqual(Interception.Done, false);
                Aspect.Weave <Before.Interceptor>(_method);
                Interception.Initialize();
                var _return = _instance.Method(2, 3);
                Assert.AreEqual(_return, 1);
                Assert.AreEqual(Interception.Done, true);
                Aspect.Release <Before.Interceptor>(_method);
                Interception.Initialize();
                _instance.Method(2, 3);
                Assert.AreEqual(Interception.Done, false);
            }
        }