chore: begin porting code from playground

This commit is contained in:
Stevan Freeborn
2025-05-07 23:54:46 -05:00
parent 30dbba37be
commit 3f4ab165ce
19 changed files with 230 additions and 24 deletions
+4
View File
@@ -0,0 +1,4 @@
[*.cs]
dotnet_diagnostic.CA1515.severity = none
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.CA2201.severity = none
@@ -1,21 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="moq" Version="4.20.72" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0" />
</ItemGroup>
<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<CoverletOutput>./TestResults/Coverage/</CoverletOutput>
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
<Include>[StevesBot.Worker]*</Include>
<ExcludeByFile>**/Program.cs,**/Worker.cs</ExcludeByFile>
</PropertyGroup>
<Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest">
<Exec Command="reportgenerator -reports:./TestResults/Coverage/*.xml -targetdir:./TestResults/Coverage/Report/ -reporttypes:Html_Dark" />
</Target>
<ItemGroup>
<Using Include="Xunit" />
<Using Include="FluentAssertions" />
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,37 @@
namespace StevesBot.Worker.Tests.Unit;
public class DiscordClientExceptionTests
{
[Fact]
public void Constructor_WhenCalledWithoutParameters_ItShouldCreateInstance()
{
var exception = new DiscordClientException();
exception.Should().NotBeNull();
exception.Should().BeOfType<DiscordClientException>();
}
[Fact]
public void Constructor_WhenCalledWithMessage_ItShouldCreateInstance()
{
var message = "Test message";
var exception = new DiscordClientException(message);
exception.Should().NotBeNull();
exception.Should().BeOfType<DiscordClientException>();
exception.Message.Should().Be(message);
}
[Fact]
public void Constructor_WhenCalledWithMessageAndInnerException_ItShouldCreateInstance()
{
var message = "Test message";
var innerException = new Exception("Inner exception");
var exception = new DiscordClientException(message, innerException);
exception.Should().NotBeNull();
exception.Should().BeOfType<DiscordClientException>();
exception.Message.Should().Be(message);
exception.InnerException.Should().Be(innerException);
}
}
@@ -0,0 +1,37 @@
namespace StevesBot.Worker.Tests.Unit;
public class DiscordClientOptionsTests
{
[Fact]
public void Constructor_WhenCalledWithoutParameters_ItShouldCreateInstance()
{
var options = new DiscordClientOptions();
options.Should().NotBeNull();
options.Should().BeOfType<DiscordClientOptions>();
options.ApiUrl.Should().Be(string.Empty);
options.AppToken.Should().Be(string.Empty);
options.Intents.Should().Be(0);
}
[Fact]
public void Constructor_WhenCalledWithParameters_ItShouldCreateInstance()
{
var apiUrl = "https://api.example.com";
var appToken = "test-token";
var intents = 123;
var options = new DiscordClientOptions
{
ApiUrl = apiUrl,
AppToken = appToken,
Intents = intents
};
options.Should().NotBeNull();
options.Should().BeOfType<DiscordClientOptions>();
options.ApiUrl.Should().Be(apiUrl);
options.AppToken.Should().Be(appToken);
options.Intents.Should().Be(intents);
}
}
-10
View File
@@ -1,10 +0,0 @@
namespace StevesBot.Worker.Tests;
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
+1
View File
@@ -0,0 +1 @@
global using StevesBot.Worker.Discord;