Skip to content

Commit e51b296

Browse files
committed
Test for properties column filtering
1 parent 4aed3fb commit e51b296

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed
Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,51 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
using Dapper;
2+
using FluentAssertions;
3+
using System.Data.SqlClient;
4+
using Xunit;
45

56
namespace Serilog.Sinks.MSSqlServer.Tests
67
{
7-
class TestPropertiesColumnFiltering
8+
[Collection("LogTest")]
9+
public class TestPropertiesColumnFiltering
810
{
11+
internal class PropertiesColumns
12+
{
13+
public string Properties { get; set; }
14+
}
15+
16+
[Fact]
17+
public void FilteredProperties()
18+
{
19+
// arrange
20+
var columnOptions = new ColumnOptions();
21+
columnOptions.Properties.PropertiesFilter = (propName) => propName == "A";
22+
23+
Log.Logger = new LoggerConfiguration()
24+
.WriteTo.MSSqlServer
25+
(
26+
connectionString: DatabaseFixture.LogEventsConnectionString,
27+
tableName: DatabaseFixture.LogTableName,
28+
columnOptions: columnOptions,
29+
autoCreateSqlTable: true
30+
)
31+
.CreateLogger();
32+
33+
// act
34+
Log.Logger
35+
.ForContext("A", "AValue")
36+
.ForContext("B", "BValue")
37+
.Information("Logging message");
38+
39+
Log.CloseAndFlush();
40+
41+
// assert
42+
using (var conn = new SqlConnection(DatabaseFixture.LogEventsConnectionString))
43+
{
44+
var logEvents = conn.Query<PropertiesColumns>($"SELECT Properties from {DatabaseFixture.LogTableName}");
45+
46+
logEvents.Should().Contain(e => e.Properties.Contains("AValue"));
47+
logEvents.Should().NotContain(e => e.Properties.Contains("BValue"));
48+
}
49+
}
950
}
1051
}

0 commit comments

Comments
 (0)