Skip to content

Commit

Permalink
Add some variance into tests to validate custom logging scope key
Browse files Browse the repository at this point in the history
  • Loading branch information
laurynasr committed Sep 27, 2023
1 parent 09a85d4 commit 6cb2651
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/Correlate.Core.Tests/CorrelationManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using System.Diagnostics;
using Correlate.Testing;
using Correlate.Testing.TestCases;
using Microsoft.Extensions.Logging;
Expand All @@ -21,7 +20,7 @@ public class CorrelationManagerTests : IDisposable
private readonly SerilogLoggerProvider _logProvider;
private readonly CorrelationManager _sut;

protected CorrelationManagerTests()
protected CorrelationManagerTests(CorrelationManagerOptions options)
{
_correlationContextAccessor = new CorrelationContextAccessor();

Expand All @@ -36,7 +35,7 @@ protected CorrelationManagerTests()

_logProvider = new SerilogLoggerProvider(serilogLogger);
_logger = new TestLogger<CorrelationManager>(_logProvider.CreateLogger(nameof(CorrelationManager)));
_options = Options.Create(new CorrelationManagerOptions());
_options = Options.Create(options);

_sut = new CorrelationManager(
new CorrelationContextFactory(_correlationContextAccessor),
Expand All @@ -55,6 +54,13 @@ public void Dispose()

public class Async : CorrelationManagerTests
{
public Async() : base(new()
{
LoggingScopeKey = "ActivityId"
})
{
}

[Fact]
public async Task Given_a_task_should_run_task_inside_correlated_context()
{
Expand Down Expand Up @@ -148,7 +154,7 @@ await _sut.CorrelateAsync(() =>
var logEvents = TestCorrelator.GetLogEventsFromCurrentContext().ToList();
logEvents.Should()
.HaveCount(3)
.And.ContainSingle(ev => ev.MessageTemplate.Text == "Message with correlation id." && ev.Properties.ContainsKey("CorrelationId"));
.And.ContainSingle(ev => ev.MessageTemplate.Text == "Message with correlation id." && ev.Properties.ContainsKey("ActivityId"));
}
}

Expand Down Expand Up @@ -236,7 +242,7 @@ Task ThrowingTask()
.Cast<DictionaryEntry>()
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
.Should()
.ContainKey(CorrelateConstants.CorrelationIdKey)
.ContainKey("ActivityId")
.WhoseValue.Should()
.Be(GeneratedCorrelationId);
}
Expand Down Expand Up @@ -366,6 +372,10 @@ await _sut.CorrelateAsync(innerContextId,

public class Sync : CorrelationManagerTests
{
public Sync() : base(new())
{
}

[Fact]
public void Given_a_action_should_run_action_inside_correlated_context()
{
Expand Down

0 comments on commit 6cb2651

Please sign in to comment.