Exemple #1
0
        public void TestPublicMethod()
        {
            var derived = new OptionsTestTargetDerived();

            MethodAdviceContainer.Clear();
            derived.PublicReturnObj(1, "a");
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(12, content.Count);
            Assert.AreEqual("PublicEntry", content.ElementAt(0).Name);
            Assert.AreEqual("PublicReturnObj", content.ElementAt(0).Execution.Name);
            Assert.AreEqual("InstanceEntry", content.ElementAt(1).Name);
            Assert.AreEqual("PublicReturnObj", content.ElementAt(1).Execution.Name);
            Assert.AreEqual("MethodEntry", content.ElementAt(2).Name);
            Assert.AreEqual("PublicReturnObj", content.ElementAt(2).Execution.Name);
            Assert.AreEqual("PrivateEntry", content.ElementAt(3).Name);
            Assert.AreEqual("get_StringBuilder", content.ElementAt(3).Execution.Name);
            Assert.AreEqual("InstanceEntry", content.ElementAt(4).Name);
            Assert.AreEqual("get_StringBuilder", content.ElementAt(4).Execution.Name);
            Assert.AreEqual("PropertyGetterEntry", content.ElementAt(5).Name);
            Assert.AreEqual("get_StringBuilder", content.ElementAt(5).Execution.Name);
            Assert.AreEqual("PropertyGetterExit", content.ElementAt(6).Name);
            Assert.AreEqual("get_StringBuilder", content.ElementAt(6).Execution.Name);
            Assert.AreEqual("InstanceExit", content.ElementAt(7).Name);
            Assert.AreEqual("get_StringBuilder", content.ElementAt(7).Execution.Name);
            Assert.AreEqual("PrivateExit", content.ElementAt(8).Name);
            Assert.AreEqual("get_StringBuilder", content.ElementAt(8).Execution.Name);
            Assert.AreEqual("MethodExit", content.ElementAt(9).Name);
            Assert.AreEqual("PublicReturnObj", content.ElementAt(9).Execution.Name);
            Assert.AreEqual("InstanceExit", content.ElementAt(10).Name);
            Assert.AreEqual("PublicReturnObj", content.ElementAt(10).Execution.Name);
            Assert.AreEqual("PublicExit", content.ElementAt(11).Name);
            Assert.AreEqual("PublicReturnObj", content.ElementAt(11).Execution.Name);
        }
Exemple #2
0
        public void TestNoClassAttribute()
        {
            // Constructor test
            MethodAdviceContainer.Clear();
            var tester  = new OverwriteTestClassNotMarked();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // internal method and attribute concerned by attribute
            MethodAdviceContainer.Clear();
            tester.InternalMethodConceredByAttribute();
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);
            Assert.AreEqual("Entry", content.ElementAt(1).Name);
            Assert.AreEqual("Exit", content.ElementAt(2).Name);
            Assert.AreEqual("Exit", content.ElementAt(3).Name);

            // only exit advice
            MethodAdviceContainer.Clear();
            tester.EntryExit();
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);
            Assert.AreEqual("Exit", content.ElementAt(1).Name);

            // not concerned by property attribute
            MethodAdviceContainer.Clear();
            tester.InternalProperty = 1;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
        }
Exemple #3
0
 public void TestNoExecution()
 {
     MethodAdviceContainer.Clear();
     try
     {
         ParameterTestTarget.NoExecutionTest();
     }
     catch (Exception e)
     {
         Console.Out.WriteLine(e.Message);
     }
     finally
     {
         var content = MethodAdviceContainer.Content;
         MethodAdviceContainer.PrintContent(Console.Out);
         Assert.AreEqual(3, content.Count);
         Assert.IsNull(content.ElementAt(0).Execution);
         Assert.IsNull(content.ElementAt(1).Execution);
         Assert.IsNotNull(content.ElementAt(1).Exception);
         Assert.IsNull(content.ElementAt(2).Execution);
         Assert.IsNotNull(content.ElementAt(2).Return);
         Assert.IsFalse(content.ElementAt(2).Return.HasReturn);
         var hasException = content.ElementAt(2).HasException;
         Assert.IsTrue(hasException != null && (hasException.HasValue && hasException.Value));
     }
 }
