@@ -10,28 +10,22 @@ namespace CodeCracker.Test
10
10
{
11
11
public class RethrowExceptionTests : CodeFixVerifier
12
12
{
13
- private const string test = @"
14
- using System;
15
- using System.Collections.Generic;
16
- using System.Linq;
17
- using System.Text;
18
- using System.Threading.Tasks;
19
- using System.Diagnostics;
20
-
13
+ private const string sourceWithoutUsingSystem = @"
21
14
namespace ConsoleApplication1
22
15
{
23
16
class TypeName
24
17
{
25
18
public void Foo()
26
19
{
27
20
try { }
28
- catch (Exception ex)
21
+ catch (System. Exception ex)
29
22
{
30
23
throw ex;
31
24
}
32
25
}
33
26
}
34
27
}" ;
28
+ private const string sourceWithUsingSystem = "\n using System;" + sourceWithoutUsingSystem ;
35
29
36
30
[ Fact ]
37
31
public void WhenThrowingOriginalExceptionAnalyzerCreatesDiagnostic ( )
@@ -43,11 +37,11 @@ public void WhenThrowingOriginalExceptionAnalyzerCreatesDiagnostic()
43
37
Severity = DiagnosticSeverity . Error ,
44
38
Locations =
45
39
new [ ] {
46
- new DiagnosticResultLocation ( "Test0.cs" , 18 , 21 )
40
+ new DiagnosticResultLocation ( "Test0.cs" , 12 , 21 )
47
41
}
48
42
} ;
49
43
50
- VerifyCSharpDiagnostic ( test , expected ) ;
44
+ VerifyCSharpDiagnostic ( sourceWithUsingSystem , expected ) ;
51
45
}
52
46
53
47
[ Fact ]
@@ -56,56 +50,65 @@ public void WhenThrowingOriginalExceptionAndApplyingThrowNewExceptionFix()
56
50
57
51
var fixtest = @"
58
52
using System;
59
- using System.Collections.Generic;
60
- using System.Linq;
61
- using System.Text;
62
- using System.Threading.Tasks;
63
- using System.Diagnostics;
64
-
65
53
namespace ConsoleApplication1
66
54
{
67
55
class TypeName
68
56
{
69
57
public void Foo()
70
58
{
71
59
try { }
72
- catch (Exception ex)
60
+ catch (System. Exception ex)
73
61
{
74
62
throw new Exception(""some reason to rethrow"", ex);
75
63
}
76
64
}
77
65
}
78
66
}" ;
79
- VerifyCSharpFix ( test , fixtest , 0 ) ;
67
+ VerifyCSharpFix ( sourceWithUsingSystem , fixtest , 0 ) ;
80
68
}
81
69
82
70
[ Fact ]
83
71
public void WhenThrowingOriginalExceptionAndApplyingRethrowFix ( )
84
72
{
85
-
86
73
var fixtest = @"
87
74
using System;
88
- using System.Collections.Generic;
89
- using System.Linq;
90
- using System.Text;
91
- using System.Threading.Tasks;
92
- using System.Diagnostics;
93
-
94
75
namespace ConsoleApplication1
95
76
{
96
77
class TypeName
97
78
{
98
79
public void Foo()
99
80
{
100
81
try { }
101
- catch (Exception ex)
82
+ catch (System. Exception ex)
102
83
{
103
84
throw;
104
85
}
105
86
}
106
87
}
107
88
}" ;
108
- VerifyCSharpFix ( test , fixtest , 1 ) ;
89
+ VerifyCSharpFix ( sourceWithUsingSystem , fixtest , 1 ) ;
90
+ }
91
+
92
+ [ Fact ]
93
+ public void WhenThrowingOriginalExceptionAndApplyingThrowNewExceptionCompleteExceptionDeclationFix ( )
94
+ {
95
+
96
+ var fixtest = @"
97
+ namespace ConsoleApplication1
98
+ {
99
+ class TypeName
100
+ {
101
+ public void Foo()
102
+ {
103
+ try { }
104
+ catch (System.Exception ex)
105
+ {
106
+ throw new System.Exception(""some reason to rethrow"", ex);
107
+ }
108
+ }
109
+ }
110
+ }" ;
111
+ VerifyCSharpFix ( sourceWithoutUsingSystem , fixtest , 0 ) ;
109
112
}
110
113
111
114
0 commit comments