/// <inheritdoc/>
        public List <TestCaseDescriptor> GetTestCaseDescriptors(List <ITestCase> testCases, bool includeSerialization)
        {
            var results = new List <TestCaseDescriptor>(testCases.Count);

            foreach (var testCase in testCases)
            {
                var serialization = includeSerialization && discoverer != null?discoverer.Serialize(testCase) : null;

                var sourceInformation = testCase.SourceInformation;
                var testMethod        = testCase.TestMethod;

                try
                {
                    results.Add(new TestCaseDescriptor
                    {
                        ClassName        = testMethod.TestClass.Class.Name,
                        DisplayName      = testCase.DisplayName,
                        MethodName       = testMethod.Method.Name,
                        Serialization    = serialization,
                        SkipReason       = testCase.SkipReason,
                        SourceFileName   = sourceInformation?.FileName,
                        SourceLineNumber = sourceInformation?.LineNumber,
                        Traits           = testCase.Traits ?? new Dictionary <string, List <string> >(),
                        UniqueID         = testCase.UniqueID
                    });
                }
                catch (Exception) { }
            }

            return(results);
        }
    public DefaultTestCaseDescriptorProviderTests()
    {
        discoverer = Substitute.For <ITestFrameworkDiscoverer>();
        discoverer.Serialize(null).ReturnsForAnyArgs(callInfo => $"Serialization of test case ID '{callInfo.Arg<ITestCase>().UniqueID}'");

        provider = new DefaultTestCaseDescriptorProvider(discoverer);
    }
示例#3
0
        public static TestCase CreateVsTestCase(string source, ITestFrameworkDiscoverer discoverer, ITestCase xunitTestCase, XunitVisualStudioSettings settings, bool forceUniqueNames)
        {
            var serializedTestCase = discoverer.Serialize(xunitTestCase);
            var fqTestMethodName   = String.Format("{0}.{1}", xunitTestCase.Class.Name, xunitTestCase.Method.Name);
            var displayName        = settings.GetDisplayName(xunitTestCase.DisplayName, xunitTestCase.Method.Name, fqTestMethodName);
            var uniqueName         = forceUniqueNames ? String.Format("{0} ({1})", fqTestMethodName, xunitTestCase.UniqueID) : fqTestMethodName;

            var result = new TestCase(uniqueName, uri, source)
            {
                DisplayName = Escape(displayName)
            };

            result.SetPropertyValue(VsTestRunner.SerializedTestCaseProperty, serializedTestCase);

            if (addTraitThunk != null)
            {
                foreach (var key in xunitTestCase.Traits.Keys)
                {
                    foreach (var value in xunitTestCase.Traits[key])
                    {
                        addTraitThunk(result, key, value);
                    }
                }
            }

            result.CodeFilePath = xunitTestCase.SourceInformation.FileName;
            result.LineNumber   = xunitTestCase.SourceInformation.LineNumber.GetValueOrDefault();

            return(result);
        }
        public static TestCase CreateVsTestCase(string source, ITestFrameworkDiscoverer discoverer, ITestCase xunitTestCase, bool forceUniqueName, LoggerHelper logger, bool designMode)
        {
            try
            {
                var serializedTestCase = discoverer.Serialize(xunitTestCase);
                var fqTestMethodName   = $"{xunitTestCase.TestMethod.TestClass.Class.Name}.{xunitTestCase.TestMethod.Method.Name}";
                var result             = new TestCase(fqTestMethodName, uri, source)
                {
                    DisplayName = Escape(xunitTestCase.DisplayName)
                };
                result.SetPropertyValue(VsTestRunner.SerializedTestCaseProperty, serializedTestCase);
                result.Id = GuidFromString(uri + xunitTestCase.UniqueID);

                if (forceUniqueName)
                {
                    ForceUniqueName(result, xunitTestCase.UniqueID);
                }

                if (addTraitThunk != null)
                {
                    foreach (var key in xunitTestCase.Traits.Keys)
                    {
                        foreach (var value in xunitTestCase.Traits[key])
                        {
                            addTraitThunk(result, key, value);
                        }
                    }
                }

                if (designMode)
                {
                    // Source information is not required for non-design mode i.e. command line test runs.
                    // See RunSettingsHelper.DesignMode for more details.
                    result.CodeFilePath = xunitTestCase.SourceInformation.FileName;
                    result.LineNumber   = xunitTestCase.SourceInformation.LineNumber.GetValueOrDefault();
                }

                return(result);
            }
            catch (Exception ex)
            {
                logger.LogError(xunitTestCase, "Error creating Visual Studio test case for {0}: {1}", xunitTestCase.DisplayName, ex);
                return(null);
            }
        }
示例#5
0
        public static TestCase CreateVsTestCase(string source, ITestFrameworkDiscoverer discoverer, ITestCase xunitTestCase, bool forceUniqueNames, LoggerHelper logger, HashSet <string> knownTraitNames = null)
        {
            try
            {
                var serializedTestCase = discoverer.Serialize(xunitTestCase);
                var fqTestMethodName   = $"{xunitTestCase.TestMethod.TestClass.Class.Name}.{xunitTestCase.TestMethod.Method.Name}";
                var uniqueName         = forceUniqueNames ? $"{fqTestMethodName} ({xunitTestCase.UniqueID})" : fqTestMethodName;

                var result = new TestCase(uniqueName, uri, source)
                {
                    DisplayName = Escape(xunitTestCase.DisplayName)
                };
                result.SetPropertyValue(VsTestRunner.SerializedTestCaseProperty, serializedTestCase);
                result.Id = GuidFromString(uri + xunitTestCase.UniqueID);

                if (addTraitThunk != null)
                {
                    foreach (var key in xunitTestCase.Traits.Keys)
                    {
                        if (knownTraitNames != null)
                        {
                            knownTraitNames.Add(key);
                        }

                        foreach (var value in xunitTestCase.Traits[key])
                        {
                            addTraitThunk(result, key, value);
                        }
                    }
                }

                result.CodeFilePath = xunitTestCase.SourceInformation.FileName;
                result.LineNumber   = xunitTestCase.SourceInformation.LineNumber.GetValueOrDefault();

                return(result);
            }
            catch (Exception ex)
            {
                logger.LogError(xunitTestCase, "Error creating Visual Studio test case for {0}: {1}", xunitTestCase.DisplayName, ex);
                return(null);
            }
        }
