Ejemplo n.º 1
0
        public async Task Should_Not_Substitue_Existing_Operation_Id_If_Context_Contains_Null()
        {
            using (new OperationContextScope("opid", "parentid"))
            {
                var context = new MockOwinContext();

                var collector = new OperationContextCollectingMiddleware();
                var sut       = new RestoreOperationIdContextMiddleware(collector);

                await sut.Invoke(context);

                collector.OperationIdFromAmbientContext.Should().Be("opid");
                collector.ParentOperationIdFromAmbientContext.Should().Be("parentid");
            }
        }
Ejemplo n.º 2
0
        public async Task Can_Restore_Operation_Context_Id_From_Owin_Context()
        {
            var context = new MockOwinContext();

            context.Set(Consts.OperationIdContextKey, "opid");
            context.Set(Consts.ParentOperationIdContextKey, "parentid");

            var collector = new OperationContextCollectingMiddleware();
            var sut       = new RestoreOperationIdContextMiddleware(collector);

            await sut.Invoke(context);

            collector.OperationIdFromAmbientContext.Should().Be("opid");
            collector.ParentOperationIdFromAmbientContext.Should().Be("parentid");
        }
        public async Task Can_Establish_Id_Context()
        {
            var actual = new OperationContextCollectingMiddleware();

            var sut = new OperationIdContextMiddleware(
                actual,
                new OperationIdContextMiddlewareConfiguration
            {
                OperationIdFactory = _ => "operationid"
            });

            await sut.Invoke(new MockOwinContextBuilder().Build());

            actual.OperationIdFromAmbientContext.Should().Be("operationid");
            actual.OperationIdFromEnvironment.Should().Be("operationid");

            actual.ParentOperationIdFromAmbientContext.Should().Be("operationid");
            actual.ParentOperationIdFromEnvironment.Should().Be("operationid");
        }
        public async Task Should_Establish_New_OperationContext_With_ReqestId_As_ParentId()
        {
            // given
            var context = new MockOwinContextBuilder().Build();

            var configuration = new TelemetryConfigurationBuilder().Build();

            var actual = new OperationContextCollectingMiddleware();

            var sut = new OperationIdContextMiddleware(
                new HttpRequestTrackingMiddleware(
                    actual,
                    new RequestTrackingConfiguration
            {
                TelemetryConfiguration = configuration,
                RequestIdFactory       = _ => "requestid"
            }),
                new OperationIdContextMiddlewareConfiguration
            {
                OperationIdFactory = _ => "operationid"
            });

            // when
            await sut.Invoke(context);

            // then
            var channel = configuration.TelemetryChannel as MockTelemetryChannel;

            var telemetry = channel.SentTelemetries.First() as RequestTelemetry;

            telemetry.Should().NotBeNull();
            telemetry.Id.Should().Be("requestid");

            actual.ParentOperationIdFromAmbientContext.Should().Be("requestid");
            actual.ParentOperationIdFromEnvironment.Should().Be("requestid");
            actual.OperationIdFromEnvironment.Should().Be("operationid");
            actual.OperationIdFromAmbientContext.Should().Be("operationid");
        }