More work on SeqBackgroundService, next step is tests for it.

This commit is contained in:
Janus C. H. Knudsen 2025-02-18 16:23:08 +01:00
parent a139b1ad08
commit 67207cf90b
27 changed files with 237 additions and 190 deletions

View file

@ -1,13 +1,8 @@
using Core.Configurations.SmartConfig;
using Core.Configurations;
using Core.Configurations;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using Core.Configurations.JsonConfigProvider;
using Autofac;
using System.Data;
using Insight.Database;
using Npgsql;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Core.Configurations.SmartConfigProvider;
namespace Tests.ConfigurationTests
{
@ -25,7 +20,7 @@ namespace Tests.ConfigurationTests
}") as JToken;
var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile("ConfigurationTests/appconfiguration.dev.json")
.Build();
// Act

View file

@ -1,7 +1,4 @@
using Moq;
using Newtonsoft.Json.Linq;
using Tests;
using Core.Configurations.SmartConfig;
using Newtonsoft.Json.Linq;
using Core.Configurations.Common;
namespace Tests.ConfigurationTests;

View file

@ -1,11 +1,11 @@
using Core.Configurations.SmartConfig;
using Core.Configurations;
using Core.Configurations;
using FluentAssertions;
using Core.Configurations.JsonConfigProvider;
using Autofac;
using System.Data;
using Insight.Database;
using Npgsql;
using Core.Configurations.SmartConfigProvider;
namespace Tests.ConfigurationTests
{

View file

@ -1,17 +1,14 @@
using Autofac;
using System.Data;
using Insight.Database;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Extensions.Logging;
using Core.Telemetry;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Core.Logging;
namespace Tests
namespace Tests.Logging
{
[TestClass]
public class MessageChannelIntegrationTests : TestFixture
public class SeqBackgroundServiceTest : TestFixture
{
private IMessageChannel<ITelemetry> _messageChannel;
private SeqBackgroundService _service;
@ -22,10 +19,17 @@ namespace Tests
{
_messageChannel = new MessageChannel();
var telemetryClient = Container.Resolve<TelemetryClient>();
var httpClient = new HttpClient(new TestMessageHandler());
_service = new SeqBackgroundService(telemetryClient, _messageChannel, httpClient);
var config = new SeqConfiguration("http://localhost:5341", null, "MSTEST");
var httpClient = new SeqHttpClient(config);
var logger = new SeqLogger(httpClient, Environment.MachineName, config);
_service = new SeqBackgroundService(telemetryClient, _messageChannel, logger);
_cts = new CancellationTokenSource();
}
}
[TestMethod]
public async Task Messages_ShouldBeProcessedFromQueue()

View file

@ -1,8 +1,7 @@
using Core.Telemetry;
using Microsoft.ApplicationInsights.Channel;
using Core.Logging;
using Microsoft.ApplicationInsights.DataContracts;
namespace Tests.TelemetryLogging
namespace Tests.Logging
{
[TestClass]
public class SeqLoggerTests : TestFixture
@ -34,8 +33,7 @@ namespace Tests.TelemetryLogging
// Act
await _logger.LogAsync(traceTelemetry);
// Du kan nu tjekke Seq med følgende query:
// TestId = 'guid-værdi-her'
}
[TestMethod]
public async Task LogTraceTelemetry_SendsCorrectDataWithWarningLevel()

View file

@ -27,7 +27,10 @@
</ItemGroup>
<ItemGroup>
<None Update="appconfiguration.dev.json">
<None Update="xappconfiguration.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ConfigurationTests\appconfiguration.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

View file

@ -0,0 +1,60 @@
{
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
},
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
},
"Authentication": "SHA256",
"Feature": {
"Enabled": true,
"RolloutPercentage": 25,
"AllowedUserGroups": [ "beta" ]
},
"AnotherSetting": {
"Thresholds": {
"High": "123",
"Low": "-1"
},
"Temperature": {
"Indoor": {
"Max": { "Limit": 22 },
"Min": { "Limit": 18 }
},
"Outdoor": {
"Max": { "Limit": 12 },
"Min": { "Limit": 9 }
}
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341",
"apiKey": ""
}
}
],
"Enrich": [
"WithMachineName",
"WithThreadId",
"WithProcessId",
"WithEnvironmentName"
],
"Properties": {
"Application": "PlanTempus"
}
}
}