Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec3422e

Browse files
committed
Readme and some basic tests
1 parent b1b22c4 commit ec3422e

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

‎README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ Basic settings of the sink are configured using the properties in a `MSSqlServer
249249
* `EagerlyEmitFirstEvent`
250250
* `LevelSwitch`
251251
* `UseSqlBulkCopy`
252+
* `ConnectionConfiguration`
252253

253254
### TableName
254255

@@ -299,6 +300,10 @@ A switch allowing the pass-through minimum level to be changed at runtime. If th
299300
A flag to use `SqlBulkCopy` instead of individual INSERT statements when writing log events. The default is `true`.
300301
This setting is not used by the audit sink as it always uses INSERT statements to write events.
301302

303+
### ConnectionConfiguration
304+
305+
An optional action to customize the underlying SqlConnection object. Can be used to set properties such as `AccessTokenCallback`.
306+
302307
## ColumnOptions Object
303308

304309
Features of the log table are defined by changing properties on a `ColumnOptions` object:

‎test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/Dependencies/SinkDependenciesFactoryTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using Serilog.Sinks.MSSqlServer.Dependencies;
1+
using Moq;
2+
using System;
3+
using Serilog.Sinks.MSSqlServer.Dependencies;
24
using Serilog.Sinks.MSSqlServer.Platform;
35
using Serilog.Sinks.MSSqlServer.Tests.TestUtils;
46
using Xunit;
7+
using Microsoft.Data.SqlClient;
58

69
namespace Serilog.Sinks.MSSqlServer.Tests.Dependencies
710
{
@@ -68,5 +71,19 @@ public void DefaultsColumnOptionsIfNull()
6871
// Act (should not throw)
6972
SinkDependenciesFactory.Create(_connectionString, _sinkOptions, null, null, null);
7073
}
74+
75+
[Fact]
76+
public void CreatesSinkDependenciesWithSqlConnectionConfiguration()
77+
{
78+
// Arrange
79+
var mockConfigurationAction = new Mock<Action<SqlConnection>>();
80+
var sinkOptions = new MSSqlServerSinkOptions { TableName = "LogEvents", ConnectionConfiguration = mockConfigurationAction.Object };
81+
82+
// Act
83+
var result = SinkDependenciesFactory.Create(_connectionString, sinkOptions, null, _columnOptions, null);
84+
85+
// Assert
86+
Assert.NotNull(result.SqlDatabaseCreator);
87+
}
7188
}
7289
}

‎test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/Platform/SqlConnectionFactoryTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Microsoft.Data.SqlClient;
23
using Moq;
34
using Serilog.Sinks.MSSqlServer.Platform;
45
using Serilog.Sinks.MSSqlServer.Platform.SqlClient;
@@ -38,5 +39,23 @@ public void CreateConnectionReturnsConnectionWrapper()
3839
Assert.IsAssignableFrom<ISqlConnectionWrapper>(connection);
3940
}
4041
}
42+
43+
44+
[Fact]
45+
public void CreateConnectionCallsCustomConfigurationAction()
46+
{
47+
// Arrange
48+
var mockAction = new Mock<Action<SqlConnection>>();
49+
var sut = new SqlConnectionFactory(_sqlConnectionStringBuilderWrapperMock.Object, mockAction.Object);
50+
51+
// Act
52+
using (var connection = sut.Create())
53+
{
54+
// Assert
55+
Assert.NotNull(connection);
56+
Assert.IsAssignableFrom<ISqlConnectionWrapper>(connection);
57+
mockAction.Verify(m => m.Invoke(connection.SqlConnection), Times.Once);
58+
}
59+
}
4160
}
4261
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /