Skip to content

Commit

Permalink
Merge pull request #125 from austins/nunit
Browse files Browse the repository at this point in the history
NUnit
  • Loading branch information
austins authored Feb 5, 2024
2 parents 0a06e73 + 3696241 commit a71238a
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 121 deletions.
3 changes: 2 additions & 1 deletion DiscordTranslationBot.Tests/AssemblySetup.cs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
[assembly: Parallelizable(ParallelScope.All)]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace DiscordTranslationBot.Tests.Commands.TempReply;

[TestClass]
public sealed class DeleteTempReplyValidatorTests
{
private readonly DeleteTempReplyValidator _sut;
Expand All @@ -15,7 +14,7 @@ public DeleteTempReplyValidatorTests()
_sut = new DeleteTempReplyValidator();
}

[TestMethod]
[Test]
public async Task Valid_ValidatesWithoutErrors()
{
// Arrange
Expand All @@ -37,7 +36,7 @@ public async Task Valid_ValidatesWithoutErrors()
result.ShouldNotHaveAnyValidationErrors();
}

[TestMethod]
[Test]
public async Task Invalid_Reply_HasValidationErrors()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace DiscordTranslationBot.Tests.Commands.TempReply;

[TestClass]
public sealed class SendTempReplyValidatorTests
{
private readonly SendTempReplyValidator _sut;
Expand All @@ -15,7 +14,7 @@ public SendTempReplyValidatorTests()
_sut = new SendTempReplyValidator();
}

[TestMethod]
[Test]
public async Task Valid_ValidatesWithoutErrors()
{
// Arrange
Expand All @@ -38,10 +37,9 @@ public async Task Valid_ValidatesWithoutErrors()
result.ShouldNotHaveAnyValidationErrors();
}

