Files
CBDDC/tests/ZB.MOM.WW.CBDDC.Hosting.Tests/HostedServicesTests.cs

43 lines
1.5 KiB
C#

using Microsoft.Extensions.Logging;
using ZB.MOM.WW.CBDDC.Hosting.HostedServices;
using ZB.MOM.WW.CBDDC.Network;
namespace ZB.MOM.WW.CBDDC.Hosting.Tests;
public class HostedServicesTests
{
/// <summary>
/// Verifies that the TCP sync server hosted service starts and stops the server lifecycle.
/// </summary>
[Fact]
public async Task TcpSyncServerHostedService_StartAndStop_CallsServerLifecycle()
{
var syncServer = Substitute.For<ISyncServer>();
var logger = Substitute.For<ILogger<TcpSyncServerHostedService>>();
var hostedService = new TcpSyncServerHostedService(syncServer, logger);
await hostedService.StartAsync(CancellationToken.None);
await hostedService.StopAsync(CancellationToken.None);
await syncServer.Received(1).Start();
await syncServer.Received(1).Stop();
}
/// <summary>
/// Verifies that the discovery hosted service starts and stops the discovery lifecycle.
/// </summary>
[Fact]
public async Task DiscoveryServiceHostedService_StartAndStop_CallsDiscoveryLifecycle()
{
var discoveryService = Substitute.For<IDiscoveryService>();
var logger = Substitute.For<ILogger<DiscoveryServiceHostedService>>();
var hostedService = new DiscoveryServiceHostedService(discoveryService, logger);
await hostedService.StartAsync(CancellationToken.None);
await hostedService.StopAsync(CancellationToken.None);
await discoveryService.Received(1).Start();
await discoveryService.Received(1).Stop();
}
}