Пример #1
0
        public async Task DropNewFramesIfPreviousOneIsStillInProgress()
        {
            var inputImage    = new Image <Rgb, byte>(1, 1);
            var expectedImage = new Image <Rgb, byte>(10, 10);

            strategy.Setup(s => s.Denoise(inputImage)).Returns(() => {
                Task.Delay(TimeSpan.FromMilliseconds(900)).Wait();
                return(expectedImage);
            });

            var denoiser = new DenoisingStream(strategy.Object, new Counter(), CancellationToken.None, logger.Object);
            var observer = new TestImageObserver <Rgb>();

            using (denoiser.Subscribe(observer))
            {
                var _ = Task.Run(() => denoiser.Process(inputImage));
                _ = Task.Run(() => denoiser.Process(inputImage));
                _ = Task.Run(() => denoiser.Process(inputImage));
                _ = Task.Run(() => denoiser.Process(inputImage));

                await Task.Delay(TimeSpan.FromMilliseconds(1300));
            }

            Assert.Single(observer.ReceivedItems);
        }
Пример #2
0
        public async Task ProvideDataForObservers()
        {
            var inputImage     = new Image <Rgb, byte>(1, 1);
            var expectedImages = new List <Image <Rgb, byte> >();
            var i = 0;

            strategy.Setup(s => s.Denoise(inputImage)).Returns(() =>
            {
                var value = new Image <Rgb, byte>(++i, 1);
                expectedImages.Add(value);
                return(value);
            });

            var denoiser = new DenoisingStream(strategy.Object, new Counter(), CancellationToken.None, logger.Object);
            var observer = new TestImageObserver <Rgb>();

            using (denoiser.Subscribe(observer))
            {
                denoiser.Process(inputImage);
                await Task.Delay(TimeSpan.FromMilliseconds(100));

                denoiser.Process(inputImage);
                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }

            Assert.Equal(2, observer.ReceivedItems.Count);
            Assert.Equal(expectedImages[0], observer.ReceivedItems.Keys.First());
            Assert.Equal(expectedImages[1], observer.ReceivedItems.Keys.Skip(1).First());
        }
Пример #3
0
        public async Task CompleteStreamIfErrorOccurred()
        {
            var inputImage = new Image <Rgb, byte>(1, 1);

            strategy.Setup(s => s.Denoise(inputImage)).Throws <TestException>();
            var denoiser = new DenoisingStream(strategy.Object, new Counter(), CancellationToken.None, logger.Object);
            var observer = new TestImageObserver <Rgb>();

            using (denoiser.Subscribe(observer))
            {
                denoiser.Process(inputImage);
                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }

            Assert.IsType <TestException>(observer.Error);
            Assert.True(observer.StreamCompleted);
        }
Пример #4
0
        public async Task NotProvideDataForObserversAfterCompletion()
        {
            var inputImage    = new Image <Rgb, byte>(1, 1);
            var expectedImage = new Image <Rgb, byte>(10, 10);

            strategy.Setup(s => s.Denoise(inputImage)).Returns(expectedImage);

            var denoiser = new DenoisingStream(strategy.Object, new Counter(), CancellationToken.None, logger.Object);
            var observer = new TestImageObserver <Rgb>();

            using (denoiser.Subscribe(observer))
            {
                denoiser.Complete();
                denoiser.Process(inputImage);
                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }

            Assert.Empty(observer.ReceivedItems);
        }