Skip to content

Commit bea1891

Browse files
committed
Added an integration test.
1 parent aa2c116 commit bea1891

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

test/Serilog.Sinks.MSSqlServer.Tests/Misc/AdditionalPropertiesTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,69 @@ public void WritesLogEventWithCustomNamedProperties()
123123
VerifyStringColumnWritten(additionalColumn1Name, property1Value);
124124
VerifyIntegerColumnWritten(additionalColumn2Name, property2Value);
125125
}
126+
127+
[Fact]
128+
public void WritesLogEventWithColumnsFromHierarchicalNamedProperties()
129+
{
130+
// Arrange
131+
const string additionalColumn1Name = "AdditionalColumn1";
132+
const string additionalProperty1Name = "AdditionalProperty1.SubProperty1";
133+
const string additionalColumn2Name = "AdditionalColumn2";
134+
const string additionalProperty2Name = "AdditionalProperty2.SubProperty2.SubSubProperty1";
135+
var columnOptions = new MSSqlServer.ColumnOptions
136+
{
137+
AdditionalColumns = new List<SqlColumn>
138+
{
139+
new SqlColumn
140+
{
141+
ColumnName = additionalColumn1Name,
142+
PropertyName = additionalProperty1Name,
143+
DataType = SqlDbType.NVarChar,
144+
AllowNull = true,
145+
DataLength = 100
146+
},
147+
new SqlColumn
148+
{
149+
ColumnName = additionalColumn2Name,
150+
PropertyName = additionalProperty2Name,
151+
DataType = SqlDbType.Int,
152+
AllowNull = true
153+
}
154+
}
155+
};
156+
var property1Value = "PropertyValue1";
157+
var property2Value = 2;
158+
159+
// Act
160+
Log.Logger = new LoggerConfiguration()
161+
.WriteTo.MSSqlServer(
162+
DatabaseFixture.LogEventsConnectionString,
163+
sinkOptions: new MSSqlServerSinkOptions
164+
{
165+
TableName = DatabaseFixture.LogTableName,
166+
AutoCreateSqlTable = true
167+
},
168+
columnOptions: columnOptions,
169+
formatProvider: CultureInfo.InvariantCulture)
170+
.CreateLogger();
171+
Log.Information("Hello {@AdditionalProperty1} from thread {@AdditionalProperty2}",
172+
new StructuredType
173+
{
174+
SubProperty1 = property1Value
175+
},
176+
new StructuredType
177+
{
178+
SubProperty2 = new StructuredSubType
179+
{
180+
SubSubProperty1 = property2Value
181+
}
182+
});
183+
Log.CloseAndFlush();
184+
185+
// Assert
186+
VerifyDatabaseColumnsWereCreated(columnOptions.AdditionalColumns);
187+
VerifyStringColumnWritten(additionalColumn1Name, property1Value);
188+
VerifyIntegerColumnWritten(additionalColumn2Name, property2Value);
189+
}
126190
}
127191
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Serilog.Sinks.MSSqlServer.Tests.Misc
2+
{
3+
internal class StructuredSubType
4+
{
5+
public int SubSubProperty1 { get; set; }
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Serilog.Sinks.MSSqlServer.Tests.Misc
2+
{
3+
internal class StructuredType
4+
{
5+
public string SubProperty1 { get; set; }
6+
public StructuredSubType SubProperty2 { get; set; }
7+
}
8+
}

0 commit comments

Comments
 (0)