Ejemplo n.º 1
0
        public async Task Always_ShouldInvokeMethodsCorrectly()
        {
            // arrange
            var performedActions = new List <string>();
            var proxy            = AopProxy.Create <ITest>(new Test(performedActions),
                                                           GetHandler(performedActions, 1), GetHandler(performedActions, 2));

            // act
            var strMethodResult     = proxy.StrMethod("t1");
            var taskIntMethodResult = await proxy.TaskIntMethod(5);

            await proxy.TaskVoidMethod();

            proxy.VoidMethod();
            var TaskIntMethodWithoutDelayResult = await proxy.TaskIntMethodWithoutDelay(6);

            // assert
            strMethodResult.Should().Be("t1 h2 h1");
            taskIntMethodResult.Should().Be(115);
            TaskIntMethodWithoutDelayResult.Should().Be(116);

            performedActions.Should().BeEquivalentTo(new List <string>
            {
                "StrMethod before 1 with args [\"t1\"]",
                "StrMethod before 2 with args [\"t1\"]",
                "StrMethod",
                "StrMethod after 2 with res t1",
                "StrMethod after 1 with res t1 h2",

                "TaskIntMethod before 1 with args [5]",
                "TaskIntMethod before 2 with args [5]",
                "TaskIntMethod",
                "TaskIntMethod after delay",
                "TaskIntMethod after 2 with res 5",
                "TaskIntMethod after 1 with res 105",

                "TaskVoidMethod before 1 with args []",
                "TaskVoidMethod before 2 with args []",
                "TaskVoidMethod",
                "TaskVoidMethod after delay",
                "TaskVoidMethod after 2 with res null",
                "TaskVoidMethod after 1 with res null",

                "VoidMethod before 1 with args []",
                "VoidMethod before 2 with args []",
                "VoidMethod",
                "VoidMethod after 2 with res null",
                "VoidMethod after 1 with res null",

                "TaskIntMethodWithoutDelay before 1 with args [6]",
                "TaskIntMethodWithoutDelay before 2 with args [6]",
                "TaskIntMethodWithoutDelay",
                "TaskIntMethodWithoutDelay after 2 with res 6",
                "TaskIntMethodWithoutDelay after 1 with res 106",
            }, o => o.WithStrictOrdering());
        }
Ejemplo n.º 2
0
 private T WrapIfNeeded <T>(T obj, string name)
 {
     return(_wrappers.Count > 0
         ? AopProxy.Create(obj, name, _wrappers.Select(w => (AopProxy.MethodCallHandler)w.HandleMethodCall).ToArray())
         : obj);
 }
Ejemplo n.º 3
0
        private T AddCaching <T>(T obj)
        {
            var cachingHelper = new CachingHelper();

            return(AopProxy.Create(obj, cachingHelper.HandleMethodCall));
        }