public async void ShouldProcessNextImageAfterCurrentIsProcessed()
        {
            // Given
            var engine = new AsyncProcessingEngine(ImageProvider.Object, ImageProcessingChain.Object, ReceiveProcessedImageCommand.Object);

            // When
            await StartProcessingWaitForSpecifiedTimeAndWaitForEnd(engine, 2400);

            // Then
            Assert.AreEqual(2, TimesImageProcessingChainCalled);
        }
        public async void ShouldNotProcessImageBeforeAcquiringIt()
        {
            // Given
            var engine = new AsyncProcessingEngine(ImageProvider.Object, ImageProcessingChain.Object, ReceiveProcessedImageCommand.Object);

            // When
            await StartProcessingWaitForSpecifiedTimeAndWaitForEnd(engine, 400);

            // Then
            Assert.AreEqual(1, TimesImageProviderCalled);
            Assert.AreEqual(0, TimesImageProcessingChainCalled);
        }
        public async void ShouldSetOutputImageAfterProcessing()
        {
            // Given
            var engine = new AsyncProcessingEngine(ImageProvider.Object, ImageProcessingChain.Object, ReceiveProcessedImageCommand.Object);

            // When
            await StartProcessingWaitForSpecifiedTimeAndWaitForEnd(engine, 1750);

            // Then
            Assert.That(1 <= TimesImageProcessingChainCalled);
            Assert.That(1 <= TimesReceiveProcessedImageCommandCalled);
        }
        public void ShouldNotAllowToStopNotStartedEngine()
        {
            // Given
            var   imageProvider = new Mock <IImageProvider>();
            Image image;

            imageProvider.Setup(ia => ia.TryToObtainImage(out image)).Callback(ImageProviderMockWork).ReturnsInOrder(true, false);


            var engine = new AsyncProcessingEngine(imageProvider.Object, ImageProcessingChain.Object, ReceiveProcessedImageCommand.Object);

            // When
            // Then
            Assert.Throws <InvalidEngineStateException>(async() => await engine.Stop());
        }
        public async void ShouldInformAboutNotWorkingWhenNoThreadRunning()
        {
            // Given
            var   imageProvider = new Mock <IImageProvider>();
            Image image;

            imageProvider.Setup(ia => ia.TryToObtainImage(out image)).Callback(ImageProviderMockWork).ReturnsInOrder(true, false);


            var engine = new AsyncProcessingEngine(imageProvider.Object, ImageProcessingChain.Object, ReceiveProcessedImageCommand.Object);

            // When
            await engine.Start();

            // Then
            Assert.IsFalse(engine.IsWorking());
        }
        public async void ShouldStopWorkingAfterNoImageWasObtained()
        {
            // Given
            var   imageProvider = new Mock <IImageProvider>();
            Image image;

            imageProvider.Setup(ia => ia.TryToObtainImage(out image)).Callback(ImageProviderMockWork).ReturnsInOrder(true, false);


            var engine = new AsyncProcessingEngine(imageProvider.Object, ImageProcessingChain.Object, ReceiveProcessedImageCommand.Object);

            // When
            await StartProcessingWaitForSpecifiedTimeAndWaitForEnd(engine, 2000);

            // Then
            Assert.That(1 >= TimesImageProcessingChainCalled);
            Assert.AreEqual(1, TimesReceiveProcessedImageCommandCalled);
        }