示例#6
0
            protected override bool Visit(ITestCaseDiscoveryMessage testCaseDiscovered)
            {
                var testCase = testCaseDiscovered.TestCase;

                TestCases.Add(new TestCaseViewModel(discoverer.Serialize(testCase), testCase.DisplayName, testCaseDiscovered.TestAssembly.Assembly.AssemblyPath));

                foreach (var k in testCase.Traits.Keys)
                {
                    IList <string> value;
                    if (!Traits.TryGetValue(k, out value))
                    {
                        value     = new List <string>();
                        Traits[k] = value;
                    }

                    value.AddRange(testCase.Traits[k]);
                }

                return(true);
            }
        public static TestCase CreateVsTestCase(string source, ITestFrameworkDiscoverer discoverer, ITestCase xunitTestCase, bool forceUniqueNames, IMessageLogger logger, bool logDiscovery)
        {
            try
            {
                var serializedTestCase = discoverer.Serialize(xunitTestCase);
                var fqTestMethodName   = String.Format("{0}.{1}", xunitTestCase.TestMethod.TestClass.Class.Name, xunitTestCase.TestMethod.Method.Name);
                var uniqueName         = forceUniqueNames ? String.Format("{0} ({1})", fqTestMethodName, xunitTestCase.UniqueID) : fqTestMethodName;

                var result = new TestCase(uniqueName, uri, source)
                {
                    DisplayName = Escape(xunitTestCase.DisplayName)
                };
                result.SetPropertyValue(VsTestRunner.SerializedTestCaseProperty, serializedTestCase);
                result.Id = GuidFromString(uri + xunitTestCase.UniqueID);

                if (addTraitThunk != null)
                {
                    foreach (var key in xunitTestCase.Traits.Keys)
                    {
                        foreach (var value in xunitTestCase.Traits[key])
                        {
                            addTraitThunk(result, key, value);
                        }
                    }
                }

                result.CodeFilePath = xunitTestCase.SourceInformation.FileName;
                result.LineNumber   = xunitTestCase.SourceInformation.LineNumber.GetValueOrDefault();

                return(result);
            }
            catch (Exception ex)
            {
                logger.SendMessage(TestMessageLevel.Error, String.Format("Error creating Visual Studio test case for {0}: {1}", xunitTestCase.DisplayName, ex));
                return(null);
            }
        }
 public MockDiscovery()
 {
     discoverer = Substitute.For <ITestFrameworkDiscoverer>();
     discoverer.Serialize(null).ReturnsForAnyArgs(callInfo => $"Serialization of test case ID '{callInfo.Arg<ITestCase>().UniqueID}'");
 }
示例#9
0
 /// <inheritdoc/>
 public string Serialize(ITestCase testCase)
 => discoverer.Serialize(testCase);
示例#10
0
 /// <inheritdoc/>
 public string Serialize(ITestCase testCase)
 {
     return(discoverer.Serialize(testCase));
 }
示例#11
0
        public static TestCase CreateVsTestCase(string source,
                                                ITestFrameworkDiscoverer discoverer,
                                                ITestCase xunitTestCase,
                                                bool forceUniqueName,
                                                LoggerHelper logger,
                                                TestPlatformContext testPlatformContext,
                                                string testClassName  = null,
                                                string testMethodName = null,
                                                string uniqueID       = null)
        {
            try
            {
                if (string.IsNullOrEmpty(testClassName))
                {
                    testClassName = xunitTestCase.TestMethod.TestClass.Class.Name;
                }

                if (string.IsNullOrEmpty(testMethodName))
                {
                    testMethodName = xunitTestCase.TestMethod.Method.Name;
                }

                if (string.IsNullOrEmpty(uniqueID))
                {
                    uniqueID = xunitTestCase.UniqueID;
                }

                var fqTestMethodName = $"{testClassName}.{testMethodName}";
                var result           = new TestCase(fqTestMethodName, uri, source)
                {
                    DisplayName = Escape(xunitTestCase.DisplayName)
                };

                if (testPlatformContext.RequireXunitTestProperty)
                {
                    result.SetPropertyValue(VsTestRunner.SerializedTestCaseProperty, discoverer.Serialize(xunitTestCase));
                }

                result.Id = GuidFromString(uri + uniqueID);

                if (forceUniqueName)
                {
                    ForceUniqueName(result, uniqueID);
                }

                if (addTraitThunk != null)
                {
                    var traits = xunitTestCase.Traits;

                    foreach (var key in traits.Keys)
                    {
                        foreach (var value in traits[key])
                        {
                            addTraitThunk(result, key, value);
                        }
                    }
                }

                if (testPlatformContext.RequireSourceInformation)
                {
                    result.CodeFilePath = xunitTestCase.SourceInformation.FileName;
                    result.LineNumber   = xunitTestCase.SourceInformation.LineNumber.GetValueOrDefault();
                }

                return(result);
            }
            catch (Exception ex)
            {
                logger.LogError(xunitTestCase, "Error creating Visual Studio test case for {0}: {1}", xunitTestCase.DisplayName, ex);
                return(null);
            }
        }