Exemple #1
0
        public void TestGetRpcTraceContext_WithExpectedValues(string traceparent, string tracestate, IEnumerable <KeyValuePair <string, string> > attributes)
        {
            IEnumerable <KeyValuePair <string, string> > expectedAttributes = null;

            if (!string.IsNullOrEmpty(traceparent))
            {
                attributes = new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("key1", "value1"), new KeyValuePair <string, string>("key1", "value2")
                };
                expectedAttributes = new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("key1", "value2")
                };
            }

            RpcTraceContext traceContext = ScriptInvocationContextExtensions.GetRpcTraceContext(traceparent, tracestate, attributes, NullLogger.Instance);

            Assert.Equal(traceparent ?? string.Empty, traceContext.TraceParent);
            Assert.Equal(tracestate ?? string.Empty, traceContext.TraceState);

            if (attributes != null)
            {
                Assert.True(expectedAttributes.SequenceEqual(traceContext.Attributes));
            }
            else
            {
                Assert.Equal(0, traceContext.Attributes.Count);
            }
        }
        public void TestSetRetryContext_Retry()
        {
            ScriptInvocationContext context = new ScriptInvocationContext()
            {
                ExecutionContext = new ExecutionContext()
                {
                    RetryContext = new Host.RetryContext()
                    {
                        RetryCount    = 1,
                        MaxRetryCount = 2,
                        Exception     = new Exception("test")
                    }
                }
            };
            HttpScriptInvocationContext testContext = new HttpScriptInvocationContext()
            {
                Data     = new Dictionary <string, object>(),
                Metadata = new Dictionary <string, object>()
            };

            ScriptInvocationContextExtensions.SetRetryContext(context, testContext);
            var retryContext = (RetryContext)testContext.Metadata["RetryContext"];

            Assert.NotNull(retryContext);
            Assert.Equal(retryContext.RetryCount, context.ExecutionContext.RetryContext.RetryCount);
            Assert.Equal(retryContext.MaxRetryCount, context.ExecutionContext.RetryContext.MaxRetryCount);
            Assert.NotNull(retryContext.Exception);
        }
Exemple #3
0
        public void GetHttpScriptInvocationContextValueTest_String()
        {
            string inputValue = "stringTest";
            object result     = ScriptInvocationContextExtensions.GetHttpScriptInvocationContextValue(inputValue);

            Assert.Equal($"\"{inputValue}\"", result);
        }
Exemple #4
0
        public void GetHttpScriptInvocationContextValueTest_POCO()
        {
            TestPoco inputValue = new TestPoco()
            {
                Name = "TestName",
                Id   = 1234
            };
            object result          = ScriptInvocationContextExtensions.GetHttpScriptInvocationContextValue(inputValue);
            var    resultAsJObject = (JObject)result;

            Assert.Equal("TestName", resultAsJObject["Name"]);
            Assert.Equal(1234, resultAsJObject["Id"]);
        }
        public void TestSetRetryContext_NoRetry()
        {
            ScriptInvocationContext scriptInvocationContext = new ScriptInvocationContext()
            {
                ExecutionContext = new ExecutionContext()
            };

            HttpScriptInvocationContext testContext = new HttpScriptInvocationContext()
            {
                Data     = new Dictionary <string, object>(),
                Metadata = new Dictionary <string, object>()
            };

            ScriptInvocationContextExtensions.SetRetryContext(scriptInvocationContext, testContext);

            Assert.Empty(testContext.Metadata);
        }