public void ScopeManager_NotNull() { var shim = TracerShim.Create(tracer); // Internals of the ScopeManagerShim tested elsewhere Assert.NotNull(shim.ScopeManager as ScopeManagerShim); }
public void BuildSpan_NotNull() { var shim = TracerShim.Create(tracer); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); }
public void Extract_ArgumentValidation() { var shim = TracerShim.Create(tracer); Assert.Throws <ArgumentNullException>(() => shim.Extract(null, new Mock <ITextMap>().Object)); Assert.Throws <ArgumentNullException>(() => shim.Extract(new Mock <IFormat <ITextMap> >().Object, null)); }
public void BuildSpan_NotNull() { var tracerMock = new Mock <Trace.ITracer>(); var shim = TracerShim.Create(tracerMock.Object); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); }
public void ScopeManager_NotNull() { var tracerMock = new Mock <Trace.ITracer>(); var shim = TracerShim.Create(tracerMock.Object); // Internals of the ScopeManagerShim tested elsewhere Assert.NotNull(shim.ScopeManager as ScopeManagerShim); }
public void Inject_Ok() { var shim = TracerShim.Create(tracer); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); var mockCarrier = new Mock <ITextMap>(); shim.Inject(spanContextShim, BuiltinFormats.TextMap, mockCarrier.Object); // Verify that the carrier mock was invoked at least one time. mockCarrier.Verify(x => x.Set(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce); }
public void Inject_ArgumentValidation() { var shim = TracerShim.Create(tracer); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); var mockFormat = new Mock <IFormat <ITextMap> >(); var mockCarrier = new Mock <ITextMap>(); Assert.Throws <ArgumentNullException>(() => shim.Inject(null, mockFormat.Object, mockCarrier.Object)); Assert.Throws <ArgumentException>(() => shim.Inject(new Mock <ISpanContext>().Object, mockFormat.Object, mockCarrier.Object)); Assert.Throws <ArgumentNullException>(() => shim.Inject(spanContextShim, null, mockCarrier.Object)); Assert.Throws <ArgumentNullException>(() => shim.Inject(spanContextShim, mockFormat.Object, null)); }
public void Extract_UnknownFormatIgnored() { var shim = TracerShim.Create(tracer); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); // Only two specific types of ITextMap are supported, and neither is a Mock. var mockCarrier = new Mock <ITextMap>(); var context = shim.Extract(new Mock <IFormat <ITextMap> >().Object, mockCarrier.Object); // Verify that the carrier mock was never called. mockCarrier.Verify(x => x.GetEnumerator(), Times.Never); }
public void Inject_UnknownFormatIgnored() { var shim = TracerShim.Create(NoopTracer.Instance); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); // Only two specific types of ITextMap are supported, and neither is a Mock. var mockCarrier = new Mock <ITextMap>(); shim.Inject(spanContextShim, new Mock <IFormat <ITextMap> >().Object, mockCarrier.Object); // Verify that the carrier mock was never called. mockCarrier.Verify(x => x.Set(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void Extract_InvalidTraceParent() { var shim = TracerShim.Create(tracer); var mockCarrier = new Mock <ITextMap>(); // The ProxyTracer uses OpenTelemetry.Context.Propagation.TraceContextFormat, so we need to satisfy the traceparent key at the least var carrierMap = new Dictionary <string, string> { // This is an invalid traceparent value { "traceparent", "unused" }, }; mockCarrier.Setup(x => x.GetEnumerator()).Returns(carrierMap.GetEnumerator()); var spanContextShim = shim.Extract(BuiltinFormats.TextMap, mockCarrier.Object) as SpanContextShim; // Verify that the carrier was called mockCarrier.Verify(x => x.GetEnumerator(), Times.Once); Assert.Null(spanContextShim); }
public void InjectExtract_Binary_Ok() { var tracerMock = new Mock <Trace.ITracer>(); var carrier = new BinaryCarrier(); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); var format = new BinaryFormat(); tracerMock.Setup(x => x.BinaryFormat).Returns(format); var shim = TracerShim.Create(tracerMock.Object); // first inject shim.Inject(spanContextShim, BuiltinFormats.Binary, carrier); // then extract var extractedSpanContext = shim.Extract(BuiltinFormats.Binary, carrier); AssertOpenTracerSpanContextEqual(spanContextShim, extractedSpanContext); }
public void Extract_Ok() { var shim = TracerShim.Create(tracer); var mockCarrier = new Mock <ITextMap>(); // The ProxyTracer uses OpenTelemetry.Context.Propagation.TraceContextFormat, so we need to satisfy that. var traceContextFormat = new TraceContextFormat(); var spanContext = Defaults.GetOpenTelemetrySpanContext(); var carrierMap = new Dictionary <string, string>(); // inject the SpanContext into the carrier map traceContextFormat.Inject <Dictionary <string, string> >(spanContext, carrierMap, (map, key, value) => map.Add(key, value)); // send the populated carrier map to the extract method. mockCarrier.Setup(x => x.GetEnumerator()).Returns(carrierMap.GetEnumerator()); var spanContextShim = shim.Extract(BuiltinFormats.TextMap, mockCarrier.Object) as SpanContextShim; // Verify that the carrier was called mockCarrier.Verify(x => x.GetEnumerator(), Times.Once); Assert.Equal(spanContext, spanContextShim.SpanContext); }
public void CtorArgumentValidation() { Assert.Throws <ArgumentNullException>(() => TracerShim.Create(null)); }