Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release
- BuildBot.Json.Tests: new test project covering BuildBot.Json at 100% line and branch coverage
- BuildBot.ServiceModel.Tests: Added test coverage for all types in BuildBot.ServiceModel
- BuildBot.Discord.Tests: Added unit tests to increase code coverage to 100%
- BotService null-guard branch coverage test
### Fixed
- Suppress known Scriban 6.2.0 vulnerabilities pending upgrade
- SnsMessage: Token property was never populated from the constructor argument
- Added null guards for botMessageChannel and botReleaseMessageChannel parameters in BotService constructor
### Changed
- Dependencies - Updated NSubstitute.Analyzers.CSharp to 1.0.17
- Switched to use minimal APIs
Expand Down
34 changes: 34 additions & 0 deletions src/BuildBot.Discord.Tests/Services/BotServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using BuildBot.Discord.Models;
Expand Down Expand Up @@ -105,4 +106,37 @@ await bot.Received(1)
);
}
}

public static TheoryData<int, string> NullConstructorArguments =>
new()
{
{ 0, "bot" },
{ 1, "botMessageChannel" },
{ 2, "botReleaseMessageChannel" },
};

[Theory]
[MemberData(nameof(NullConstructorArguments))]
public void Constructor_ThrowsArgumentNullException_WhenParameterIsNull(
int nullParameterIndex,
string expectedParamName
)
{
ConstructorInfo? ctor = typeof(BotService).GetConstructor(
[typeof(IDiscordBot), typeof(IMessageChannel<BotMessage>), typeof(IMessageChannel<BotReleaseMessage>)]
);
Assert.NotNull(ctor);

object?[] args =
[
GetSubstitute<IDiscordBot>(),
GetSubstitute<IMessageChannel<BotMessage>>(),
GetSubstitute<IMessageChannel<BotReleaseMessage>>(),
];
args[nullParameterIndex] = null;

TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => ctor.Invoke(args));
ArgumentNullException ane = Assert.IsType<ArgumentNullException>(ex.InnerException);
Assert.Equal(expected: expectedParamName, actual: ane.ParamName);
}
}
5 changes: 3 additions & 2 deletions src/BuildBot.Discord/Services/BotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ IMessageChannel<BotReleaseMessage> botReleaseMessageChannel
)
{
this._bot = bot ?? throw new ArgumentNullException(nameof(bot));
this._botMessageChannel = botMessageChannel;
this._botReleaseMessageChannel = botReleaseMessageChannel;
this._botMessageChannel = botMessageChannel ?? throw new ArgumentNullException(nameof(botMessageChannel));
this._botReleaseMessageChannel =
botReleaseMessageChannel ?? throw new ArgumentNullException(nameof(botReleaseMessageChannel));

this._botMessageChannel.ReadAllAsync(this._cancellationTokenSource.Token)
.ToObservable()
Expand Down
Loading