Example #1
0
        public void NoExpressionTest()
        {
            var expressions = new string[] {
                null,
                "",
                "*",
                "*:*",
                "methods|properties",
                "methods|properties:*",
            };

            foreach (var expression in expressions)
            {
                var aspect = new MyAspect <IService>(expression);

                IService service = aspect.Build(new Service());

                service.DoWork();
                service.Property1 = true;
                try { service.ThrowException(); } catch { }

                Assert.Equal(3 * 3 - 1, aspect.ExecutionCounter);                       //3 * is for the method (2 times) and property (1 time) executions, -1 for the throw that prevents the after execution
                Assert.Equal(1, aspect.ThrowCounter);
            }
        }
Example #2
0
        public void ExpressionsMethodTest()
        {
            var expressions = new string[] {
                "methods:",
                "methods:*",
                "methods:",
                "methods:Do*"
            };

            foreach (var expression in expressions)
            {
                var aspect = new MyAspect <IService>(expression);

                IService service = aspect.Build(new Service());

                service.DoWork();
                service.DoAnotherWork();
                service.Property1 = true;
                try { service.ThrowException(); } catch { }

                if ("methods:Do*".Equals(expression))
                {
                    Assert.Equal(2 * 3, aspect.ExecutionCounter);                               //2 * is for the Do* method (2 times) executions
                    Assert.Equal(0, aspect.ThrowCounter);
                }
                else
                {
                    Assert.Equal(3 * 3 - 1, aspect.ExecutionCounter);                           //3 * is for the method (2 times) executions, -1 for the throw that prevents the after execution
                    Assert.Equal(1, aspect.ThrowCounter);
                }
            }
        }
Example #3
0
        public void ExpressionsPropertiesTest()
        {
            var expressions = new string[] {
                "properties:",
                "properties:*",
                "properties:",
                "properties:Property*"
            };

            foreach (var expression in expressions)
            {
                var aspect = new MyAspect <IService>(expression);

                IService service = aspect.Build(new Service());

                service.DoWork();
                service.DoAnotherWork();
                service.Property1 = true;
                service.Property2 = true;
                try { service.ThrowException(); } catch { }

                Assert.Equal(2 * 3, aspect.ExecutionCounter);                       //2 * is for the properties (3 times) executions
                Assert.Equal(0, aspect.ThrowCounter);
            }
        }