1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Data . SqlClient ;
3
- using System . Diagnostics ;
4
4
using System . Linq ;
5
5
using Dapper ;
6
6
using Xunit ;
@@ -10,16 +10,12 @@ namespace Serilog.Sinks.MSSqlServer.Tests
10
10
{
11
11
public class CustomStandardColumnNames : IClassFixture < DatabaseFixture >
12
12
{
13
- public class InfoSchema
14
- {
15
- public string ColumnName { get ; set ; }
16
- }
17
-
18
13
[ Fact ]
19
14
public void TableCreatedWithCustomNames ( )
20
15
{
21
16
// arrange
22
17
var options = new ColumnOptions ( ) ;
18
+ var standardNames = new List < string > { "CustomMessage" , "CustomMessageTemplate" , "CustomLevel" , "CustomTimeStamp" , "CustomException" , "CustomProperties" } ;
23
19
24
20
options . Store . ToList ( ) . ForEach ( c =>
25
21
{
@@ -28,26 +24,47 @@ public void TableCreatedWithCustomNames()
28
24
} ) ;
29
25
30
26
// act
31
- var sink = new MSSqlServerSink ( DatabaseFixture . LogEventsConnectionString , DatabaseFixture . LogTableName , 1 , TimeSpan . FromSeconds ( 1 ) , null , true , options ) ;
27
+ var logTableName = $ "{ DatabaseFixture . LogTableName } Custom";
28
+ var sink = new MSSqlServerSink ( DatabaseFixture . LogEventsConnectionString , logTableName , 1 , TimeSpan . FromSeconds ( 1 ) , null , true , options ) ;
32
29
33
30
// assert
34
31
using ( var conn = new SqlConnection ( DatabaseFixture . MasterConnectionString ) )
35
32
{
36
33
conn . Execute ( $ "use { DatabaseFixture . Database } ") ;
37
- var logEvents = conn . Query < InfoSchema > ( $@ "SELECT COLUMN_NAME AS ColumnName FROM { DatabaseFixture . Database } .INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{ DatabaseFixture . LogTableName } '") ;
38
- var infoSchemata = logEvents as InfoSchema [ ] ?? logEvents . ToArray ( ) ;
34
+ var logEvents = conn . Query < InfoSchema > ( $@ "SELECT COLUMN_NAME AS ColumnName FROM { DatabaseFixture . Database } .INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{ logTableName } '") ;
35
+ var infoSchema = logEvents as InfoSchema [ ] ?? logEvents . ToArray ( ) ;
39
36
40
- foreach ( var column in options . Store . Values )
37
+ foreach ( var column in standardNames )
41
38
{
42
- infoSchemata . Should ( ) . Contain ( columns => columns . ColumnName == column ) ;
39
+ infoSchema . Should ( ) . Contain ( columns => columns . ColumnName == column ) ;
43
40
}
44
41
}
45
42
}
46
43
47
44
[ Fact ]
48
45
public void TableCreatedWithDefaultNames ( )
49
46
{
50
-
47
+ // arrange
48
+ var options = new ColumnOptions ( ) ;
49
+ var standardNames = new List < string > { "Message" , "MessageTemplate" , "Level" , "TimeStamp" , "Exception" , "Properties" } ;
50
+
51
+ // act
52
+ var logTableName = $ "{ DatabaseFixture . LogTableName } Standard";
53
+ System . Diagnostics . Debugger . Launch ( ) ;
54
+ var sink = new MSSqlServerSink ( DatabaseFixture . LogEventsConnectionString , logTableName , 1 , TimeSpan . FromSeconds ( 1 ) , null , true , options ) ;
55
+
56
+ // assert
57
+ using ( var conn = new SqlConnection ( DatabaseFixture . MasterConnectionString ) )
58
+ {
59
+ conn . Execute ( $ "use { DatabaseFixture . Database } ") ;
60
+ var logEvents = conn . Query < InfoSchema > ( $@ "SELECT COLUMN_NAME AS ColumnName FROM { DatabaseFixture . Database } .INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{ logTableName } '") ;
61
+ var infoSchema = logEvents as InfoSchema [ ] ?? logEvents . ToArray ( ) ;
62
+
63
+ foreach ( var column in standardNames )
64
+ {
65
+ infoSchema . Should ( ) . Contain ( columns => columns . ColumnName == column ) ;
66
+ }
67
+ }
51
68
}
52
69
}
53
70
}
0 commit comments