74 lines
3.4 KiB
C#
74 lines
3.4 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", removeRemoteConfig: 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", removeRemoteConfig: 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(" ", removeRemoteConfig: true));
|
|
|
|
await confirmationStore.DidNotReceive().RemovePeerTrackingAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
|
|
await configStore.DidNotReceive().RemoveRemotePeerAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
|
|
}
|
|
}
|