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); }
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); }
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)); } }
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); }
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); }
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); } }
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)); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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. }
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")); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }