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