refactor: extract tests to library test project
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class CreateMessageRequestTests
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class DiscordClientOptionsTests
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class DiscordMessageReferenceTests
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class DiscordMessageReferenceTypesTests
|
||||
{
|
||||
@@ -0,0 +1 @@
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class DiscordRestClientExceptionTests
|
||||
{
|
||||
+1
-3
@@ -1,6 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public sealed class DiscordRestClientTests : IDisposable
|
||||
{
|
||||
@@ -0,0 +1 @@
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class HostExtensionsTests
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public class SeqOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
var result = new SeqOptions();
|
||||
|
||||
result.ServerUrl.Should().Be(string.Empty);
|
||||
result.ApiKeyHeader.Should().Be(string.Empty);
|
||||
result.ApiKey.Should().Be(string.Empty);
|
||||
result.IsEnabled.Should().BeFalse();
|
||||
result.LogEndpoint.Should().Be($"{string.Empty}/ingest/otlp/v1/logs");
|
||||
result.TraceEndpoint.Should().Be($"{string.Empty}/ingest/otlp/v1/traces");
|
||||
result.AuthHeader.Should().Be($"{string.Empty}={string.Empty}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenPropertiesSet_ItShouldReturnCorrectValues()
|
||||
{
|
||||
var serverUrl = "http://example.com";
|
||||
var apiKeyHeader = "ApiKeyHeader";
|
||||
var apiKey = "ApiKeyValue";
|
||||
|
||||
var result = new SeqOptions
|
||||
{
|
||||
ServerUrl = serverUrl,
|
||||
ApiKeyHeader = apiKeyHeader,
|
||||
ApiKey = apiKey
|
||||
};
|
||||
|
||||
result.ServerUrl.Should().Be(serverUrl);
|
||||
result.ApiKeyHeader.Should().Be(apiKeyHeader);
|
||||
result.ApiKey.Should().Be(apiKey);
|
||||
result.IsEnabled.Should().BeTrue();
|
||||
result.LogEndpoint.Should().Be($"{serverUrl}/ingest/otlp/v1/logs");
|
||||
result.TraceEndpoint.Should().Be($"{serverUrl}/ingest/otlp/v1/traces");
|
||||
result.AuthHeader.Should().Be($"{apiKeyHeader}={apiKey}");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null, null, false)]
|
||||
[InlineData("", "", "", false)]
|
||||
[InlineData("http://example.com", null, null, false)]
|
||||
[InlineData("http://example.com", "", "", false)]
|
||||
[InlineData(null, "ApiKeyHeader", null, false)]
|
||||
[InlineData(null, null, "ApiKeyValue", false)]
|
||||
[InlineData("http://example.com", "ApiKeyHeader", "ApiKeyValue", true)]
|
||||
[InlineData("http://example.com", "", "ApiKeyValue", false)]
|
||||
[InlineData("", "ApiKeyHeader", "ApiKeyValue", false)]
|
||||
[InlineData("http://example.com", "ApiKeyHeader", null, false)]
|
||||
[InlineData("", "ApiKeyHeader", null, false)]
|
||||
[InlineData(null, "ApiKeyHeader", "ApiKeyValue", false)]
|
||||
public void IsEnabled_WhenPropertiesAreEmpty_ItShouldReturnFalse(string? serverUrl, string? apiKeyHeader, string? apiKey, bool expected)
|
||||
{
|
||||
var result = new SeqOptions
|
||||
{
|
||||
ServerUrl = serverUrl!,
|
||||
ApiKeyHeader = apiKeyHeader!,
|
||||
ApiKey = apiKey!
|
||||
};
|
||||
|
||||
result.IsEnabled.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public sealed class StevesBotWebhookInstrumentationTests : IDisposable
|
||||
{
|
||||
private readonly StevesBotWebhookInstrumentation _instrumentation = new();
|
||||
|
||||
[Fact]
|
||||
public void SourceName_WhenCalled_ItShouldReturnCorrectName()
|
||||
{
|
||||
_instrumentation.SourceName.Should().Be("StevesBot.Webhook");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SourceVersion_WhenCalled_ItShouldReturnCorrectVersion()
|
||||
{
|
||||
_instrumentation.SourceVersion.Should().Be("0.0.0");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
using var result = new StevesBotWorkerInstrumentation();
|
||||
using var expectedSource = new ActivitySource(_instrumentation.SourceName, _instrumentation.SourceVersion);
|
||||
|
||||
result.Source.Should().BeEquivalentTo(expectedSource);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_instrumentation.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace StevesBot.Library.Tests.Unit;
|
||||
|
||||
public sealed class StevesBotWorkerInstrumentationTests : IDisposable
|
||||
{
|
||||
private readonly StevesBotWorkerInstrumentation _instrumentation = new();
|
||||
|
||||
[Fact]
|
||||
public void SourceName_WhenCalled_ItShouldReturnCorrectName()
|
||||
{
|
||||
_instrumentation.SourceName.Should().Be("StevesBot.Worker");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SourceVersion_WhenCalled_ItShouldReturnCorrectVersion()
|
||||
{
|
||||
_instrumentation.SourceVersion.Should().Be("0.0.0");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
using var result = new StevesBotWorkerInstrumentation();
|
||||
using var expectedSource = new ActivitySource(_instrumentation.SourceName, _instrumentation.SourceVersion);
|
||||
|
||||
result.Source.Should().BeEquivalentTo(expectedSource);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_instrumentation.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,16 @@
|
||||
global using System.Diagnostics;
|
||||
global using System.Net;
|
||||
global using System.Text.Json;
|
||||
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
|
||||
global using Moq;
|
||||
|
||||
global using RichardSzalay.MockHttp;
|
||||
|
||||
global using StevesBot.Library.Discord;
|
||||
global using StevesBot.Library.Discord.Common;
|
||||
global using StevesBot.Library.Discord.Rest;
|
||||
global using StevesBot.Library.Discord.Rest;
|
||||
global using StevesBot.Library.Discord.Rest.Requests;
|
||||
global using StevesBot.Library.Telemetry;
|
||||
|
||||
Reference in New Issue
Block a user