@@ -60,16 +60,128 @@ public void InitializeWithoutLogEventDataGeneratorThrows()
60
60
public void WriteEventCallsSqlConnectionFactoryCreate ( )
61
61
{
62
62
// Arrange
63
- var logEvent = new LogEvent (
64
- new DateTimeOffset ( 2020 , 1 , 1 , 0 , 0 , 0 , 0 , TimeSpan . Zero ) ,
65
- LogEventLevel . Debug , null , new MessageTemplate ( new List < MessageTemplateToken > ( ) ) ,
66
- new List < LogEventProperty > ( ) ) ;
63
+ var logEvent = CreateLogEvent ( ) ;
67
64
68
65
// Act
69
66
_sut . WriteEvent ( logEvent ) ;
70
67
71
68
// Assert
72
69
_sqlConnectionFactoryMock . Verify ( f => f . Create ( ) , Times . Once ) ;
73
70
}
71
+
72
+ [ Fact ]
73
+ public void WriteEventCallsSqlConnectionWrapperOpen ( )
74
+ {
75
+ // Arrange
76
+ var logEvent = CreateLogEvent ( ) ;
77
+
78
+ // Act
79
+ _sut . WriteEvent ( logEvent ) ;
80
+
81
+ // Assert
82
+ _sqlConnectionWrapperMock . Verify ( c => c . Open ( ) , Times . Once ) ;
83
+ }
84
+
85
+ [ Fact ]
86
+ public void WriteEventCallsSqlConnectionWrappeCreateCommand ( )
87
+ {
88
+ // Arrange
89
+ var logEvent = CreateLogEvent ( ) ;
90
+
91
+ // Act
92
+ _sut . WriteEvent ( logEvent ) ;
93
+
94
+ // Assert
95
+ _sqlConnectionWrapperMock . Verify ( c => c . CreateCommand ( ) , Times . Once ) ;
96
+ }
97
+
98
+ [ Fact ]
99
+ public void WriteEventCallsSqlConnectionWrapperDispose ( )
100
+ {
101
+ // Arrange
102
+ var logEvent = CreateLogEvent ( ) ;
103
+
104
+ // Act
105
+ _sut . WriteEvent ( logEvent ) ;
106
+
107
+ // Assert
108
+ _sqlConnectionWrapperMock . Verify ( c => c . Dispose ( ) , Times . Once ) ;
109
+ }
110
+
111
+ [ Fact ]
112
+ public void WriteEventSetsSqlCommandWrapperCommandTypeText ( )
113
+ {
114
+ // Arrange
115
+ var logEvent = CreateLogEvent ( ) ;
116
+
117
+ // Act
118
+ _sut . WriteEvent ( logEvent ) ;
119
+
120
+ // Assert
121
+ _sqlCommandWrapperMock . VerifySet ( c => c . CommandType = System . Data . CommandType . Text ) ;
122
+ }
123
+
124
+ [ Fact ]
125
+ public void WriteEventSetsSqlCommandWrapperCommandTextToSqlInsertWithFields ( )
126
+ {
127
+ // TODO finish test
128
+
129
+ // Arrange
130
+ var logEvent = CreateLogEvent ( ) ;
131
+ //_logEventDataGeneratorMock.Setup(...)
132
+
133
+ // Act
134
+ _sut . WriteEvent ( logEvent ) ;
135
+
136
+ // Assert
137
+ //_sqlCommandWrapperMock.VerifySet(c => c.CommandText = expectedCommandText);
138
+ }
139
+
140
+ [ Fact ]
141
+ public void WriteEventCallsSqlCommandWrapperExecuteNonQuery ( )
142
+ {
143
+ // Arrange
144
+ var logEvent = CreateLogEvent ( ) ;
145
+
146
+ // Act
147
+ _sut . WriteEvent ( logEvent ) ;
148
+
149
+ // Assert
150
+ _sqlCommandWrapperMock . Verify ( c => c . ExecuteNonQuery ( ) , Times . Once ) ;
151
+ }
152
+
153
+ [ Fact ]
154
+ public void WriteEventCallsSqlCommandWrapperDispose ( )
155
+ {
156
+ // Arrange
157
+ var logEvent = CreateLogEvent ( ) ;
158
+
159
+ // Act
160
+ _sut . WriteEvent ( logEvent ) ;
161
+
162
+ // Assert
163
+ _sqlCommandWrapperMock . Verify ( c => c . Dispose ( ) , Times . Once ) ;
164
+ }
165
+
166
+ [ Fact ]
167
+ public void WriteEventCallsLogEventDataGeneratorGetColumnsAndValuesWithLogEvent ( )
168
+ {
169
+ // Arrange
170
+ var logEvent = CreateLogEvent ( ) ;
171
+
172
+ // Act
173
+ _sut . WriteEvent ( logEvent ) ;
174
+
175
+ // Assert
176
+ _logEventDataGeneratorMock . Verify ( d => d . GetColumnsAndValues ( logEvent ) , Times . Once ) ;
177
+ }
178
+
179
+ private static LogEvent CreateLogEvent ( )
180
+ {
181
+ return new LogEvent (
182
+ new DateTimeOffset ( 2020 , 1 , 1 , 0 , 0 , 0 , 0 , TimeSpan . Zero ) ,
183
+ LogEventLevel . Debug , null , new MessageTemplate ( new List < MessageTemplateToken > ( ) ) ,
184
+ new List < LogEventProperty > ( ) ) ;
185
+ }
74
186
}
75
187
}
0 commit comments