コード例 #1
0
        private static Scope CreateScope(object testSdk)
        {
            if (!Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationName))
            {
                // integration disabled, don't create a scope, skip this trace
                return(null);
            }

            Scope scope = null;

            try
            {
                string testSuite  = null;
                string testName   = null;
                string skipReason = null;
                List <KeyValuePair <string, string> > testArguments = null;
                List <KeyValuePair <string, string> > testTraits    = null;

                // Get test type
                if (!testSdk.TryGetPropertyValue <Type>("TestClass", out Type testClassType))
                {
                    // if we don't have the test class type, we can't extract the info that we need.
                    Log.TestClassTypeNotFound();
                    return(null);
                }

                // Get test method
                if (!testSdk.TryGetPropertyValue <MethodInfo>("TestMethod", out MethodInfo testMethod))
                {
                    // if we don't have the test method info, we can't extract the info that we need.
                    Log.TestMethodNotFound();
                    return(null);
                }

                // Get test name
                testName = testMethod.Name;

                // Get skip reason
                testSdk.TryGetPropertyValue <string>("SkipReason", out skipReason);

                // Get traits
                if (testSdk.TryGetPropertyValue("TestCase", out object testCase))
                {
                    if (testCase.TryGetPropertyValue <Dictionary <string, List <string> > >("Traits", out Dictionary <string, List <string> > traits) && traits != null)
                    {
                        if (traits.Count > 0)
                        {
                            testTraits = new List <KeyValuePair <string, string> >();

                            foreach (KeyValuePair <string, List <string> > traitValue in traits)
                            {
                                testTraits.Add(new KeyValuePair <string, string>($"{TestTags.Traits}.{traitValue.Key}", string.Join(", ", traitValue.Value) ?? "(null)"));
                            }
                        }
                    }
                }

                AssemblyName testInvokerAssemblyName       = testSdk.GetType().Assembly.GetName();
                AssemblyName testClassInstanceAssemblyName = testClassType.Assembly?.GetName();

                testSuite = testClassType.ToString();

                // Get test parameters
                ParameterInfo[] methodParameters = testMethod.GetParameters();
                if (methodParameters?.Length > 0)
                {
                    if (testSdk.TryGetPropertyValue <object[]>("TestMethodArguments", out object[] testMethodArguments))