File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed
test/Serilog.Sinks.MSSqlServer.Tests Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,18 @@ if ($SkipTests -eq $false) {
54
54
55
55
echo " build: Testing project in $test "
56
56
57
- & dotnet test - c Release
57
+ & dotnet test - c Release -- filter " Category!=Isolated"
58
+ if ($LASTEXITCODE -ne 0 ) { exit 3 }
59
+
60
+ Pop-Location
61
+ }
62
+
63
+ foreach ($test in ls test/* .Tests) {
64
+ Push-Location $test
65
+
66
+ echo " build: Running isolated tests in $test "
67
+
68
+ & dotnet test - c Release -- filter " Category=Isolated"
58
69
if ($LASTEXITCODE -ne 0 ) { exit 3 }
59
70
60
71
Pop-Location
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ public static class TestCategory
5
5
public const string TraitName = "Category" ;
6
6
7
7
public const string Integration = nameof ( Integration ) ;
8
+ public const string Isolated = nameof ( Isolated ) ;
8
9
public const string Unit = nameof ( Unit ) ;
9
10
}
10
11
}
Original file line number Diff line number Diff line change
1
+ using System . Transactions ;
2
+ using FluentAssertions ;
3
+ using Serilog . Sinks . MSSqlServer . Tests . TestUtils ;
4
+ using Xunit ;
5
+ using Xunit . Abstractions ;
6
+
7
+ namespace Serilog . Sinks . MSSqlServer . Tests
8
+ {
9
+ [ Trait ( TestCategory . TraitName , TestCategory . Isolated ) ]
10
+ public class TransactionTests : DatabaseTestsBase
11
+ {
12
+ public TransactionTests ( ITestOutputHelper output ) : base ( output )
13
+ {
14
+ }
15
+
16
+ [ Fact ]
17
+ public void LogsAreNotAffectedByTransactionsByDefault ( )
18
+ {
19
+ // Arrange
20
+ Log . Logger = new LoggerConfiguration ( )
21
+ . WriteTo . MSSqlServer
22
+ (
23
+ connectionString : DatabaseFixture . LogEventsConnectionString ,
24
+ new MSSqlServerSinkOptions
25
+ {
26
+ TableName = DatabaseFixture . LogTableName ,
27
+ AutoCreateSqlTable = true
28
+ }
29
+ )
30
+ . CreateLogger ( ) ;
31
+
32
+ using ( var scope = new TransactionScope ( TransactionScopeAsyncFlowOption . Enabled ) )
33
+ {
34
+ // Act
35
+ Log . Logger . Information ( "Logging message" ) ;
36
+
37
+ // Flush message so it is written on foreground thread instead of timer
38
+ // So we can test if it is affected by transaction
39
+ Log . CloseAndFlush ( ) ;
40
+ }
41
+
42
+ // Assert after rollback, the message should still be persisted
43
+ VerifyCustomQuery < LogEventColumn > ( $ "SELECT Id from { DatabaseFixture . LogTableName } ",
44
+ e => e . Should ( ) . HaveCount ( 1 ) ) ;
45
+ }
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments