public void Run_ExceptionInsideThread_ExceptionSourceCancelled(CompressionMode compressionMode) { // arrange var threadsCount = 3; var compressionServiceMock = MockCompressionService(true); var statusUpdateServiceMock = new Mock <IStatusUpdateService>(); var service = new ParallelCompressionService(compressionServiceMock.Object, statusUpdateServiceMock.Object, new DefaultSettings()); var inputData = GenerateInputData(10); var readContext = GenerateReadContext(inputData, true, false); var threadService = new ThreadService(); // act var result = service.Run(compressionMode, threadsCount, readContext); threadService.WaitThreadsCompletion(result.Threads); // wait for completion // assert result.ExceptionSource.IsCancellationRequested.Should().BeTrue(); }
public void Run_ReturnsRightContext(CompressionMode compressionMode) { // arrange var threadsCount = 3; var compressionServiceMock = MockCompressionService(false); var statusUpdateServiceMock = new Mock <IStatusUpdateService>(); var service = new ParallelCompressionService(compressionServiceMock.Object, statusUpdateServiceMock.Object, new DefaultSettings()); var inputData = GenerateInputData(10); var readContext = GenerateReadContext(inputData, true, false); var threadService = new ThreadService(); // act var result = service.Run(compressionMode, threadsCount, readContext); threadService.WaitThreadsCompletion(result.Threads); // wait for completion // assert result.Threads.Count().Should().Be(threadsCount); result.ExceptionSource.IsCancellationRequested.Should().BeFalse(); result.OutputOverflowEvent.IsSet.Should().BeTrue(); result.ResultsDictionary.Count.Should().Be(inputData.Count); compressionServiceMock.Verify(x => x.Compress(It.IsAny <byte[]>()), Times.Exactly(compressionMode == CompressionMode.Compress ? inputData.Count : 0)); compressionServiceMock.Verify(x => x.Decompress(It.IsAny <byte[]>()), Times.Exactly(compressionMode == CompressionMode.Decompress ? inputData.Count : 0)); }