public async Task OnNextAsync_TracerIsNull_DoesNotThrowException() { // Arrange var sut = new TracingObserver <MockMessage>(_observerMock.Object); // Act await sut.OnNextAsync(new MockMessage()); // Assert _observerMock.Verify(x => x.OnNextAsync(It.IsAny <MockMessage>(), It.IsAny <StreamSequenceToken>()), Times.Once); VerifyNotOtherCalls(); }
public async Task OnNextAsync_WithTracing_Success() { // Arrange var spanMock = new Mock <TelemetrySpan>(); _tracerMock.Setup(x => x.StartSpanFromActivity(It.IsAny <string>(), It.IsAny <Activity>(), SpanKind.Consumer, null)) .Returns(spanMock.Object); var sut = new TracingObserver <MockMessage>(_observerMock.Object, _tracerMock.Object); // Act await sut.OnNextAsync(new MockMessage()); // Assert _tracerMock.Verify(x => x.StartSpanFromActivity(It.IsAny <string>(), It.IsAny <Activity>(), SpanKind.Consumer, null), Times.Once); _observerMock.Verify(x => x.OnNextAsync(It.IsAny <MockMessage>(), It.IsAny <StreamSequenceToken>()), Times.Once); spanMock.Verify(x => x.End(), Times.Once); VerifyNotOtherCalls(); }
/// <summary> /// Subscribes a consumer to this observable, adding tracing in the consumption of items. /// </summary> /// <param name="observer">The <see cref="IAsyncObserver{T}"/> to subscribe.</param> /// <param name="token">The <see cref="StreamSequenceToken"/> to be used as an offset to start the subscription from.</param> /// <returns>A promise for a StreamSubscriptionHandle that represents the subscription. The /// consumer may unsubscribe by using this handle. The subscription remains active /// for as long as it is not explicitly unsubscribed. ///</returns> public async Task <StreamSubscriptionHandle <TMessage> > SubscribeAsync(IAsyncObserver <TMessage> observer, StreamSequenceToken token = null) { var tracingObserver = new TracingObserver <TMessage>(observer, _tracer); return(await _asyncStream.SubscribeAsync(tracingObserver, token)); }