[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
public async Task Invalid_Reply_HasValidationErrors(string? text)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

namespace DiscordTranslationBot.Tests.Configuration;

[TestClass]
public sealed class DiscordOptionsValidatorTests
{
private readonly DiscordOptionsValidator _sut = new();

[TestMethod]
[Test]
public void Valid_Options_ValidatesWithoutErrors()
{
// Arrange
Expand All @@ -21,10 +20,9 @@ public void Valid_Options_ValidatesWithoutErrors()
result.ShouldNotHaveAnyValidationErrors();
}

[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
public void Invalid_BotToken_HasValidationErrors(string? botToken)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

namespace DiscordTranslationBot.Tests.Configuration.TranslationProviders;

[TestClass]
public sealed class TranslationProvidersOptionsValidatorTests
{
private readonly TranslationProvidersOptionsValidator _sut = new();

[TestMethod]
[Test]
public void Valid_Options_ValidatesWithoutErrors()
{
// Arrange
Expand All @@ -31,10 +30,9 @@ public void Valid_Options_ValidatesWithoutErrors()
result.ShouldNotHaveAnyValidationErrors();
}

[DataTestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
public void Invalid_ProviderOptions_HasValidationErrors(string? stringValue)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="MSTest" Version="3.2.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="NSubstitute" Version="5.1.0"/>
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="4.0.1"/>
<PackageReference Include="NUnit.Analyzers" Version="4.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace DiscordTranslationBot.Tests.Handlers;

[TestClass]
public sealed class FlagEmojiReactionHandlerTests
{
private const string Content = """
Expand Down Expand Up @@ -69,7 +68,7 @@ public FlagEmojiReactionHandlerTests()
new LoggerFake<FlagEmojiReactionHandler>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_Returns_IfNotEmoji()
{
// Arrange
Expand All @@ -90,7 +89,7 @@ public async Task Handle_ReactionAddedNotification_Returns_IfNotEmoji()
_countryService.DidNotReceive().TryGetCountry(Arg.Any<string>(), out Arg.Any<Country?>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_Returns_IfCountryNotFound()
{
// Arrange
Expand Down Expand Up @@ -118,7 +117,7 @@ await _message.DidNotReceive()
await _mediator.DidNotReceive().Send(Arg.Any<SendTempReply>(), Arg.Any<CancellationToken>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_Returns_WhenTranslatingBotMessage()
{
// Arrange
Expand Down Expand Up @@ -157,7 +156,7 @@ await _translationProvider.DidNotReceive()
.TranslateByCountryAsync(Arg.Any<Country>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_Success()
{
// Arrange
Expand Down Expand Up @@ -208,7 +207,7 @@ await _mediator.Received(1)
Arg.Any<CancellationToken>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_Returns_SanitizesMessageEmpty()
{
// Arrange
Expand Down Expand Up @@ -247,7 +246,7 @@ await _translationProvider.DidNotReceive()
await _message.Received(1).RemoveReactionAsync(Arg.Any<IEmote>(), Arg.Any<ulong>(), Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_NoTranslationResult()
{
// Arrange
Expand Down Expand Up @@ -287,7 +286,7 @@ public async Task Handle_ReactionAddedNotification_NoTranslationResult()
await _message.Received(1).RemoveReactionAsync(Arg.Any<IEmote>(), Arg.Any<ulong>(), Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task
Handle_ReactionAddedNotification_TempReplySent_WhenUnsupportedCountryExceptionIsThrown_ForLastTranslationProvider()
{
Expand Down Expand Up @@ -331,7 +330,7 @@ await _translationProvider.Received(1)
await _mediator.Received(1).Send(Arg.Any<SendTempReply>(), Arg.Any<CancellationToken>());
}

[TestMethod]
[Test]
public async Task Handle_ReactionAddedNotification_TempReplySent_OnFailureToDetectSourceLanguage()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace DiscordTranslationBot.Tests.Handlers;

[TestClass]
public sealed class RedirectLogMessageToLoggerHandlerTests
{
private readonly LoggerFake<RedirectLogMessageToLoggerHandler> _logger;
Expand All @@ -16,13 +15,12 @@ public RedirectLogMessageToLoggerHandlerTests()
_sut = new RedirectLogMessageToLoggerHandler(_logger);
}

[DataTestMethod]
[DataRow(LogSeverity.Debug, LogLevel.Trace)]
[DataRow(LogSeverity.Verbose, LogLevel.Debug)]
[DataRow(LogSeverity.Info, LogLevel.Information)]
[DataRow(LogSeverity.Warning, LogLevel.Warning)]
[DataRow(LogSeverity.Error, LogLevel.Error)]
[DataRow(LogSeverity.Critical, LogLevel.Critical)]
[TestCase(LogSeverity.Debug, LogLevel.Trace)]
[TestCase(LogSeverity.Verbose, LogLevel.Debug)]
[TestCase(LogSeverity.Info, LogLevel.Information)]
[TestCase(LogSeverity.Warning, LogLevel.Warning)]
[TestCase(LogSeverity.Error, LogLevel.Error)]
[TestCase(LogSeverity.Critical, LogLevel.Critical)]
public async Task Handle_LogNotification_Success(LogSeverity severity, LogLevel expectedLevel)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

namespace DiscordTranslationBot.Tests.Handlers;

[TestClass]
public sealed class RegisterCommandsHandlerTests
{
private const string ProviderName = "Test Provider";
#pragma warning disable NUnit1032
private readonly IDiscordClient _client;
#pragma warning restore NUnit1032
private readonly RegisterCommandsHandler _sut;
private readonly TranslationProviderBase _translationProvider;

Expand All @@ -27,7 +28,7 @@ public RegisterCommandsHandlerTests()
new LoggerFake<RegisterCommandsHandler>());
}

[TestMethod]
[Test]
public async Task Handle_ReadyNotification_Success()
{
// Arrange
Expand Down Expand Up @@ -67,7 +68,7 @@ await guild.Received(1)
}
}

[TestMethod]
[Test]
public async Task Handle_ReadyNotification_NoGuilds_Returns()
{
// Arrange
Expand All @@ -82,7 +83,7 @@ public async Task Handle_ReadyNotification_NoGuilds_Returns()
_ = _translationProvider.DidNotReceive().TranslateCommandLangCodes;
}

[TestMethod]
[Test]
public async Task Handle_JoinedGuildNotification_Success()
{
// Arrange
Expand Down
7 changes: 3 additions & 4 deletions DiscordTranslationBot.Tests/Handlers/TempReplyHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace DiscordTranslationBot.Tests.Handlers;

[TestClass]
public sealed class TempReplyHandlerTests
{
private readonly IMediator _mediator;
Expand All @@ -20,7 +19,7 @@ public TempReplyHandlerTests()
_sut = new TempReplyHandler(_mediator, new LoggerFake<TempReplyHandler>());
}

[TestMethod]
[Test]
public async Task Handle_DeleteTempReply_Success_WithReactionAndSourceMessage()
{
// Arrange
Expand Down Expand Up @@ -57,7 +56,7 @@ await sourceMessage.Received(1)
await request.Reply.ReceivedWithAnyArgs(1).DeleteAsync();
}

[TestMethod]
[Test]
public async Task Handle_DeleteTempReply_Success_NoReactionAndSourceMessage()
{
// Arrange
Expand All @@ -77,7 +76,7 @@ public async Task Handle_DeleteTempReply_Success_NoReactionAndSourceMessage()
await request.Reply.ReceivedWithAnyArgs(1).DeleteAsync();
}

[TestMethod]
[Test]
public async Task Handle_SendTempReply_Success()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace DiscordTranslationBot.Tests.Handlers;

[TestClass]
public sealed class TranslateMessageCommandHandlerTests
{
private const ulong BotUserId = 1UL;
Expand Down Expand Up @@ -46,7 +45,7 @@ public TranslateMessageCommandHandlerTests()
_sut.Configure().GetJumpUrl(_message).Returns(new Uri("http://localhost/test"));
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_Success()
{
// Arrange
Expand Down Expand Up @@ -89,7 +88,7 @@ await _command.Received(1)
options: Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_NotTranslateCommand_Returns()
{
// Arrange
Expand All @@ -108,7 +107,7 @@ await notification.Command.DidNotReceive()
.FollowupAsync(Arg.Any<string>(), ephemeral: Arg.Any<bool>(), options: Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_Returns_WhenSanitizedMessageIsEmpty()
{
// Arrange
Expand All @@ -128,7 +127,7 @@ await _command.Received(1)
_ = _translationProviders[0].DidNotReceive().SupportedLanguages;
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_UsesNextTranslationProvider_Success()
{
// Arrange
Expand Down Expand Up @@ -176,7 +175,7 @@ await _command.Received(1)
options: Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_Returns_WhenTranslatingBotMessage()
{
// Arrange
Expand All @@ -197,7 +196,7 @@ await _command.Received(1)
options: Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_Returns_IfNoProviderSupportsLocale()
{
// Arrange
Expand Down Expand Up @@ -235,7 +234,7 @@ await _command.Received(1)
options: Arg.Any<RequestOptions>());
}

[TestMethod]
[Test]
public async Task Handle_MessageCommandExecutedNotification_Returns_WhenTranslatedTextIsSame()
{
// Arrange
Expand Down
Loading

0 comments on commit a71238a

Please sign in to comment.