Skip to content

Commit 0f6c3bd

Browse files
(#16) Test warning log is correct
1 parent b8250aa commit 0f6c3bd

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

src/Stravaig.Configuration.SqlServer.Tests/SqlServerConfigurationSourceExtensionTests.cs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Microsoft.Extensions.Logging;
23
using Microsoft.Extensions.Logging.Abstractions;
34
using NUnit.Framework;
45
using Shouldly;
@@ -39,15 +40,44 @@ public void CreateLoggerIndicatesHowTheProviderIsSetup()
3940

4041
var logs = captureLogger.GetLogs();
4142
logs.RenderLogs(Formatter.SimpleBySequence, Sink.Console);
42-
43-
logs[1].OriginalMessage.ShouldBe("SQL Server Configuration Provider will retrieve from [{serverName}].[{databaseName}].[{schemaName}].[{tableName}] {frequency}. Will wait {connectionTimeout} seconds to connect, and {commandTimeout} seconds to retrieve data.");
44-
logs[1].PropertyDictionary["serverName"].ShouldBe("localhost");
45-
logs[1].PropertyDictionary["databaseName"].ShouldBe("testing");
46-
logs[1].PropertyDictionary["schemaName"].ShouldBe("Stravaig");
47-
logs[1].PropertyDictionary["tableName"].ShouldBe("AppConfiguration");
48-
logs[1].PropertyDictionary["frequency"].ShouldBe("every 120 seconds");
49-
logs[1].PropertyDictionary["connectionTimeout"].ShouldBe(5);
50-
logs[1].PropertyDictionary["commandTimeout"].ShouldBe(10);
43+
44+
var descriptionLog = logs[1];
45+
descriptionLog.OriginalMessage.ShouldBe("SQL Server Configuration Provider will retrieve from [{serverName}].[{databaseName}].[{schemaName}].[{tableName}] {frequency}. Will wait {connectionTimeout} seconds to connect, and {commandTimeout} seconds to retrieve data.");
46+
descriptionLog.PropertyDictionary["serverName"].ShouldBe("localhost");
47+
descriptionLog.PropertyDictionary["databaseName"].ShouldBe("testing");
48+
descriptionLog.PropertyDictionary["schemaName"].ShouldBe("Stravaig");
49+
descriptionLog.PropertyDictionary["tableName"].ShouldBe("AppConfiguration");
50+
descriptionLog.PropertyDictionary["frequency"].ShouldBe("every 120 seconds");
51+
descriptionLog.PropertyDictionary["connectionTimeout"].ShouldBe(5);
52+
descriptionLog.PropertyDictionary["commandTimeout"].ShouldBe(10);
5153
}
54+
55+
[Test]
56+
public void CreateLoggerWarnsOfInterleavePossibility()
57+
{
58+
var source = new SqlServerConfigurationSource(DummyConnectionString, expectLogger: true, refreshInterval: TimeSpan.FromSeconds(12), commandTimeout: TimeSpan.FromSeconds(30));
59+
var replayLogger = (ReplayLogger<SqlServerConfigurationProvider>)source.CreateLogger();
60+
var captureLogger = new TestCaptureLogger<SqlServerConfigurationProvider>();
61+
replayLogger.Replay(captureLogger);
62+
63+
var logs = captureLogger.GetLogs();
64+
logs.RenderLogs(Formatter.SimpleBySequence, Sink.Console);
65+
66+
var descriptionLog = logs[1];
67+
descriptionLog.OriginalMessage.ShouldBe("SQL Server Configuration Provider will retrieve from [{serverName}].[{databaseName}].[{schemaName}].[{tableName}] {frequency}. Will wait {connectionTimeout} seconds to connect, and {commandTimeout} seconds to retrieve data.");
68+
descriptionLog.PropertyDictionary["serverName"].ShouldBe("localhost");
69+
descriptionLog.PropertyDictionary["databaseName"].ShouldBe("testing");
70+
descriptionLog.PropertyDictionary["schemaName"].ShouldBe("Stravaig");
71+
descriptionLog.PropertyDictionary["tableName"].ShouldBe("AppConfiguration");
72+
descriptionLog.PropertyDictionary["frequency"].ShouldBe("every 12 seconds");
73+
descriptionLog.PropertyDictionary["connectionTimeout"].ShouldBe(5);
74+
descriptionLog.PropertyDictionary["commandTimeout"].ShouldBe(30);
5275

76+
var warningLog = logs[2];
77+
warningLog.OriginalMessage.ShouldBe("The refresh interval, {refreshInterval} seconds, should be greater than combined connection, {connectionTimeout} seconds, and command, {commandTimeout} seconds, timeouts. A new refresh cycle may start before the previous cycle is complete.");
78+
warningLog.LogLevel.ShouldBe(LogLevel.Warning);
79+
warningLog.PropertyDictionary["refreshInterval"].ShouldBe(12);
80+
warningLog.PropertyDictionary["connectionTimeout"].ShouldBe(5);
81+
warningLog.PropertyDictionary["commandTimeout"].ShouldBe(30);
82+
}
5383
}

0 commit comments

Comments
 (0)