public void WhenDisposing_ThenOperationStopsExecution_IfOperationIsCancellable( [Frozen] RepeatingOperationSettings settings, IFixture fixture) { // Arrange settings.EverySeconds = 0.1; fixture.Register <IOperation>(() => new EndlessCancellableOperationStub()); var sut = fixture.Create <RepeatingOperationProcessingManager>(); Exception raisedException = null; var eventExecutionCount = 0; sut.OnExecutionError += exception => { raisedException = exception; eventExecutionCount++; }; // Act sut.Start(); Thread.Sleep(750); sut.Dispose(); Thread.Sleep(1000); // Assert raisedException.Should().BeAssignableTo <TimeoutException>(); eventExecutionCount.Should().Be(1); }
public void WhenStarting_ThenExceptionThrown_IfStartCalledTwice( [Frozen] RepeatingOperationSettings settings, double anyInterval, IFixture fixture) { // Arrange settings.EverySeconds = anyInterval; var sut = fixture.Create <RepeatingOperationProcessingManager>(); // Act sut.Start(); Action secondStartAction = () => sut.Start(); // Assert secondStartAction.ShouldThrow <InvalidOperationException>(); }
public void WhenDisposing_ThenRepeatingWasStopped( [Frozen] Mock <IOperation> operationMock, [Frozen] RepeatingOperationSettings settings, IFixture fixture) { // Arrange settings.EverySeconds = 0.1; var sut = fixture.Create <RepeatingOperationProcessingManager>(); // Act sut.Start(); Thread.Sleep(500); sut.Dispose(); Thread.Sleep(500); // Assert operationMock.Verify( operation => operation.Execute(It.IsAny <CancellationToken>()), Times.Between(4, 6, Range.Inclusive)); }