Files
CBDDC/tests/ZB.MOM.WW.CBDDC.Core.Tests/PeerManagementServiceTests.cs
Joseph Doherty 7ebc2cb567
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m10s
Reformat/cleanup
2026-02-21 07:53:53 -05:00

75 lines
3.3 KiB
C#

using ZB.MOM.WW.CBDDC.Core.Management;
using ZB.MOM.WW.CBDDC.Core.Storage;
namespace ZB.MOM.WW.CBDDC.Core.Tests;
public class PeerManagementServiceTests
{
/// <summary>
/// Verifies that removing peer tracking with remote removal enabled removes both tracking and remote peer
/// configuration.
/// </summary>
[Fact]
public async Task RemovePeerTrackingAsync_WhenRemoveRemoteConfigTrue_RemovesTrackingAndRemoteConfig()
{
var configStore = Substitute.For<IPeerConfigurationStore>();
var confirmationStore = Substitute.For<IPeerOplogConfirmationStore>();
var service = new PeerManagementService(configStore, confirmationStore);
var token = new CancellationTokenSource().Token;
await service.RemovePeerTrackingAsync("peer-1", true, token);
await confirmationStore.Received(1).RemovePeerTrackingAsync("peer-1", token);
await configStore.Received(1).RemoveRemotePeerAsync("peer-1", token);
}
/// <summary>
/// Verifies that removing peer tracking with remote removal disabled removes only tracking data.
/// </summary>
[Fact]
public async Task RemovePeerTrackingAsync_WhenRemoveRemoteConfigFalse_RemovesTrackingOnly()
{
var configStore = Substitute.For<IPeerConfigurationStore>();
var confirmationStore = Substitute.For<IPeerOplogConfirmationStore>();
var service = new PeerManagementService(configStore, confirmationStore);
await service.RemovePeerTrackingAsync("peer-1", false);
await confirmationStore.Received(1).RemovePeerTrackingAsync("peer-1", Arg.Any<CancellationToken>());
await configStore.DidNotReceive().RemoveRemotePeerAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
}
/// <summary>
/// Verifies that removing a remote peer delegates to tracking removal with remote configuration cleanup enabled.
/// </summary>
[Fact]
public async Task RemoveRemotePeerAsync_DelegatesToTrackingRemovalWithRemoteConfig()
{
var configStore = Substitute.For<IPeerConfigurationStore>();
var confirmationStore = Substitute.For<IPeerOplogConfirmationStore>();
var service = new PeerManagementService(configStore, confirmationStore);
var token = new CancellationTokenSource().Token;
await service.RemoveRemotePeerAsync("peer-1", token);
await confirmationStore.Received(1).RemovePeerTrackingAsync("peer-1", token);
await configStore.Received(1).RemoveRemotePeerAsync("peer-1", token);
}
/// <summary>
/// Verifies that removing peer tracking with an invalid node identifier throws an <see cref="ArgumentException" />.
/// </summary>
[Fact]
public async Task RemovePeerTrackingAsync_WhenNodeIdInvalid_ThrowsArgumentException()
{
var configStore = Substitute.For<IPeerConfigurationStore>();
var confirmationStore = Substitute.For<IPeerOplogConfirmationStore>();
var service = new PeerManagementService(configStore, confirmationStore);
await Should.ThrowAsync<ArgumentException>(() => service.RemovePeerTrackingAsync(" ", true));
await confirmationStore.DidNotReceive()
.RemovePeerTrackingAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
await configStore.DidNotReceive().RemoveRemotePeerAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
}
}