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