11using System ;
2- using jjm . one . Serilog . Extensions . Logging . Helpers . Tests . util ;
2+ using System . Reflection ;
33using Moq ;
44using Serilog . Events ;
55using Serilog ;
66
77namespace jjm . one . Serilog . Extensions . Logging . Helpers . Tests . FunctionLogging ;
88
9+ /// <summary>
10+ /// This class contains the tests for the <see cref="FunctionLogging"/> class.
11+ /// </summary>
912public class FunctionLoggingTests
1013{
1114 #region private members
1215
1316 private readonly Mock < ILogger > _logger ;
14-
15- private readonly DummyClass _sut ;
1617
1718 #endregion
1819
1920 #region ctors
2021
22+ /// <summary>
23+ /// The default constructor of the <see cref="FunctionLoggingTests"/> class.
24+ /// </summary>
2125 public FunctionLoggingTests ( )
2226 {
2327 _logger = new Mock < ILogger > ( ) ;
24-
25- _sut = new DummyClass ( _logger . Object ) ;
2628 }
2729
2830 #endregion
2931
3032 #region tests
3133
34+ /// <summary>
35+ /// 1. test of the LogFctCall function.
36+ /// </summary>
3237 [ Fact ]
3338 public void LogFctCallTest1 ( )
3439 {
@@ -37,15 +42,18 @@ public void LogFctCallTest1()
3742 It . IsAny < string > ( ) , It . IsAny < object ? [ ] ? > ( ) ) ) . Verifiable ( ) ;
3843
3944 // act
40- _sut . Test1 ( ) ;
41-
45+ _logger . Object . LogFctCall ( ) ;
46+
4247 // assert
43- _logger . Verify ( logger => logger . Write ( LogEventLevel . Debug ,
48+ _logger . Verify ( x => x . Write ( LogEventLevel . Debug ,
4449 "Function called: {ClassName} -> {FctName}" ,
45- nameof ( DummyClass ) , nameof ( DummyClass . Test1 ) ) ,
50+ nameof ( FunctionLoggingTests ) , nameof ( LogFctCallTest1 ) ) ,
4651 Times . Once ) ;
4752 }
4853
54+ /// <summary>
55+ /// 2. test of the LogFctCall function.
56+ /// </summary>
4957 [ Fact ]
5058 public void LogFctCallTest2 ( )
5159 {
@@ -54,84 +62,106 @@ public void LogFctCallTest2()
5462 It . IsAny < string > ( ) , It . IsAny < object ? [ ] ? > ( ) ) ) . Verifiable ( ) ;
5563
5664 // act
57- _sut . Test2 ( ) ;
65+ _logger . Object . LogFctCall ( GetType ( ) , MethodBase . GetCurrentMethod ( ) ) ;
5866
5967 // assert
60- _logger . Verify ( logger => logger . Write ( LogEventLevel . Debug ,
68+ _logger . Verify ( x => x . Write ( LogEventLevel . Debug ,
6169 "Function called: {ClassName} -> {FctName}" ,
62- nameof ( DummyClass ) , nameof ( DummyClass . Test2 ) ) ,
70+ nameof ( FunctionLoggingTests ) , nameof ( LogFctCallTest2 ) ) ,
6371 Times . Once ) ;
6472 }
6573
74+ /// <summary>
75+ /// 1. test of the LogExcInFctCall function.
76+ /// </summary>
6677 [ Fact ]
67- public void LogFctCallTest3 ( )
78+ public void LogExcInFctCallTest1 ( )
6879 {
6980 // arrange
81+ var exc = new Exception ( "Test" ) ;
7082 _logger . Setup ( x => x . Write ( LogEventLevel . Debug , It . IsAny < Exception > ( ) ,
7183 It . IsAny < string > ( ) , It . IsAny < object ? [ ] ? > ( ) ) ) . Verifiable ( ) ;
7284
7385 // act
74- _sut . Test3 ( ) ;
86+ _logger . Object . LogExcInFctCall ( exc ) ;
7587
7688 // assert
77- _logger . Verify ( logger => logger . Write ( LogEventLevel . Error ,
78- It . IsAny < Exception > ( ) ,
79- "Exception thrown in: {ClassName} -> {FctName}" ,
80- nameof ( DummyClass ) , nameof ( DummyClass . Test3 ) ) ,
89+ _logger . Verify ( x => x . Write ( LogEventLevel . Error ,
90+ It . Is < Exception > ( e => e == exc ) ,
91+ "Exception thrown in: {ClassName} -> {FctName}{CustomMsg}" ,
92+ nameof ( FunctionLoggingTests ) , nameof ( LogExcInFctCallTest1 ) ,
93+ string . Empty ) ,
8194 Times . Once ) ;
8295 }
8396
97+ /// <summary>
98+ /// 2. test of the LogExcInFctCall function.
99+ /// </summary>
84100 [ Fact ]
85- public void LogFctCallTest4 ( )
101+ public void LogExcInFctCallTest2 ( )
86102 {
87103 // arrange
104+ var exc = new Exception ( "Test" ) ;
88105 _logger . Setup ( x => x . Write ( LogEventLevel . Debug , It . IsAny < Exception > ( ) ,
89106 It . IsAny < string > ( ) , It . IsAny < object ? [ ] ? > ( ) ) ) . Verifiable ( ) ;
90107
91108 // act
92- _sut . Test4 ( ) ;
109+ _logger . Object . LogExcInFctCall ( exc , "TestMSG" ) ;
93110
94111 // assert
95- _logger . Verify ( logger => logger . Write ( LogEventLevel . Error ,
96- It . IsAny < Exception > ( ) ,
97- "Exception thrown in: {ClassName} -> {FctName}\n TestMSG" ,
98- nameof ( DummyClass ) , nameof ( DummyClass . Test4 ) ) ,
112+ _logger . Verify ( x => x . Write ( LogEventLevel . Error ,
113+ It . Is < Exception > ( e => e == exc ) ,
114+ "Exception thrown in: {ClassName} -> {FctName}{CustomMsg}" ,
115+ nameof ( FunctionLoggingTests ) , nameof ( LogExcInFctCallTest2 ) ,
116+ "\n TestMSG" ) ,
99117 Times . Once ) ;
100118 }
101119
120+ /// <summary>
121+ /// 3. test of the LogExcInFctCall function.
122+ /// </summary>
102123 [ Fact ]
103- public void LogFctCallTest5 ( )
124+ public void LogExcInFctCallTest3 ( )
104125 {
105126 // arrange
127+ var exc = new Exception ( "Test" ) ;
106128 _logger . Setup ( x => x . Write ( LogEventLevel . Debug , It . IsAny < Exception > ( ) ,
107129 It . IsAny < string > ( ) , It . IsAny < object ? [ ] ? > ( ) ) ) . Verifiable ( ) ;
108130
109131 // act
110- _sut . Test5 ( ) ;
132+ _logger . Object . LogExcInFctCall ( exc , GetType ( ) ,
133+ MethodBase . GetCurrentMethod ( ) ) ;
111134
112135 // assert
113- _logger . Verify ( logger => logger . Write ( LogEventLevel . Error ,
114- It . IsAny < Exception > ( ) ,
115- "Exception thrown in: {ClassName} -> {FctName}" ,
116- nameof ( DummyClass ) , nameof ( DummyClass . Test5 ) ) ,
136+ _logger . Verify ( x => x . Write ( LogEventLevel . Error ,
137+ It . Is < Exception > ( e => e == exc ) ,
138+ "Exception thrown in: {ClassName} -> {FctName}{CustomMsg}" ,
139+ nameof ( FunctionLoggingTests ) , nameof ( LogExcInFctCallTest3 ) ,
140+ string . Empty ) ,
117141 Times . Once ) ;
118142 }
119143
144+ /// <summary>
145+ /// 4. test of the LogExcInFctCall function.
146+ /// </summary>
120147 [ Fact ]
121- public void LogFctCallTest6 ( )
148+ public void LogExcInFctCallTest4 ( )
122149 {
123150 // arrange
151+ var exc = new Exception ( "Test" ) ;
124152 _logger . Setup ( x => x . Write ( LogEventLevel . Debug , It . IsAny < Exception > ( ) ,
125153 It . IsAny < string > ( ) , It . IsAny < object ? [ ] ? > ( ) ) ) . Verifiable ( ) ;
126154
127155 // act
128- _sut . Test6 ( ) ;
156+ _logger . Object . LogExcInFctCall ( exc , GetType ( ) ,
157+ MethodBase . GetCurrentMethod ( ) , "TestMSG" ) ;
129158
130159 // assert
131- _logger . Verify ( logger => logger . Write ( LogEventLevel . Error ,
132- It . IsAny < Exception > ( ) ,
133- "Exception thrown in: {ClassName} -> {FctName}\n TestMSG" ,
134- nameof ( DummyClass ) , nameof ( DummyClass . Test6 ) ) ,
160+ _logger . Verify ( x => x . Write ( LogEventLevel . Error ,
161+ It . Is < Exception > ( e => e == exc ) ,
162+ "Exception thrown in: {ClassName} -> {FctName}{CustomMsg}" ,
163+ nameof ( FunctionLoggingTests ) , nameof ( LogExcInFctCallTest4 ) ,
164+ "\n TestMSG" ) ,
135165 Times . Once ) ;
136166 }
137167
0 commit comments