12
12
namespace Serilog . Sinks . MSSqlServer . Tests . Platform
13
13
{
14
14
[ Trait ( TestCategory . TraitName , TestCategory . Unit ) ]
15
- public class SqlInsertBatchWriterTests
15
+ public class SqlInsertStatementWriterTests
16
16
{
17
17
private const string _tableName = "TestTableName" ;
18
18
private const string _schemaName = "TestSchemaName" ;
19
19
private readonly Mock < ISqlConnectionFactory > _sqlConnectionFactoryMock ;
20
20
private readonly Mock < ILogEventDataGenerator > _logEventDataGeneratorMock ;
21
21
private readonly Mock < ISqlConnectionWrapper > _sqlConnectionWrapperMock ;
22
22
private readonly Mock < ISqlCommandWrapper > _sqlCommandWrapperMock ;
23
- private readonly SqlInsertBatchWriter _sut ;
23
+ private readonly SqlInsertStatementWriter _sut ;
24
24
25
- public SqlInsertBatchWriterTests ( )
25
+ public SqlInsertStatementWriterTests ( )
26
26
{
27
27
_sqlConnectionFactoryMock = new Mock < ISqlConnectionFactory > ( ) ;
28
28
_logEventDataGeneratorMock = new Mock < ILogEventDataGenerator > ( ) ;
@@ -32,31 +32,31 @@ public SqlInsertBatchWriterTests()
32
32
_sqlConnectionFactoryMock . Setup ( f => f . Create ( ) ) . Returns ( _sqlConnectionWrapperMock . Object ) ;
33
33
_sqlConnectionWrapperMock . Setup ( c => c . CreateCommand ( ) ) . Returns ( _sqlCommandWrapperMock . Object ) ;
34
34
35
- _sut = new SqlInsertBatchWriter ( _tableName , _schemaName , _sqlConnectionFactoryMock . Object , _logEventDataGeneratorMock . Object ) ;
35
+ _sut = new SqlInsertStatementWriter ( _tableName , _schemaName , _sqlConnectionFactoryMock . Object , _logEventDataGeneratorMock . Object ) ;
36
36
}
37
37
38
38
[ Fact ]
39
39
public void InitializeWithoutTableNameThrows ( )
40
40
{
41
- Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertBatchWriter ( null , _schemaName , _sqlConnectionFactoryMock . Object , _logEventDataGeneratorMock . Object ) ) ;
41
+ Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertStatementWriter ( null , _schemaName , _sqlConnectionFactoryMock . Object , _logEventDataGeneratorMock . Object ) ) ;
42
42
}
43
43
44
44
[ Fact ]
45
45
public void InitializeWithoutSchemaNameThrows ( )
46
46
{
47
- Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertBatchWriter ( _tableName , null , _sqlConnectionFactoryMock . Object , _logEventDataGeneratorMock . Object ) ) ;
47
+ Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertStatementWriter ( _tableName , null , _sqlConnectionFactoryMock . Object , _logEventDataGeneratorMock . Object ) ) ;
48
48
}
49
49
50
50
[ Fact ]
51
51
public void InitializeWithoutSqlConnectionFactoryThrows ( )
52
52
{
53
- Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertBatchWriter ( _tableName , _schemaName , null , _logEventDataGeneratorMock . Object ) ) ;
53
+ Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertStatementWriter ( _tableName , _schemaName , null , _logEventDataGeneratorMock . Object ) ) ;
54
54
}
55
55
56
56
[ Fact ]
57
57
public void InitializeWithoutLogEventDataGeneratorThrows ( )
58
58
{
59
- Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertBatchWriter ( _tableName , _schemaName , _sqlConnectionFactoryMock . Object , null ) ) ;
59
+ Assert . Throws < ArgumentNullException > ( ( ) => new SqlInsertStatementWriter ( _tableName , _schemaName , _sqlConnectionFactoryMock . Object , null ) ) ;
60
60
}
61
61
62
62
[ Fact ]
@@ -66,7 +66,7 @@ public async Task WriteBatchCallsSqlConnectionFactoryCreate()
66
66
var logEvents = CreateLogEvents ( ) ;
67
67
68
68
// Act
69
- await _sut . WriteBatch ( logEvents , null ) ;
69
+ await _sut . WriteBatch ( logEvents ) ;
70
70
71
71
// Assert
72
72
_sqlConnectionFactoryMock . Verify ( f => f . Create ( ) , Times . Once ) ;
@@ -79,7 +79,7 @@ public async Task WriteBatchCallsSqlConnectionWrapperOpenAsync()
79
79
var logEvents = CreateLogEvents ( ) ;
80
80
81
81
// Act
82
- await _sut . WriteBatch ( logEvents , null ) ;
82
+ await _sut . WriteBatch ( logEvents ) ;
83
83
84
84
// Assert
85
85
_sqlConnectionWrapperMock . Verify ( c => c . OpenAsync ( ) , Times . Once ) ;
@@ -92,7 +92,7 @@ public async Task WriteBatchCallsSqlConnectionWrappeCreateCommand()
92
92
var logEvents = CreateLogEvents ( ) ;
93
93
94
94
// Act
95
- await _sut . WriteBatch ( logEvents , null ) ;
95
+ await _sut . WriteBatch ( logEvents ) ;
96
96
97
97
// Assert
98
98
_sqlConnectionWrapperMock . Verify ( c => c . CreateCommand ( ) , Times . Exactly ( logEvents . Count ) ) ;
@@ -105,7 +105,7 @@ public async Task WriteBatchSetsSqlCommandWrapperCommandTypeText()
105
105
var logEvents = CreateLogEvents ( ) ;
106
106
107
107
// Act
108
- await _sut . WriteBatch ( logEvents , null ) ;
108
+ await _sut . WriteBatch ( logEvents ) ;
109
109
110
110
// Assert
111
111
_sqlCommandWrapperMock . VerifySet ( c => c . CommandType = System . Data . CommandType . Text ) ;
@@ -129,7 +129,7 @@ public async Task WriteBatchCallsSqlCommandWrapperAddParameterForEachField()
129
129
. Returns ( fieldsAndValues ) ;
130
130
131
131
// Act
132
- await _sut . WriteBatch ( new [ ] { logEvent } , null ) ;
132
+ await _sut . WriteBatch ( new [ ] { logEvent } ) ;
133
133
134
134
// Assert
135
135
_sqlCommandWrapperMock . Verify ( c => c . AddParameter ( "@P0" , field1Value ) , Times . Once ) ;
@@ -153,7 +153,7 @@ public async Task WriteBatchSetsSqlCommandWrapperCommandTextToSqlInsertWithCorre
153
153
. Returns ( fieldsAndValues ) ;
154
154
155
155
// Act
156
- await _sut . WriteBatch ( new [ ] { logEvent } , null ) ;
156
+ await _sut . WriteBatch ( new [ ] { logEvent } ) ;
157
157
158
158
// Assert
159
159
_sqlCommandWrapperMock . VerifySet ( c => c . CommandText = expectedSqlCommandText ) ;
@@ -166,7 +166,7 @@ public async Task WriteBatchCallsSqlCommandWrapperExecuteNonQueryAsync()
166
166
var logEvents = CreateLogEvents ( ) ;
167
167
168
168
// Act
169
- await _sut . WriteBatch ( logEvents , null ) ;
169
+ await _sut . WriteBatch ( logEvents ) ;
170
170
171
171
// Assert
172
172
_sqlCommandWrapperMock . Verify ( c => c . ExecuteNonQueryAsync ( ) , Times . Exactly ( logEvents . Count ) ) ;
@@ -179,7 +179,7 @@ public async Task WriteBatchCallsSqlCommandWrapperDispose()
179
179
var logEvents = CreateLogEvents ( ) ;
180
180
181
181
// Act
182
- await _sut . WriteBatch ( logEvents , null ) ;
182
+ await _sut . WriteBatch ( logEvents ) ;
183
183
184
184
// Assert
185
185
_sqlCommandWrapperMock . Verify ( c => c . Dispose ( ) , Times . Exactly ( logEvents . Count ) ) ;
@@ -192,7 +192,7 @@ public async Task WriteBatchCallsLogEventDataGeneratorGetColumnsAndValuesForEach
192
192
var logEvents = CreateLogEvents ( ) ;
193
193
194
194
// Act
195
- await _sut . WriteBatch ( logEvents , null ) . ConfigureAwait ( false ) ;
195
+ await _sut . WriteBatch ( logEvents ) . ConfigureAwait ( false ) ;
196
196
197
197
// Assert
198
198
_logEventDataGeneratorMock . Verify ( c => c . GetColumnsAndValues ( logEvents [ 0 ] ) , Times . Once ) ;
@@ -207,7 +207,7 @@ public async Task WriteBatchRethrowsIfSqlConnectionFactoryCreateThrows()
207
207
var logEvents = CreateLogEvents ( ) ;
208
208
209
209
// Act + assert
210
- await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents , null ) ) ;
210
+ await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents ) ) ;
211
211
}
212
212
213
213
[ Fact ]
@@ -218,7 +218,7 @@ public async Task WriteBatchRethrowsIfSqlConnectionCreateCommandThrows()
218
218
var logEvents = CreateLogEvents ( ) ;
219
219
220
220
// Act + assert
221
- await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents , null ) ) ;
221
+ await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents ) ) ;
222
222
}
223
223
224
224
[ Fact ]
@@ -229,7 +229,7 @@ public async Task WriteBatchRethrowsIfLogEventDataGeneratorGetColumnsAndValuesTh
229
229
var logEvents = CreateLogEvents ( ) ;
230
230
231
231
// Act + assert
232
- await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents , null ) ) ;
232
+ await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents ) ) ;
233
233
}
234
234
235
235
[ Fact ]
@@ -243,7 +243,7 @@ public async Task WriteBatchRethrowsIfSqlCommandAddParameterThrows()
243
243
var logEvents = CreateLogEvents ( ) ;
244
244
245
245
// Act + assert
246
- await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents , null ) ) ;
246
+ await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents ) ) ;
247
247
}
248
248
249
249
[ Fact ]
@@ -254,7 +254,7 @@ public async Task WriteBatchRethrowsIfSqlCommandExecuteNonQueryAsyncThrows()
254
254
var logEvents = CreateLogEvents ( ) ;
255
255
256
256
// Act + assert
257
- await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents , null ) ) ;
257
+ await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => _sut . WriteBatch ( logEvents ) ) ;
258
258
}
259
259
260
260
private static List < LogEvent > CreateLogEvents ( )
0 commit comments