public void TestNonMethodExpressionInterceptionFailure() { var someCls = new SomeTestClass(); // Example of improper calling instance method returning string, by using a non-method-call operator. string actual = someCls.GetProxy(TestAspects).Invoke(instance => instance.GetDateString("whatevs") + "123"); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed actual.ToString(CultureInfo.InvariantCulture); }
public void CallConstPerfCounter() { const int baseLineConstParmRunsPerSec = 4000; var dal = new SomeTestClass(); long runsPerSec = RunCounter.SpinPerSec(MillisecToRun, () => dal.GetProxy().Invoke(ctx => ctx.DoNothing(123, "bogus", false, 1m, null))); this.TestContext.WriteLine("DoNothing() INSTANCE PROXIED SQUENTIAL CONSTANTPARAMS got {0} cps, with expected {1} cps.", runsPerSec, baseLineConstParmRunsPerSec); //Assert.IsTrue(runsPerSec >= baseLineConstParmRunsPerSec); }
public void TestOne() { var dal = new SomeTestClass(new DateTime(2010, 2, 5)); // Example of the most common use case: calling instance GetDateString() method returning string. string actual = dal.GetProxy(TestAspects).Invoke(instance => instance.GetDateString("whatevs")); Assert.AreEqual("whatevs 2/5/2010 12:00:00 AM", actual); // Example of instantiating an IDisposable class, calling its instance method returning string, and disposing of class instance. actual = AOP.GetProxy <SomeTestDisposable>(TestAspects).Invoke(dispInstance => dispInstance.Echo("some text")); Assert.AreEqual("some text", actual); }
public void CallPerfCounter() { const int baseLineSingleThreadRunsPerSec = 2700; const int baseLineMultiThreadRunsPerSec = 9500; // 10000; var dal = new SomeTestClass(); long runsPerSec; int parmInt = 123; string parmStr = "bogus"; bool parmBool = false; decimal parmDec = 1.0m; int[] arr = { 1, 2, 3, 4, 5 }; runsPerSec = RunCounter.SpinParallelPerSec(MillisecToRun, () => dal.GetProxy().Invoke(ctx => ctx.DoNothing(parmInt, parmStr, parmBool, parmDec, arr))); this.TestContext.WriteLine("Worst case scenario: DoNothing() INSTANCE PROXIED PARALLEL VARPARAMS got {0} cps, with expected {1} cps.", runsPerSec, baseLineMultiThreadRunsPerSec); //Assert.IsTrue(runsPerSec >= baseLineMultiThreadRunsPerSec); runsPerSec = RunCounter.SpinPerSec(MillisecToRun, () => dal.GetProxy().Invoke(ctx => ctx.DoNothing(parmInt, parmStr, parmBool, parmDec, arr))); this.TestContext.WriteLine("DoNothing() INSTANCE PROXIED SEQUENTIAL VARPARAMS got {0} cps, with expected {1} cps.", runsPerSec, baseLineSingleThreadRunsPerSec); //Assert.IsTrue(runsPerSec >= baseLineSingleThreadRunsPerSec); }
public void TestMethodSignatures() { var obj = new SomeTestClass(); string username, password; username = "******"; password = "******"; obj.GetProxy().Invoke(inst => inst.FakeLogin(username, password)); obj = new SomeTestClass(new DateTime(2010, 11, 5)); //username = "******"; //password = "******"; obj.GetProxy().Invoke(inst => inst.FakeLogin(username, password)); int index = "Wassup".GetProxy(TestAspects).Invoke(str => str.IndexOf('u')); Assert.AreEqual(4, index); }
public void CallPerfCounter() { const int baseLineSingleThreadRunsPerSec = 2700; const int baseLineMultiThreadRunsPerSec = 9500; // 10000; var dal = new SomeTestClass(); long runsPerSec; int parmInt = 123; string parmStr = "bogus"; bool parmBool = false; decimal parmDec = 1.0m; int[] arr = {1, 2, 3, 4, 5}; runsPerSec = RunCounter.SpinParallelPerSec(MillisecToRun, () => dal.GetProxy().Invoke(ctx => ctx.DoNothing(parmInt, parmStr, parmBool, parmDec, arr))); this.TestContext.WriteLine("Worst case scenario: DoNothing() INSTANCE PROXIED PARALLEL VARPARAMS got {0} cps, with expected {1} cps.", runsPerSec, baseLineMultiThreadRunsPerSec); //Assert.IsTrue(runsPerSec >= baseLineMultiThreadRunsPerSec); runsPerSec = RunCounter.SpinPerSec(MillisecToRun, () => dal.GetProxy().Invoke(ctx => ctx.DoNothing(parmInt, parmStr, parmBool, parmDec, arr))); this.TestContext.WriteLine("DoNothing() INSTANCE PROXIED SEQUENTIAL VARPARAMS got {0} cps, with expected {1} cps.", runsPerSec, baseLineSingleThreadRunsPerSec); //Assert.IsTrue(runsPerSec >= baseLineSingleThreadRunsPerSec); }
public void TestInterceptedException() { var someCls = new SomeTestClass(new DateTime(2010, 2, 5)); someCls.GetProxy(TestAspects).Invoke(instance => instance.ThrowFailure()); }
public void TestOne() { var dal = new SomeTestClass(new DateTime(2010, 2, 5)); // Example of the most common use case: calling instance GetDateString() method returning string. string actual = dal.GetProxy(TestAspects).Invoke(instance => instance.GetDateString("whatevs")); Assert.AreEqual("whatevs 2/5/2010 12:00:00 AM", actual); // Example of instantiating an IDisposable class, calling its instance method returning string, and disposing of class instance. actual = AOP.GetProxy<SomeTestDisposable>(TestAspects).Invoke(dispInstance => dispInstance.Echo("some text")); Assert.AreEqual("some text", actual); }