Exemple #4
0
        public void TestAbstractMethod()
        {
            var derived = new OptionsTestTargetDerived();

            MethodAdviceContainer.Clear();
            derived.TestAbstract(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(12, content.Count);
            Assert.AreEqual("ProtectedEntry", content.ElementAt(0).Name);
            Assert.AreEqual("ProtectedReturnString", content.ElementAt(0).Execution.Name);
            Assert.AreEqual("StaticEntry", content.ElementAt(1).Name);
            Assert.AreEqual("ProtectedReturnString", content.ElementAt(1).Execution.Name);
            Assert.AreEqual("MethodEntry", content.ElementAt(2).Name);
            Assert.AreEqual("ProtectedReturnString", content.ElementAt(2).Execution.Name);
            Assert.AreEqual("PublicEntry", content.ElementAt(3).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(3).Execution.Name);
            Assert.AreEqual("StaticEntry", content.ElementAt(4).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(4).Execution.Name);
            Assert.AreEqual("PropertyGetterEntry", content.ElementAt(5).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(5).Execution.Name);
            Assert.AreEqual("PropertyGetterExit", content.ElementAt(6).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(6).Execution.Name);
            Assert.AreEqual("StaticExit", content.ElementAt(7).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(7).Execution.Name);
            Assert.AreEqual("PublicExit", content.ElementAt(8).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(8).Execution.Name);
            Assert.AreEqual("MethodExit", content.ElementAt(9).Name);
            Assert.AreEqual("ProtectedReturnString", content.ElementAt(9).Execution.Name);
            Assert.AreEqual("StaticExit", content.ElementAt(10).Name);
            Assert.AreEqual("ProtectedReturnString", content.ElementAt(10).Execution.Name);
            Assert.AreEqual("ProtectedExit", content.ElementAt(11).Name);
            Assert.AreEqual("ProtectedReturnString", content.ElementAt(11).Execution.Name);
        }
Exemple #5
0
        public void TestInternalProperty()
        {
            var derived = new OptionsTestTargetDerived();

            MethodAdviceContainer.Clear();
            derived.InternalInstanceFunc(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(12, content.Count);
            Assert.AreEqual("InternalEntry", content.ElementAt(0).Name);
            Assert.AreEqual("get_InternalInstanceFunc", content.ElementAt(0).Execution.Name);
            Assert.AreEqual("InstanceEntry", content.ElementAt(1).Name);
            Assert.AreEqual("get_InternalInstanceFunc", content.ElementAt(1).Execution.Name);
            Assert.AreEqual("PropertyGetterEntry", content.ElementAt(2).Name);
            Assert.AreEqual("get_InternalInstanceFunc", content.ElementAt(2).Execution.Name);
            Assert.AreEqual("PropertyGetterExit", content.ElementAt(3).Name);
            Assert.AreEqual("get_InternalInstanceFunc", content.ElementAt(3).Execution.Name);
            Assert.AreEqual("InstanceExit", content.ElementAt(4).Name);
            Assert.AreEqual("get_InternalInstanceFunc", content.ElementAt(4).Execution.Name);
            Assert.AreEqual("InternalExit", content.ElementAt(5).Name);
            Assert.AreEqual("get_InternalInstanceFunc", content.ElementAt(5).Execution.Name);
            Assert.AreEqual("PrivateEntry", content.ElementAt(6).Name);
            Assert.AreEqual("Square", content.ElementAt(6).Execution.Name);
            Assert.AreEqual("StaticEntry", content.ElementAt(7).Name);
            Assert.AreEqual("Square", content.ElementAt(7).Execution.Name);
            Assert.AreEqual("MethodEntry", content.ElementAt(8).Name);
            Assert.AreEqual("Square", content.ElementAt(8).Execution.Name);
            Assert.AreEqual("MethodExit", content.ElementAt(9).Name);
            Assert.AreEqual("Square", content.ElementAt(9).Execution.Name);
            Assert.AreEqual("StaticExit", content.ElementAt(10).Name);
            Assert.AreEqual("Square", content.ElementAt(10).Execution.Name);
            Assert.AreEqual("PrivateExit", content.ElementAt(11).Name);
            Assert.AreEqual("Square", content.ElementAt(11).Execution.Name);
        }
Exemple #6
0
 public void Test2()
 {
     MethodAdviceContainer.Clear();
     try
     {
         ContextTestTarget.Test2(1);
     }
     catch (Exception e)
     {
         Console.Out.WriteLine(e.Message);
     }
     finally
     {
         var content = MethodAdviceContainer.Content;
         MethodAdviceContainer.PrintContent(Console.Out);
         Assert.AreEqual(3, content.Count);
         Assert.IsNotNull(content.ElementAt(0).Context);
         Assert.IsNotNull(content.ElementAt(1).Context);
         Assert.IsNotNull(content.ElementAt(2).Context);
         Assert.AreEqual(((TestObj)content.ElementAt(0).Context.Get("Exception1")).Value1, ((TestObj)content.ElementAt(1).Context.Get("Exception1")).Value1);
         Assert.AreEqual(((TestObj)content.ElementAt(0).Context.Get("Exception1")).Value2, ((TestObj)content.ElementAt(1).Context.Get("Exception1")).Value2);
         Assert.AreEqual(((TestObj)content.ElementAt(1).Context.Get("Exception1")).Value1, ((TestObj)content.ElementAt(2).Context.Get("Exception1")).Value1);
         Assert.AreEqual(((TestObj)content.ElementAt(1).Context.Get("Exception1")).Value2, ((TestObj)content.ElementAt(2).Context.Get("Exception1")).Value2);
     }
 }
Exemple #7
0
 public void TestAllException()
 {
     MethodAdviceContainer.Clear();
     try
     {
         ParameterTestTarget.AllExceptionTest(10, new StringBuilder("abc"), Square);
     }
     catch (Exception e)
     {
         Assert.AreEqual("abc100", e.Message);
     }
     finally
     {
         var content = MethodAdviceContainer.Content;
         MethodAdviceContainer.PrintContent(Console.Out);
         Assert.AreEqual(3, content.Count);
         Assert.IsNotNull(content.ElementAt(0).Execution);
         Assert.AreEqual(3, content.ElementAt(0).Execution.Parameters.Count);
         Assert.AreEqual(10, content.ElementAt(0).Execution.Parameters.ElementAt(0).Value);
         Assert.AreEqual("abc", content.ElementAt(0).Execution.Parameters.ElementAt(1).Value.ToString());
         Assert.AreEqual(typeof(Func <int, int>), content.ElementAt(0).Execution.Parameters.ElementAt(2).Value.GetType());
         Assert.IsNotNull(content.ElementAt(1).Execution);
         Assert.AreEqual(3, content.ElementAt(1).Execution.Parameters.Count);
         Assert.AreEqual("abc100", content.ElementAt(1).Exception.Message);
         Assert.IsNotNull(content.ElementAt(2).Execution);
         Assert.AreEqual(3, content.ElementAt(2).Execution.Parameters.Count);
         Assert.IsNotNull(content.ElementAt(2).Return);
         Assert.IsFalse(content.ElementAt(2).Return.HasReturn);
         var hasException = content.ElementAt(2).HasException;
         Assert.IsTrue(hasException != null && (hasException.HasValue && hasException.Value));
     }
 }
Exemple #8
0
        public void TestClassAttributeOverwrite()
        {
            // Constructor test
            MethodAdviceContainer.Clear();
            var tester  = new OverwriteTestClassPropertyConcerned();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // setter not concerned
            MethodAdviceContainer.Clear();
            tester.InernalProperty = 1;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // getter concerned
            MethodAdviceContainer.Clear();
            Console.Out.WriteLine(tester.InernalProperty);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);
            Assert.AreEqual("Exit", content.ElementAt(1).Name);

            // method not concerned
            MethodAdviceContainer.Clear();
            tester.NotConcernedMethod();
            content = MethodAdviceContainer.Content;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
        }
Exemple #9
0
        public void TestSwitchClassAspect()
        {
            SwitchFacade.Controller.SwitchOff(typeof(SwitchClassAspectTestTarget), Switch2);
            MethodAdviceContainer.Clear();
            SwitchClassAspectTestTarget.Test(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.AreEqual("Entry3", content.ElementAt(0).Name);
            Assert.AreEqual("Exit3", content.ElementAt(1).Name);

            MethodAdviceContainer.Clear();
            SwitchCompareTestTarget.Test1(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            SwitchFacade.Controller.Switch(typeof(SwitchClassAspectTestTarget), Switch2);
            MethodAdviceContainer.Clear();
            SwitchClassAspectTestTarget.Test(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);
        }
Exemple #10
0
        public void TestNoReturn()
        {
            MethodAdviceContainer.Clear();
            ParameterTestTarget.NoReturnTest(10, Square);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.IsNull(content.ElementAt(1).Return);
        }
Exemple #11
0
 public void TestExactMatch()
 {
     // matched by exact overwrites all
     MethodAdviceContainer.Clear();
     NameExpressionTestTarget.NotMentionedToTestExactOverwrite();
     var content = MethodAdviceContainer.Content;
     MethodAdviceContainer.PrintContent(Console.Out);
     Assert.AreEqual(1, content.Count);
     Assert.AreEqual("Entry", content.ElementAt(0).Name);
 }
Exemple #12
0
        public void TestSwitchProperty()
        {
            SwitchFacade.Controller.SwitchOff(typeof(SwitchPropertyTestTarget).GetProperty("Value1"));
            MethodAdviceContainer.Clear();
            SwitchPropertyTestTarget.Value1 = 1;
            Console.Out.WriteLine(SwitchPropertyTestTarget.Value1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            MethodAdviceContainer.Clear();
            SwitchPropertyTestTarget.Value2 = 1;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            MethodAdviceContainer.Clear();
            Console.Out.WriteLine(SwitchPropertyTestTarget.Value2);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            SwitchFacade.Controller.SwitchOn(typeof(SwitchPropertyTestTarget).GetProperty("Value1"));
            SwitchFacade.Controller.Switch(typeof(SwitchPropertyTestTarget).GetProperty("Value2"));
            MethodAdviceContainer.Clear();
            SwitchPropertyTestTarget.Value2 = 1;
            Console.Out.WriteLine(SwitchPropertyTestTarget.Value2);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            MethodAdviceContainer.Clear();
            SwitchPropertyTestTarget.Value1 = 1;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            MethodAdviceContainer.Clear();
            Console.Out.WriteLine(SwitchPropertyTestTarget.Value1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);
        }
Exemple #13
0
        public void TestLoadedAspectBuilder()
        {
            // included method
            MethodAdviceContainer.Clear();
            LoadAspectBuilderTestTarget.MethodToBeConcerned();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(1, content.Count);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);
        }
Exemple #14
0
        public void TestNotWeaved()
        {
            var derived = new OptionsTestTargetDerived();

            MethodAdviceContainer.Clear();
            derived.Square(10);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
        }
Exemple #15
0
        public void TestAll()
        {
            MethodAdviceContainer.Clear();
            var x       = ParameterTestTarget.AllTest();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.IsTrue(content.ElementAt(1).Return.HasReturn);
            Assert.AreEqual(x, content.ElementAt(1).Return.Value);
        }
Exemple #16
0
        public void TestAaConstructor()
        {
            MethodAdviceContainer.Clear();
            var derived = new OptionsTestTargetDerived();

            Console.Out.WriteLine(derived);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(18, content.Count);

            // private static constructor
            Assert.AreEqual("PrivateEntry", content.ElementAt(0).Name);
            Assert.AreEqual(".cctor", content.ElementAt(0).Execution.Name);
            Assert.AreEqual("StaticEntry", content.ElementAt(1).Name);
            Assert.AreEqual(".cctor", content.ElementAt(1).Execution.Name);
            Assert.AreEqual("MethodEntry", content.ElementAt(2).Name);
            Assert.AreEqual(".cctor", content.ElementAt(2).Execution.Name);
            Assert.AreEqual("MethodExit", content.ElementAt(3).Name);
            Assert.AreEqual(".cctor", content.ElementAt(3).Execution.Name);
            Assert.AreEqual("StaticExit", content.ElementAt(4).Name);
            Assert.AreEqual(".cctor", content.ElementAt(4).Execution.Name);
            Assert.AreEqual("PrivateExit", content.ElementAt(5).Name);
            Assert.AreEqual(".cctor", content.ElementAt(5).Execution.Name);

            // base class constructor
            Assert.AreEqual("ProtectedEntry", content.ElementAt(6).Name);
            Assert.AreEqual(".ctor", content.ElementAt(6).Execution.Name);
            Assert.AreEqual("InstanceEntry", content.ElementAt(7).Name);
            Assert.AreEqual(".ctor", content.ElementAt(7).Execution.Name);
            Assert.AreEqual("MethodEntry", content.ElementAt(8).Name);
            Assert.AreEqual(".ctor", content.ElementAt(8).Execution.Name);
            Assert.AreEqual("InternalEntry", content.ElementAt(9).Name);
            Assert.AreEqual("set_InternalInstanceFunc", content.ElementAt(9).Execution.Name);
            Assert.AreEqual("InstanceEntry", content.ElementAt(10).Name);
            Assert.AreEqual("set_InternalInstanceFunc", content.ElementAt(10).Execution.Name);
            Assert.AreEqual("PropertySetterEntry", content.ElementAt(11).Name);
            Assert.AreEqual("set_InternalInstanceFunc", content.ElementAt(11).Execution.Name);
            Assert.AreEqual("PropertySetterExit", content.ElementAt(12).Name);
            Assert.AreEqual("set_InternalInstanceFunc", content.ElementAt(12).Execution.Name);
            Assert.AreEqual("InstanceExit", content.ElementAt(13).Name);
            Assert.AreEqual("set_InternalInstanceFunc", content.ElementAt(13).Execution.Name);
            Assert.AreEqual("InternalExit", content.ElementAt(14).Name);
            Assert.AreEqual("set_InternalInstanceFunc", content.ElementAt(14).Execution.Name);
            Assert.AreEqual("MethodExit", content.ElementAt(15).Name);
            Assert.AreEqual(".ctor", content.ElementAt(15).Execution.Name);
            Assert.AreEqual("InstanceExit", content.ElementAt(16).Name);
            Assert.AreEqual(".ctor", content.ElementAt(16).Execution.Name);
            Assert.AreEqual("ProtectedExit", content.ElementAt(17).Name);
            Assert.AreEqual(".ctor", content.ElementAt(17).Execution.Name);

            // derived class constructor is not concerned.
        }
Exemple #17
0
        public void Test7()
        {
            MethodAdviceContainer.Clear();
            ContextTestTarget.Test7(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.IsNull(content.ElementAt(0).Context);
            Assert.IsNotNull(content.ElementAt(1).Context);
            Assert.IsFalse(content.ElementAt(1).Context.Exist("Entry1"));
            Assert.IsFalse(content.ElementAt(1).Context.Exist("Exception1"));
        }
Exemple #18
0
        public void Test3()
        {
            MethodAdviceContainer.Clear();
            ContextTestTarget.Test3(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.IsNotNull(content.ElementAt(0).Context);
            Assert.IsNull(content.ElementAt(1).Context);
            Assert.AreEqual(1, ((TestObj)content.ElementAt(0).Context.Get("Entry1")).Value1);
            Assert.AreEqual("Entry1", ((TestObj)content.ElementAt(0).Context.Get("Entry1")).Value2);
        }
Exemple #19
0
        public void TestVoidReturn()
        {
            MethodAdviceContainer.Clear();
            ParameterTestTarget.AllVoidReturnTest();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.IsNotNull(content.ElementAt(1).Return);
            Assert.IsFalse(content.ElementAt(1).Return.HasReturn);
            var hasException = content.ElementAt(1).HasException;

            Assert.IsFalse(hasException != null && (hasException.HasValue && hasException.Value));
        }
Exemple #20
0
        public void TextExcluded()
        {
            // excluded method
            MethodAdviceContainer.Clear();
            NameExpressionTestTarget.MethodNotToBeConcerned();
            var content = MethodAdviceContainer.Content;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // excluded property
            MethodAdviceContainer.Clear();
            NameExpressionTestTarget.PropertyNotToBeConcerned = 2;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
        }
Exemple #21
0
        public void TestNotMentioned()
        {
            // not mentioned method
            MethodAdviceContainer.Clear();
            NameExpressionTestTarget.MethodNotMentioned();
            var content = MethodAdviceContainer.Content;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // not mentioned property
            MethodAdviceContainer.Clear();
            NameExpressionTestTarget.PropertyNotMentioned = 1;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
        }
Exemple #22
0
        public void TestMixed()
        {
            MethodAdviceContainer.Clear();
            MixedTestTarget.ConcernedByAttributeAndClassName();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(7, content.Count);
            Assert.AreEqual("EntryByAttribute1", content.ElementAt(0).Name);
            Assert.AreEqual("EntryByAttribute2", content.ElementAt(1).Name);
            Assert.AreEqual("EntryByAttribute3", content.ElementAt(2).Name);
            Assert.AreEqual("ExitByAttribute1", content.ElementAt(3).Name);
            Assert.AreEqual("ExitByNameExpression", content.ElementAt(4).Name);
            Assert.AreEqual("ExitByAttribute2", content.ElementAt(5).Name);
            Assert.AreEqual("ExitByAttribute3", content.ElementAt(6).Name);
        }
Exemple #23
0
        public void TestSwitchPropertyAspect()
        {
            SwitchFacade.Controller.Switch(typeof(SwitchPropertyAspectTestTarget).GetProperty("Value"), Switch2);
            MethodAdviceContainer.Clear();
            SwitchPropertyAspectTestTarget.Value = 1;
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.AreEqual("Entry3", content.ElementAt(0).Name);
            Assert.AreEqual("Exit3", content.ElementAt(1).Name);

            MethodAdviceContainer.Clear();
            Console.Out.Write(SwitchPropertyAspectTestTarget.Value);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.AreEqual("Entry3", content.ElementAt(0).Name);
            Assert.AreEqual("Exit3", content.ElementAt(1).Name);

            MethodAdviceContainer.Clear();
            SwitchCompareTestTarget.Test1(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            SwitchFacade.Controller.SwitchOn(typeof(SwitchPropertyAspectTestTarget).GetProperty("Value"), Switch2);
            MethodAdviceContainer.Clear();
            SwitchPropertyAspectTestTarget.Value = 1;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            MethodAdviceContainer.Clear();
            Console.Out.Write(SwitchPropertyAspectTestTarget.Value);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);
        }
Exemple #24
0
        public void TestClassOverwrittenByOther()
        {
            // Constructor test
            MethodAdviceContainer.Clear();
            var tester  = new OverwriteTestTarget();
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // no concern method
            MethodAdviceContainer.Clear();
            tester.NoConcernMethod();
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            // point cut overwrite & exception
            MethodAdviceContainer.Clear();
            try
            {
                tester.ThrowException();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                MethodAdviceContainer.PrintContent(Console.Out);
                Assert.AreEqual(3, content.Count);
                Assert.AreEqual("Entry", content.ElementAt(0).Name);
                Assert.AreEqual("Exception", content.ElementAt(1).Name);
                Assert.AreEqual("Exit", content.ElementAt(2).Name);
            }

            // overwrite by method concern and overwrite by property no concern
            MethodAdviceContainer.Clear();
            OverwriteTestTarget.OverwriteByMethodConcern();
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);
            Assert.AreEqual("Entry", content.ElementAt(1).Name);
            Assert.AreEqual("Exit", content.ElementAt(2).Name);
            Assert.AreEqual("Exit", content.ElementAt(3).Name);
        }
Exemple #25
0
        public void TestIncluded()
        {
            // included method
            MethodAdviceContainer.Clear();
            NameExpressionTestTarget.MethodToBeConcerned();
            var content = MethodAdviceContainer.Content;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(1, content.Count);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);

            // included property
            MethodAdviceContainer.Clear();
            NameExpressionTestTarget.PropertyToBeConcerned = 3;
            Console.Out.WriteLine(NameExpressionTestTarget.PropertyToBeConcerned);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(1, content.Count);
            Assert.AreEqual("Entry", content.ElementAt(0).Name);
        }
Exemple #26
0
        public void TestSwitchOnlyExecution()
        {
            var clazz = typeof(SwitchOnlyExecutionTestTarget);

            MethodAdviceContainer.Clear();
            SwitchFacade.Controller.SwitchOff(clazz, Switch10);
            SwitchOnlyExecutionTestTarget.Test(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
            SwitchFacade.Controller.SwitchOn(clazz, Switch10);
            SwitchOnlyExecutionTestTarget.Test(1);
            content = MethodAdviceContainer.Content;
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual("Entry8", content.ElementAt(0).Name);
            Assert.AreEqual("Exit8", content.ElementAt(1).Name);
        }
Exemple #27
0
        public void TestSwitchMethod()
        {
            SwitchFacade.Controller.SwitchOff(typeof(SwitchMethodTestTarget).GetMethod("Test1"));
            MethodAdviceContainer.Clear();
            SwitchMethodTestTarget.Test1(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);

            MethodAdviceContainer.Clear();
            SwitchMethodTestTarget.Test2(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            MethodAdviceContainer.Clear();
            SwitchCompareTestTarget.Test1(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            SwitchFacade.Controller.SwitchOn(typeof(SwitchMethodTestTarget).GetMethod("Test1"));
            SwitchFacade.Controller.SwitchOff(typeof(SwitchMethodTestTarget).GetMethod("Test2"));
            MethodAdviceContainer.Clear();
            SwitchMethodTestTarget.Test1(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(4, content.Count);
            Assert.AreEqual("Entry2", content.ElementAt(0).Name);
            Assert.AreEqual("Entry3", content.ElementAt(1).Name);
            Assert.AreEqual("Exit3", content.ElementAt(2).Name);
            Assert.AreEqual("Exit2", content.ElementAt(3).Name);

            MethodAdviceContainer.Clear();
            SwitchMethodTestTarget.Test2(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
        }
Exemple #28
0
 public void TestNoException()
 {
     MethodAdviceContainer.Clear();
     try
     {
         ParameterTestTarget.NoExceptionTest();
     }
     catch (Exception e)
     {
         Console.Out.WriteLine(e.Message);
     }
     finally
     {
         var content = MethodAdviceContainer.Content;
         MethodAdviceContainer.PrintContent(Console.Out);
         Assert.AreEqual(1, content.Count);
         Assert.IsNull(content.ElementAt(0).Exception);
     }
 }
Exemple #29
0
        public void TestSwitchNoReturn()
        {
            var clazz = typeof(SwitchNoReturnTestTarget);

            MethodAdviceContainer.Clear();
            SwitchFacade.Controller.SwitchOff(clazz, Switch8);
            SwitchNoReturnTestTarget.Test(1);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(0, content.Count);
            SwitchFacade.Controller.SwitchOn(clazz, Switch8);
            SwitchNoReturnTestTarget.Test(1);
            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(2, content.Count);
            Assert.AreEqual("Exit6", content.ElementAt(1).Name);
            Assert.IsTrue(content.ElementAt(1).HasException.HasValue);
            Assert.IsFalse(content.ElementAt(1).HasException);
        }
Exemple #30
0
        public void TestStatic()
        {
            MethodAdviceContainer.Clear();
            Console.Out.WriteLine(OptionsTestTargetBase.PublicStaticInt);
            var content = MethodAdviceContainer.Content;

            MethodAdviceContainer.PrintContent(Console.Out);
            Assert.AreEqual(content.Count, 6);
            Assert.AreEqual("PublicEntry", content.ElementAt(0).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(0).Execution.Name);
            Assert.AreEqual("StaticEntry", content.ElementAt(1).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(1).Execution.Name);
            Assert.AreEqual("PropertyGetterEntry", content.ElementAt(2).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(2).Execution.Name);
            Assert.AreEqual("PropertyGetterExit", content.ElementAt(3).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(3).Execution.Name);
            Assert.AreEqual("StaticExit", content.ElementAt(4).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(4).Execution.Name);
            Assert.AreEqual("PublicExit", content.ElementAt(5).Name);
            Assert.AreEqual("get_PublicStaticInt", content.ElementAt(5).Execution.Name);
        }