Skip to content

Commit

Permalink
Added tests for disposing in sink classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ckadluba committed Dec 5, 2024
1 parent a5d5e86 commit 2db0fa1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data;
using Moq;
using Serilog.Events;
using Serilog.Parsing;
Expand Down Expand Up @@ -157,6 +156,16 @@ public void EmitCallsSqlLogEventWriter()
_sqlLogEventWriter.Verify(w => w.WriteEvent(logEvent), Times.Once);
}

[Fact]
public void OnDisposeDisposesSqlLogEventWriterDependency()
{
// Arrange + act
using (new MSSqlServerAuditSink(_sinkOptions, _columnOptions, _sinkDependencies)) { }

// Assert
_sqlLogEventWriter.Verify(w => w.Dispose(), Times.Once);
}

private void SetupSut(bool autoCreateSqlDatabase = false, bool autoCreateSqlTable = false)
{
_sinkOptions.AutoCreateSqlDatabase = autoCreateSqlDatabase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Moq;
using Serilog.Events;
Expand Down Expand Up @@ -185,6 +184,26 @@ public void OnEmptyBatchAsyncReturnsCompletedTask()
Assert.True(task.IsCompleted);
}

[Fact]
public void OnDisposeDisposesSqlBulkBatchWriterDependency()
{
// Arrange + act
using (new MSSqlServerSink(_sinkOptions, _sinkDependencies)) { }

// Assert
_sqlBulkBatchWriter.Verify(w => w.Dispose(), Times.Once);
}

[Fact]
public void OnDisposeDisposesSqlLogEventWriterDependency()
{
// Arrange + act
using (new MSSqlServerSink(_sinkOptions, _sinkDependencies)) { }

// Assert
_sqlLogEventWriter.Verify(w => w.Dispose(), Times.Once);
}

private void SetupSut(
bool autoCreateSqlDatabase = false,
bool autoCreateSqlTable = false,
Expand Down

0 comments on commit 2db0fa1

Please sign in to comment.