@@ -44,25 +44,33 @@ public VsDiscoveryVisitor(string source, ITestFrameworkDiscoverer discoverer, IM
4444
4545 public int TotalTests { get ; private set ; }
4646
47- public static TestCase CreateVsTestCase ( string source , ITestFrameworkDiscoverer discoverer , ITestCase xunitTestCase , bool forceUniqueNames )
47+ public static TestCase CreateVsTestCase ( string source , ITestFrameworkDiscoverer discoverer , ITestCase xunitTestCase , bool forceUniqueNames , IMessageLogger logger )
4848 {
49- var serializedTestCase = discoverer . Serialize ( xunitTestCase ) ;
50- var fqTestMethodName = String . Format ( "{0}.{1}" , xunitTestCase . TestMethod . TestClass . Class . Name , xunitTestCase . TestMethod . Method . Name ) ;
51- var uniqueName = forceUniqueNames ? String . Format ( "{0} ({1})" , fqTestMethodName , xunitTestCase . UniqueID ) : fqTestMethodName ;
49+ try
50+ {
51+ var serializedTestCase = discoverer . Serialize ( xunitTestCase ) ;
52+ var fqTestMethodName = String . Format ( "{0}.{1}" , xunitTestCase . TestMethod . TestClass . Class . Name , xunitTestCase . TestMethod . Method . Name ) ;
53+ var uniqueName = forceUniqueNames ? String . Format ( "{0} ({1})" , fqTestMethodName , xunitTestCase . UniqueID ) : fqTestMethodName ;
5254
53- var result = new TestCase ( uniqueName , uri , source ) { DisplayName = Escape ( xunitTestCase . DisplayName ) } ;
54- result . SetPropertyValue ( VsTestRunner . SerializedTestCaseProperty , serializedTestCase ) ;
55- result . Id = GuidFromString ( uri + xunitTestCase . UniqueID ) ;
55+ var result = new TestCase ( uniqueName , uri , source ) { DisplayName = Escape ( xunitTestCase . DisplayName ) } ;
56+ result . SetPropertyValue ( VsTestRunner . SerializedTestCaseProperty , serializedTestCase ) ;
57+ result . Id = GuidFromString ( uri + xunitTestCase . UniqueID ) ;
5658
57- if ( addTraitThunk != null )
58- foreach ( var key in xunitTestCase . Traits . Keys )
59- foreach ( var value in xunitTestCase . Traits [ key ] )
60- addTraitThunk ( result , key , value ) ;
59+ if ( addTraitThunk != null )
60+ foreach ( var key in xunitTestCase . Traits . Keys )
61+ foreach ( var value in xunitTestCase . Traits [ key ] )
62+ addTraitThunk ( result , key , value ) ;
6163
62- result . CodeFilePath = xunitTestCase . SourceInformation . FileName ;
63- result . LineNumber = xunitTestCase . SourceInformation . LineNumber . GetValueOrDefault ( ) ;
64+ result . CodeFilePath = xunitTestCase . SourceInformation . FileName ;
65+ result . LineNumber = xunitTestCase . SourceInformation . LineNumber . GetValueOrDefault ( ) ;
6466
65- return result ;
67+ return result ;
68+ }
69+ catch ( Exception ex )
70+ {
71+ logger . SendMessage ( TestMessageLevel . Error , String . Format ( "Error creating Visual Studio test case for {0}: {1}" , xunitTestCase . DisplayName , ex ) ) ;
72+ return null ;
73+ }
6674 }
6775
6876 static string Escape ( string value )
@@ -145,7 +153,11 @@ private void SendExistingTestCases()
145153 var forceUniqueNames = lastTestClassTestCases . Count > 1 ;
146154
147155 foreach ( var testCase in lastTestClassTestCases )
148- discoverySink . SendTestCase ( CreateVsTestCase ( source , discoverer , testCase , forceUniqueNames ) ) ;
156+ {
157+ var vsTestCase = CreateVsTestCase ( source , discoverer , testCase , forceUniqueNames , logger ) ;
158+ if ( vsTestCase != null )
159+ discoverySink . SendTestCase ( vsTestCase ) ;
160+ }
149161
150162 lastTestClassTestCases . Clear ( ) ;
151163 }
0 commit comments