public void DefaultBasicTracer_WhenExtractValidSpanToMemoryCarrier_Works()
        {
            var spanContextFactory = new OpenTracingSpanContextFactory();
            var traceBuilder       = new TracerBuilder <OpenTracingSpanContext>();

            traceBuilder.SetSpanContextFactory(spanContextFactory);
            var tracer = traceBuilder.BuildTracer();

            var testTraceId = 1234;
            var testSpanId  = 9876;

            var data = new Dictionary <string, string>()
            {
                { "ot-tracer-traceid", testTraceId.ToString() },
                { "ot-tracer-spanid", testSpanId.ToString() },
            };

            var memoryCarrier = new MemoryTextMapCarrier(data);

            var extractResult = tracer.Extract("TestOperation", memoryCarrier);

            Assert.IsTrue(extractResult.Success);
            Assert.IsTrue(extractResult.SpanContext is OpenTracingSpanContext);

            Assert.AreEqual(testTraceId.ToString(), memoryCarrier.TextMap["ot-tracer-traceid"]);
            Assert.AreEqual(testSpanId.ToString(), memoryCarrier.TextMap["ot-tracer-spanid"]);
        }
        public void DefaultBasicTracer_WhenExtractBadSpanToMemoryCarrier_Fails()
        {
            var spanContextFactory = new OpenTracingSpanContextFactory();
            var traceBuilder       = new TracerBuilder <OpenTracingSpanContext>();

            traceBuilder.SetSpanContextFactory(spanContextFactory);
            var tracer = traceBuilder.BuildTracer();

            var memoryCarrier = new MemoryTextMapCarrier(new Dictionary <string, string>()
            {
            });

            var extractResult = tracer.Extract("TestOperation", memoryCarrier);

            Assert.IsFalse(extractResult.Success);
        }
        public void DefaultBasicTracer_WhenSpanInjectedToMemoryCarrier_Work()
        {
            var spanContextFactory = new OpenTracingSpanContextFactory();
            var traceBuilder       = new TracerBuilder <OpenTracingSpanContext>();

            traceBuilder.SetSpanContextFactory(spanContextFactory);
            var tracer = traceBuilder.BuildTracer();

            var span = tracer.BuildSpan("TestOperation").Start();

            var memoryCarrier = new MemoryTextMapCarrier();

            tracer.Inject(span.GetSpanContext(), memoryCarrier);

            Assert.IsTrue(memoryCarrier.TextMap.ContainsKey("ot-tracer-traceid"));
            Assert.IsTrue(memoryCarrier.TextMap.ContainsKey("ot-tracer-spanid"));

            Assert.IsTrue(ulong.Parse(memoryCarrier.TextMap["ot-tracer-traceid"]) != 0);
            Assert.IsTrue(ulong.Parse(memoryCarrier.TextMap["ot-tracer-spanid"]) != 0);
        }