public async Task LogErrorIfNullMatReceivedFromObservable() { logger .Setup( l => l.Log( LogLevel.Error, It.IsAny <EventId>(), It.Is <It.IsSubtype <IReadOnlyList <KeyValuePair <string, object> > > >((x, _) => x.ToString().Contains("null image received")), It.Is <Exception>((e, _) => e == null), It.IsAny <Func <It.IsSubtype <IReadOnlyList <KeyValuePair <string, object> > >, Exception, string> >())) .Verifiable("Logger was not called!"); var observer = new RawImageObserver <Rgb>(logger.Object); var _ = Task.Run(async() => { await Task.Delay(TimeSpan.FromMilliseconds(110)); observer.OnNext(null); }); try { await observer.GetImage(); } catch (Exception) { // ignored - it's expected that GetImage will throw an exception, but this test checks that logger was called before that } logger.Verify(); }
public async Task ThrowInvalidOperationExceptionIfNullMatReceivedFromObservable() { var observer = new RawImageObserver <Rgb>(logger.Object); var _ = Task.Run(async() => { await Task.Delay(TimeSpan.FromMilliseconds(110)); observer.OnNext(null); }); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await observer.GetImage(); }); }
public async Task ReturnImageOnceItWasObserved() { var expectedFrame = new Mat(new Size(100, 100), DepthType.Cv32F, 3); Image <Rgb, byte> expectedImage = expectedFrame.ToImage <Rgb, byte>(); var expectedJpeg = expectedImage.ToJpegData(); var observer = new RawImageObserver <Rgb>(logger.Object); var _ = Task.Run(async() => { await Task.Delay(TimeSpan.FromMilliseconds(110)); observer.OnNext(expectedImage); }); var image = await observer.GetImage(); var actualJpeg = image.ToJpegData(); Assert.Equal(expectedJpeg, actualJpeg); }