Exemplo n.º 1
0
        public void InterceptGenericMethods()
        {
            var simpleCalls        = new SimpleCalls();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, new NonRecursiveExecutionDispatcher());

            Assert.AreEqual(5, proxiedSimpleCalls.Repeate(5));
        }
Exemplo n.º 2
0
        public void InterceptMethodsThatRetuns()
        {
            var simpleCalls        = new SimpleCalls();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, new NonRecursiveExecutionDispatcher());

            Assert.IsTrue(proxiedSimpleCalls.Ask());
            Assert.IsTrue(simpleCalls.Called);
        }
Exemplo n.º 3
0
        public void OutParameterAreHandled()
        {
            var simpleCalls        = new SimpleCalls();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, new NonRecursiveExecutionDispatcher());

            int expect5;

            proxiedSimpleCalls.Assign5(out expect5);

            Assert.AreEqual(5, expect5);
        }
Exemplo n.º 4
0
        public void PropertyIshandled()
        {
            var simpleCalls        = new SimpleCalls();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, new NonRecursiveExecutionDispatcher());

            proxiedSimpleCalls.SomeProperty = 5;


            Assert.AreEqual(5, simpleCalls.SomeProperty);

            Assert.AreEqual(5, proxiedSimpleCalls.SomeProperty);
        }
Exemplo n.º 5
0
        public void OutParameterMixedWithOtherInGenericMethodAreHandled()
        {
            var simpleCalls        = new SimpleCalls();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, new NonRecursiveExecutionDispatcher());

            string assigned;
            bool   toInvert = false;
            var    firstVal = "55";

            proxiedSimpleCalls.AssignWithFirstVal(out assigned, ref toInvert, firstVal);

            Assert.AreEqual("55", assigned);
            Assert.AreEqual("55", firstVal);
            Assert.IsTrue(toInvert);
        }
Exemplo n.º 6
0
        public void ExceptionOnNonVoidIsRethrown()
        {
            var simpleCalls        = new SimpleCalls();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, new NonRecursiveExecutionDispatcher());

            try
            {
                proxiedSimpleCalls.ThowOnFunc();
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOf <NotImplementedException>(e);
            }

            Assert.IsTrue(simpleCalls.Called);
        }
Exemplo n.º 7
0
        public void ExceptionOnVoidIsIgnored()
        {
            var simpleCalls        = new SimpleCalls();
            var executionQueue     = new QueuedExecutionDispatcher();
            var proxiedSimpleCalls = BeginInvokeProxy <ISimpleCalls> .Create(simpleCalls, executionQueue);

            proxiedSimpleCalls.ThowOnVoid();

            try
            {
                executionQueue.ExecuteAll();
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsNotNull(e);
            }

            Assert.IsTrue(simpleCalls.Called);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var actionQueue = new ConcurrentExecutionDispatcher(e => { Console.Error.WriteLine(e.ToString()); });
            var calculator  = BeginInvokeProxy <ICalculator> .Create(new Calculator(), actionQueue);

            var cancellationTokenSource = ExecuteActionsAsync(actionQueue);

            calculator.SetValue(5);
            for (int i = 0; i < 100; i++)
            {
                calculator.Inc();
                calculator.Sub();
            }
            calculator.Inc();
            calculator.Sub();


            Console.WriteLine(calculator.Result());

            cancellationTokenSource.Cancel();


            Console.ReadKey();
        }