public void CreateTraceHeaderContext_UseBackUpFunc() { var header = $"{_traceId}/{_spanId};"; var provider = CreateProviderForTraceHeaderContext(header); var headerContext = CloudTraceExtension.CreateTraceHeaderContext(provider); Assert.Equal(TraceHeaderContext.FromHeader(header).ToString(), headerContext.ToString()); }
public void CreateTraceHeaderContext_ForceTrace_NoHeader() { var provider = CreateProviderForTraceHeaderContext("", ((HttpRequest r) => true)); var headerContext = CloudTraceExtension.CreateTraceHeaderContext(provider); Assert.NotNull(headerContext.TraceId); Assert.Equal((ulong)0, headerContext.SpanId); Assert.Equal(true, headerContext.ShouldTrace); }
public void CreateTraceHeaderContext_ForceTrace(bool?shouldTrace) { var provider = CreateProviderForTraceHeaderContext($"{_traceId}/{_spanId};", ((HttpRequest r) => shouldTrace)); var headerContext = CloudTraceExtension.CreateTraceHeaderContext(provider); Assert.Equal(_traceId, headerContext.TraceId); Assert.Equal(_spanId, headerContext.SpanId); Assert.Equal(shouldTrace, headerContext.ShouldTrace); }
public void CreateManagedTracer() { var mockProvider = new Mock <IServiceProvider>(); mockProvider.Setup(p => p.GetService(typeof(IHttpContextAccessor))).Returns(new HttpContextAccessor()); var tracer = CloudTraceExtension.CreateManagedTracer(mockProvider.Object); Assert.IsType <DelegatingTracer>(tracer); mockProvider.VerifyAll(); }
public void CreateManagedTracer() { var context = TraceHeaderContext.Create(null, null, false); var tracerFactoryMock = new Mock <IManagedTracerFactory>(); tracerFactoryMock.Setup(f => f.CreateTracer(context)).Returns(NullManagedTracer.Instance); var mockProvider = new Mock <IServiceProvider>(); mockProvider.Setup(p => p.GetService(typeof(TraceHeaderContext))).Returns(context); mockProvider.Setup(p => p.GetService(typeof(IManagedTracerFactory))).Returns(tracerFactoryMock.Object); var tracer = CloudTraceExtension.CreateManagedTracer(mockProvider.Object); Assert.IsType(typeof(NullManagedTracer), tracer); tracerFactoryMock.VerifyAll(); mockProvider.VerifyAll(); }
public void CreateTraceHeaderContext() { string header = $"{TraceId}/{SpanId};o=1"; var context = new DefaultHttpContext(); var request = new DefaultHttpRequest(context); request.Headers[TraceHeaderContext.TraceHeader] = header; var accessor = new HttpContextAccessor(); accessor.HttpContext = context; Mock <IServiceProvider> mockProvider = new Mock <IServiceProvider>(); mockProvider.Setup(p => p.GetService(typeof(IHttpContextAccessor))).Returns(accessor); var headerContext = CloudTraceExtension.CreateTraceHeaderContext(mockProvider.Object); Assert.Equal(TraceHeaderContext.FromHeader(header).ToString(), headerContext.ToString()); }
public void CreateManagedTracer() { var accessor = new HttpContextAccessor(); accessor.HttpContext = new DefaultHttpContext(); var context = TraceHeaderContext.Create(null, null, false); var tracerFactoryMock = new Mock <IManagedTracerFactory>(); tracerFactoryMock.Setup(f => f.CreateTracer(context)).Returns(NullManagedTracer.Instance); var mockProvider = new Mock <IServiceProvider>(); mockProvider.Setup(p => p.GetService(typeof(TraceHeaderContext))).Returns(context); mockProvider.Setup(p => p.GetService(typeof(IManagedTracerFactory))).Returns(tracerFactoryMock.Object); mockProvider.Setup(p => p.GetService(typeof(IHttpContextAccessor))).Returns(accessor); var tracer = CloudTraceExtension.CreateManagedTracer(mockProvider.Object); Assert.IsType(typeof(NullManagedTracer), tracer); Assert.Equal(tracer, accessor.HttpContext.Items[CloudTraceExtension.TraceKey]); tracerFactoryMock.VerifyAll(); mockProvider.VerifyAll(); }