public void Test_ApplicationHost_BackgroundOperationInvalid() { // Arrange var hostedService = new BackgroundTimerService(); // Act/Assert Assert.Throws <ArgumentException>(() => new AppHostBuilder().UseBackgroundMonitor(0) .AddHostedProcess(hostedService)); }
public void Test_ApplicationHost_BackgroundOperation() { // Arrange var hostedService = new BackgroundTimerService(); var appHost = new AppHostBuilder().UseBackgroundMonitor(3).AddHostedProcess(hostedService).Build(); hostedService.StopProcessing = (context) => { hostedService.StopProcessing = null; var host = ((AppHost)appHost); host._cancellation.Dispose(); host.ProcessingStop(); // Assert context.ApplicationRunDuration.Should().BeGreaterThan(TimeSpan.Zero); context.IsContinuouslyRunning.Should().BeTrue(); context.IsBackgroundMonitorRunning.Should().BeTrue(); context.SystemInfo.Should().NotBe(null); hostedService.BackgroundTickCount.Should().Be(1); }; // Act appHost.RunOnce(); }