public void Test_Static_Multiple_Outs_And_ReturnValue() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { string inp; int inp2; CallMe(out inp, out inp2); } private static string CallMe(out string param, out int para2) { param = ""rv""; para2 = 42; return ""response""; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "response"); result.ElementAt(1).ShouldBeTraceLeaveWithOutsFrom("First.MyClass::CallMe", "param", "rv", "para2", "42"); }
public void Test_Static_Empty_Method_Returns_Object() { string code = @" using System; using System.Diagnostics; namespace First { public class MyRetVal {} public class MyClass { public static void Main() { var val = GetValue(); } private static MyRetVal GetValue() { return new MyRetVal(); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::GetValue"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::GetValue", "First.MyRetVal"); }
public void Test_Returning_From_NestedScope() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { CallMe(""Hello"", ""Hello2"", 42); } private static string CallMe(string param, string param2, int paraInt) { for (int i=0; i < 1; i++) { return ""response"" + paraInt.ToString(); } return String.Empty; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "response42"); }
public void Test_Static_Class() { string code = @" using System; using System.Diagnostics; namespace First { public class InnerClass { public string Value { get; set; } } public class MyClass { public static void Main() { InnerClass inp; CallMe(out inp); } private static void CallMe(out InnerClass param) { param = new InnerClass() { Value=""Hi"" }; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe"); result.ElementAt(1).ShouldBeTraceLeaveWithOutsFrom("First.MyClass::CallMe", "param", "First.InnerClass"); //ToString=First.InnerClass }
public void Test_Static_Empty_Method() { string code = @" using System; using System.Diagnostics; using System.Threading; namespace First { public class MyClass { public static void Main() { Thread.Sleep(10); } } } "; MockLogResult result = RunTest(code, new AllTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::Main"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::Main"); result.ElementAt(1).NumberOfTicks.Should().BeGreaterThan(0); }
public void Test_Static_Int() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { int inp = 42; CallMe(ref inp); } private static void CallMe(ref int param) { param = 24; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "42"); result.ElementAt(1).ShouldBeTraceLeaveWithOutsFrom("First.MyClass::CallMe", "param", "24"); }
public void Test_Property_Setter() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { private int _intValue; public static void Main() { var mc = new MyClass(); mc.IntValue = 2; } private int IntValue { set { _intValue = value; } } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::set_IntValue", "value", "2"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::set_IntValue"); }
public void TestLoging_In_Closure() { string code = @" using System; using System.Diagnostics; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { delegate void TestDelegate(); public static void Main() { int foo = 1; TestDelegate dlg = () => { foo++; MockLog.OuterNoParam(); }; dlg(); } } } "; MockLogResult result = RunTest(code, new NoTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(1); result.ElementAt(0).ShouldBeLogCall("First.MyClass::Main", "MockLogOuterNoParam"); result.ElementAt(0).ContainingMethod.Should().Be("Main()"); }
public void Test_Static_Empty_Method() { string code = @" using System; using System.Diagnostics; using System.Threading; namespace First { public class MyClass { public static void Main() { try { MyStatic(); } catch { } } public static void MyStatic() { throw new ApplicationException(""failed""); } } } "; MockLogResult result = RunTest(code, new AllTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::Main"); result.ElementAt(1).ShouldBeTraceEnterInto("First.MyClass::MyStatic"); result.ElementAt(2).ShouldBeTraceLeaveWithExceptionFrom("First.MyClass::MyStatic", "failed"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::Main"); }
public void Test_Static_MultipleParameters() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { try { CallMe(""Hello"", ""Hello2"", 42); } catch {} } private static string CallMe(string param, string param2, int paraInt) { throw new ApplicationException(""failed""); return ""response"" + paraInt.ToString(); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceLeaveWithExceptionFrom("First.MyClass::CallMe", "failed"); }
public void Test_Static_ObjectParameter() { string code = @" using System; using System.Diagnostics; namespace First { public class MyInput {} public class MyClass { public static void Main() { CallMe(new MyInput()); } private static void CallMe(MyInput param) { } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "First.MyInput"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe"); }
public void Test_Static_SingleIntParameter_Empty_Method() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { SetInt(42); } private static void SetInt(int param) { } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::SetInt", "param", "42"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::SetInt"); }
public void Test_Static_SingleStructParameter_Empty_Method() { string code = @" using System; using System.Diagnostics; namespace First { public struct MyStruct { public string ValStr {get; set;} public int ValInt {get; set;} } public class MyClass { public static void Main() { SetStruct(new MyStruct() { ValStr=""Hi"", ValInt=42 }); } private static void SetStruct(MyStruct param) { } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::SetStruct", "param", "First.MyStruct"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::SetStruct"); }
public void Test_Static_MultipleParameters() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { CallMe(""Hello"", ""Hello2"", 42); } private static void CallMe(string param, string param2, int paraInt) { } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe"); }
public void Test_Generic_ReturnValue_Method() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { var myClass = new MyClass(); var r1 = myClass.CallMe<string>(""Hello""); var r2 = myClass.CallMe<int>(""Ahoy""); } private T CallMe<T>(string param) { return default(T); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", null); result.ElementAt(2).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Ahoy"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "0"); }
public void TestLoging_In_Lambda() { string code = @" using System; using System.Diagnostics; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { public static void Main() { Action act = () => { MockLog.OuterNoParam(); }; act(); } } } "; MockLogResult result = RunTest(code, new NoTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(1); result.ElementAt(0).ShouldBeLogCall("First.MyClass::Main", "MockLogOuterNoParam"); result.ElementAt(0).ContainingMethod.Should().Be("Main()"); }
public void Test_Instance_MultipleParameters_Returns_Int() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { var myClass = new MyClass(); myClass.CallMe(""Hello"", ""Hello2"", 42); myClass.CallMe(""Ahoy"", ""Ahoy2"", 43); } private int CallMe(string param, string param2, int paraInt) { return paraInt * 2; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "84"); result.ElementAt(2).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Ahoy", "param2", "Ahoy2", "paraInt", "43"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "86"); }
public void Test_Multiple_LogCalls_NoTracing() { string code = @" using System; using System.Diagnostics; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { public static void Main() { MockLog.Outer(""Hello""); int i = 1; MockLog.Outer(""String"", i); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeLogCall("First.MyClass::Main", "MockLogOuter", "Hello"); result.ElementAt(1).ShouldBeLogCall("First.MyClass::Main", "MockLogOuter", "String", "1"); }
public void Test_Generic_Parameter_Method() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { var myClass = new MyClass(); myClass.CallMe<string, int>(""Hello"", ""Hello2"", 42); myClass.CallMe<string, double>(""Ahoy"", ""Ahoy2"", 0.5); } private string CallMe<T, K>(T param, string param2, K paraNum) { return param2 + ""!""; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraNum", "42"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "Hello2!"); result.ElementAt(2).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Ahoy", "param2", "Ahoy2", "paraNum", $"0{Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator}5"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "Ahoy2!"); }
public void Test_Instance_Empty_Method() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { var myClass = new MyClass(); myClass.Run(); } public void Run() { } } } "; MockLogResult result = RunTest(code, new AllTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::Main"); result.ElementAt(1).ShouldBeTraceEnterInto("First.MyClass::Run"); result.ElementAt(2).ShouldBeTraceLeaveFrom("First.MyClass::Run"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::Main"); }
public void Test_Static_Double() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { double inp; CallMe(out inp); } private static void CallMe(out double param) { param = 42.5; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe"); result.ElementAt(1).ShouldBeTraceLeaveWithOutsFrom("First.MyClass::CallMe", "param", 42.5.ToString()); }
public void Test_Instance_Empty_Method_Returns_Int() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { var mc = new MyClass(); var i = mc.GetIntValue(); } private int GetIntValue() { return 1; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::GetIntValue"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::GetIntValue", "1"); }
public void Test_Static_OutParameter_NotListed() { string code = @" using System; using System.Diagnostics; namespace First { public class MyClass { public static void Main() { string outval; SetString(""Hello"", out outval); } private static void SetString(string param, out string outval) { outval = ""outval""; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::SetString", "param", "Hello"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::SetString"); }
public void TestLoging_In_StaticConstructor() { string code = @" using System; using System.Diagnostics; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { static MyClass() { MockLog.OuterNoParam(); } public static void Main() { var myClass = new MyClass(); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(1); result.ElementAt(0).ShouldBeLogCall("First.MyClass::.cctor()", "MockLogOuterNoParam"); }
public void Test_AsyncLoggingCallOrderWithException() { string code = @" using System; using System.Diagnostics; using System.Threading.Tasks; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { public static void Main() { try { var myClass = new MyClass(); var x1 = myClass.CallMe(""Hello"", ""Hello2"", 42).Result; } catch {} } private async Task<int> CallMe(string param, string param2, int paraInt) { var result = await Double(paraInt); return result; } private async Task<int> Double(int p) { return await Task.Run(() => Calculate()); } public int Calculate() { throw new ApplicationException(""Err""); return 1; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(6); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceEnterInto("First.MyClass::Double", "p", "42"); result.ElementAt(4).ShouldBeTraceLeaveWithExceptionFrom("First.MyClass::Double", "Err"); result.ElementAt(5).ShouldBeTraceLeaveWithExceptionFrom("First.MyClass::CallMe", "Err"); }
public void Test_GenericAsyncRetval() { string code = @" using System; using System.Diagnostics; using System.Threading.Tasks; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { public static void Main() { var myClass = new MyClass(); var x1 = myClass.CallMe<string>(""Hello"", ""Hello2"", 42).Result; var x2 = myClass.CallMe<int>(12, ""Ahoy2"", 43).Result; } private async Task<T> CallMe<T>(T param, string param2, int paraInt) { var result = await Double(paraInt); return param; } public async Task<int> Double(int p) { return await Task.Run(()=> p * 2); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "Hello"); result.ElementAt(2).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "12", "param2", "Ahoy2", "paraInt", "43"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::CallMe", "12"); }
public void Test_AsyncNoReturnValue() { string code = @" using System; using System.Diagnostics; using System.Threading.Tasks; using Tracer.Fody.Tests.MockLoggers; namespace First { public class MyClass { public static void Main() { var myClass = new MyClass(); myClass.CallMe(""Hello"", ""Hello2"", 42).Wait(); } private async Task CallMe(string param, string param2, int paraInt) { var result = await Double(paraInt); return; } private async Task<int> Double(int p) { return await Task.Run(()=> p * 2); } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "Hello", "param2", "Hello2", "paraInt", "42"); result.ElementAt(1).ShouldBeTraceEnterInto("First.MyClass::Double", "p", "42"); result.ElementAt(2).ShouldBeTraceLeaveFrom("First.MyClass::Double", "84"); result.ElementAt(3).ShouldBeTraceLeaveFrom("First.MyClass::CallMe"); }
public void Test_Instance_Empty_Method_Returns_Struct() { string code = @" using System; using System.Diagnostics; namespace First { public struct MyStruct { public int IntVal { get; set; } public override string ToString() { return String.Format(""I{0}"", IntVal); } } public class MyClass { public static void Main() { var mc = new MyClass(); var i = mc.GetStructValue(); } private MyStruct GetStructValue() { return new MyStruct() { IntVal = 42 }; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::GetStructValue"); result.ElementAt(1).ShouldBeTraceLeaveFrom("First.MyClass::GetStructValue", "I42"); }
public void Test_Static_Struct() { string code = @" using System; using System.Diagnostics; namespace First { public struct MyStruct { public int IntVal { get; set; } public override string ToString() { return String.Format(""I{0}"", IntVal); } } public class MyClass { public static void Main() { MyStruct inp = new MyStruct() { IntVal = 42 }; CallMe(ref inp); } private static void CallMe(ref MyStruct param) { param = new MyStruct() { IntVal = 24 }; } } } "; MockLogResult result = RunTest(code, new PrivateOnlyTraceLoggingFilter(), "First.MyClass::Main"); result.Count.Should().Be(2); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass::CallMe", "param", "I42"); result.ElementAt(1).ShouldBeTraceLeaveWithOutsFrom("First.MyClass::CallMe", "param", "I24"); }
public void Test_Instance_Generic() { string code = @" using System; using System.Diagnostics; namespace First { public class StartupClass { public static void Main() { var mc1 = new MyClass<string>(); string outp1; mc1.CallMe(out outp1); var mc2 = new MyClass<int>(); int outp2; mc2.CallMe(out outp2); } } public class MyClass<T> { internal void CallMe(out T param) { param = default(T); } } } "; MockLogResult result = RunTest(code, new InternalOnlyTraceLoggingFilter(), "First.StartupClass::Main"); result.Count.Should().Be(4); result.ElementAt(0).ShouldBeTraceEnterInto("First.MyClass<String>::CallMe"); result.ElementAt(1).ShouldBeTraceLeaveWithOutsFrom("First.MyClass<String>::CallMe", "param", null); result.ElementAt(2).ShouldBeTraceEnterInto("First.MyClass<Int32>::CallMe"); result.ElementAt(3).ShouldBeTraceLeaveWithOutsFrom("First.MyClass<Int32>::CallMe", "param", "0"); }