Exemplo n.º 1
0
        public async Task AsyncTrackingInterceptor_GivenTrackingContext_WhenReturnAsync_ThenSameTrackingContextReturned()
        {
            var instance    = new TestTrackingService();
            var interceptor = new AsyncTrackingInterceptor();

            ITestTrackingService proxy = s_ProxyGenerator.CreateInterfaceProxyWithTargetInterface <ITestTrackingService>(instance, interceptor.ToInterceptor());

            TrackingContext.NewCurrent();
            TrackingContext currentTrackingContext = TrackingContext.Current;

            currentTrackingContext.Should().NotBeNull();

            TrackingContext returnedTrackingContext = null;
            await proxy.ReturnAsync(() =>
            {
                returnedTrackingContext = TrackingContext.Current;
            }).ConfigureAwait(false);

            TrackingContext.Current.Should().NotBeNull();
            TrackingContext.Current.CallChainId.Should().Be(currentTrackingContext.CallChainId);
            TrackingContext.Current.OriginatorUtcTimestamp.Should().Be(currentTrackingContext.OriginatorUtcTimestamp);

            returnedTrackingContext.Should().NotBeNull();
            returnedTrackingContext.CallChainId.Should().Be(currentTrackingContext.CallChainId);
            returnedTrackingContext.OriginatorUtcTimestamp.Should().Be(currentTrackingContext.OriginatorUtcTimestamp);
        }
        public async Task AsyncTrackingInterceptor_ReturnAsyncWithCurrent_SameTrackingContextReturned()
        {
            var instance    = new TestTrackingService();
            var interceptor = new AsyncTrackingInterceptor();

            ITestTrackingService proxy = s_ProxyGenerator.CreateInterfaceProxyWithTargetInterface <ITestTrackingService>(instance, interceptor.ToInterceptor());

            TrackingContext.NewCurrent();
            TrackingContext currentTrackingContext = TrackingContext.Current;

            Assert.IsNotNull(currentTrackingContext);

            TrackingContext returnedTrackingContext = null;
            await proxy.ReturnAsync(() =>
            {
                returnedTrackingContext = TrackingContext.Current;
            });

            Assert.IsNotNull(TrackingContext.Current);
            Assert.AreEqual(TrackingContext.Current.CallChainId, currentTrackingContext.CallChainId);
            Assert.AreEqual(TrackingContext.Current.OriginatorUtcTimestamp, currentTrackingContext.OriginatorUtcTimestamp);

            Assert.IsNotNull(returnedTrackingContext);
            Assert.AreEqual(currentTrackingContext.CallChainId, returnedTrackingContext.CallChainId);
            Assert.AreEqual(currentTrackingContext.OriginatorUtcTimestamp, returnedTrackingContext.OriginatorUtcTimestamp);
        }
Exemplo n.º 3
0
        public async Task AsyncTrackingInterceptor_GivenNoTrackingContext_WhenReturnTrackingContextAsync_ThenNewTrackingContextReturned()
        {
            var instance    = new TestTrackingService();
            var interceptor = new AsyncTrackingInterceptor();

            ITestTrackingService proxy = s_ProxyGenerator.CreateInterfaceProxyWithTargetInterface <ITestTrackingService>(instance, interceptor.ToInterceptor());

            TrackingContext.Current.Should().BeNull();

            TrackingContext returnedTrackingContext = await proxy.ReturnTrackingContextAsync().ConfigureAwait(false);

            returnedTrackingContext.Should().NotBeNull();
            TrackingContext.Current.Should().BeNull();
        }
        public async Task AsyncTrackingInterceptor_ReturnTrackingContextAsyncWithoutCurrent_NewTrackingContextReturned()
        {
            var instance    = new TestTrackingService();
            var interceptor = new AsyncTrackingInterceptor();

            ITestTrackingService proxy = s_ProxyGenerator.CreateInterfaceProxyWithTargetInterface <ITestTrackingService>(instance, interceptor.ToInterceptor());

            Assert.IsNull(TrackingContext.Current);

            TrackingContext returnedTrackingContext = await proxy.ReturnTrackingContextAsync();

            Assert.IsNotNull(returnedTrackingContext);
            Assert.IsNull(TrackingContext.Current);
        }