public static VsTestCase CreateVsTestCase(string source, TestCaseDescriptor descriptor) { try { var fqTestMethodName = $"{descriptor.ClassName}.{descriptor.MethodName}"; var result = new VsTestCase(fqTestMethodName, uri, source) { DisplayName = Escape(descriptor.DisplayName) }; result.Id = GuidFromString(uri + descriptor.UniqueID); result.CodeFilePath = descriptor.SourceFileName; result.LineNumber = descriptor.SourceLineNumber.GetValueOrDefault(); //if (addTraitThunk != null) //{ // var traits = descriptor.Traits; // foreach (var key in traits.Keys) // foreach (var value in traits[key]) // addTraitThunk(result, key, value); //} return(result); } #pragma warning disable CA1031, IDE0059, CS0168 // Do not catch general exception types, Unnecessary assignment of a value, Variable is declared but never used catch (Exception ex) #pragma warning restore CA1031, IDE0059, CS0168 // Do not catch general exception types, Unnecessary assignment of a value, Variable is declared but never used { //logger.LogErrorWithSource(source, "Error creating Visual Studio test case for {0}: {1}", descriptor.DisplayName, ex); return(null); } }
public DiscoveredTestCase(string source, TestCaseDescriptor descriptor, ITestCase testCase, LoggerHelper logger, TestPlatformContext testPlatformContext) { Name = $"{descriptor.ClassName}.{descriptor.MethodName} ({descriptor.UniqueID})"; TestCase = testCase; UniqueID = descriptor.UniqueID; VSTestCase = VsDiscoverySink.CreateVsTestCase(source, descriptor, logger, testPlatformContext); TraitNames = descriptor.Traits.Keys; }
public DiscoveredTestCase(string source, TestCaseDescriptor descriptor, ITestCase testCase /*, LoggerHelper logger, TestPlatformContext testPlatformContext*/) { Name = $"{descriptor.ClassName}.{descriptor.MethodName} ({descriptor.UniqueID})"; ClassName = descriptor.ClassName; MethodName = descriptor.MethodName; TestCase = testCase; UniqueID = descriptor.UniqueID; VSTestCase = Xunit2TestAssemblyRunner.CreateVsTestCase(source, descriptor /*, logger, testPlatformContext*/); TraitNames = descriptor.Traits.Keys; }
public static TestCase CreateVsTestCase(string source, TestCaseDescriptor descriptor, LoggerHelper logger, TestPlatformContext testPlatformContext) { try { var fqTestMethodName = $"{descriptor.ClassName}.{descriptor.MethodName} ({descriptor.UniqueID})"; var result = new TestCase(fqTestMethodName, uri, source) { DisplayName = Escape(descriptor.DisplayName) }; if (testPlatformContext.RequireXunitTestProperty) { result.SetPropertyValue(VsTestRunner.SerializedTestCaseProperty, descriptor.Serialization); } result.Id = GuidFromString(uri + descriptor.UniqueID); if (addTraitThunk != null) { var traits = descriptor.Traits; foreach (var key in traits.Keys) { foreach (var value in traits[key]) { addTraitThunk(result, key, value); } } } if (testPlatformContext.RequireSourceInformation) { result.CodeFilePath = descriptor.SourceFileName; result.LineNumber = descriptor.SourceLineNumber.GetValueOrDefault(); } return(result); } catch (Exception ex) { logger.LogErrorWithSource(source, "Error creating Visual Studio test case for {0}: {1}", descriptor.DisplayName, ex); return(null); } }
public TestCaseWrapper(TestCaseDescriptor testCase) { this.Descriptor = testCase; var type = Assembly.Load(testCase.Assembly).GetType(testCase.Type, true); MethodInfo method = null; if (testCase.Method != null) { method = type.GetMethod(testCase.Method, BindingFlags.Public | BindingFlags.Instance); if (method == null) { throw new InvalidOperationException($"Unable to find method '{testCase.Method}' on {type}"); } } TestMethodDependencyAttribute attribute = method.GetCustomAttribute <TestMethodDependencyAttribute>(); if (attribute != null) { this.Dependency = new TestCaseDescriptor(attribute.MethodDependency, type); } }
public int GetOrder(Test test) { TestCaseDescriptor testCaseDescriptor = new TestCaseDescriptor(test.Method.Name, test.Method.TypeInfo.Type); return(this._testCaseDescriptors.FindIndex(x => x.Descriptor == testCaseDescriptor)); }