Skip to content

Commit 2f0d948

Browse files
committed
Enhance some fix all tests, code-cracker#352
1 parent 5c0d274 commit 2f0d948

File tree

5 files changed

+137
-91
lines changed

5 files changed

+137
-91
lines changed

test/CSharp/CodeCracker.Test/Design/StaticConstructorExceptionTests.cs

+69-56
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public class StaticConstructorExceptionTests : CodeFixVerifier<StaticConstructor
1111
public async Task WarningIfExceptionIsThrowInsideStaticConstructor()
1212
{
1313
const string test = @"
14-
public class MyClass
15-
{
16-
static MyClass()
17-
{
18-
throw new System.Exception(""error message"");
19-
}
14+
public class MyClass
15+
{
16+
static MyClass()
17+
{
18+
throw new System.Exception(""error message"");
19+
}
2020
}";
2121

2222
var expected = new DiagnosticResult
@@ -34,12 +34,12 @@ static MyClass()
3434
public async Task NotWarningWhenNoExceptionIsThrowInsideStaticConstructor()
3535
{
3636
const string test = @"
37-
public class MyClass
38-
{
39-
public MyClass()
40-
{
41-
throw new System.Exception(""error message"");
42-
}
37+
public class MyClass
38+
{
39+
public MyClass()
40+
{
41+
throw new System.Exception(""error message"");
42+
}
4343
}";
4444

4545
await VerifyCSharpHasNoDiagnosticsAsync(test);
@@ -49,12 +49,12 @@ public MyClass()
4949
public async Task StaticConstructorWithoutException()
5050
{
5151
const string test = @"
52-
public class MyClass
53-
{
54-
static MyClass()
55-
{
52+
public class MyClass
53+
{
54+
static MyClass()
55+
{
5656
57-
}
57+
}
5858
}";
5959

6060
await VerifyCSharpHasNoDiagnosticsAsync(test);
@@ -64,12 +64,12 @@ static MyClass()
6464
public async Task InstanceConstructorWithoutException()
6565
{
6666
const string test = @"
67-
public class MyClass
68-
{
69-
public MyClass()
70-
{
71-
72-
}
67+
public class MyClass
68+
{
69+
public MyClass()
70+
{
71+
72+
}
7373
}";
7474

7575
await VerifyCSharpHasNoDiagnosticsAsync(test);
@@ -79,20 +79,20 @@ public MyClass()
7979
public async Task WhenThrowIsRemovedFromStaticConstructor()
8080
{
8181
const string source = @"
82-
public class MyClass
83-
{
84-
static MyClass()
85-
{
86-
throw new System.Exception(""error message"");
87-
}
82+
public class MyClass
83+
{
84+
static MyClass()
85+
{
86+
throw new System.Exception(""error message"");
87+
}
8888
}";
8989

9090
const string fixtest = @"
91-
public class MyClass
92-
{
93-
static MyClass()
94-
{
95-
}
91+
public class MyClass
92+
{
93+
static MyClass()
94+
{
95+
}
9696
}";
9797

9898
await VerifyCSharpFixAsync(source, fixtest, 0);
@@ -102,35 +102,48 @@ static MyClass()
102102
public async Task WhenThrowIsRemovedFromAllStaticConstructors()
103103
{
104104
const string source1 = @"
105-
public class MyClass1
106-
{
107-
static MyClass1()
108-
{
109-
throw new System.Exception(""error message"");
110-
}
105+
public class MyClass1
106+
{
107+
static MyClass1()
108+
{
109+
throw new System.Exception(""error message"");
110+
}
111+
}
112+
public class MyClass3
113+
{
114+
static MyClass3()
115+
{
116+
throw new System.Exception(""error message"");
117+
}
111118
}";
112119
const string fixtest1 = @"
113-
public class MyClass1
114-
{
115-
static MyClass1()
116-
{
117-
}
120+
public class MyClass1
121+
{
122+
static MyClass1()
123+
{
124+
}
125+
}
126+
public class MyClass3
127+
{
128+
static MyClass3()
129+
{
130+
}
118131
}";
119132

120133
const string source2 = @"
121-
public class MyClass2
122-
{
123-
static MyClass2()
124-
{
125-
throw new System.Exception(""error message"");
126-
}
134+
public class MyClass2
135+
{
136+
static MyClass2()
137+
{
138+
throw new System.Exception(""error message"");
139+
}
127140
}";
128141
const string fixtest2 = @"
129-
public class MyClass2
130-
{
131-
static MyClass2()
132-
{
133-
}
142+
public class MyClass2
143+
{
144+
static MyClass2()
145+
{
146+
}
134147
}";
135148

136149
await VerifyCSharpFixAllAsync(new string[] { source1, source2 }, new string[] { fixtest1, fixtest2 });

test/CSharp/CodeCracker.Test/Performance/SealedAttributeTests.cs

+32-26
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class SealedAttributeTests : CodeFixVerifier<SealedAttributeAnalyzer, Sea
1111
public async Task ApplySealedWhenClassInheritsFromSystemAttributeClass()
1212
{
1313
const string test = @"
14-
public class MyAttribute : System.Attribute
15-
{
14+
public class MyAttribute : System.Attribute
15+
{
1616
1717
}";
1818

@@ -31,13 +31,13 @@ public class MyAttribute : System.Attribute
3131
public async Task ApplySealedWhenClassInheritsIndirectlyFromSystemAttributeClass()
3232
{
3333
const string test = @"
34-
public abstract class MyAttribute : System.Attribute
35-
{
34+
public abstract class MyAttribute : System.Attribute
35+
{
3636
3737
}
3838
39-
public class OtherAttribute : MyAttribute
40-
{
39+
public class OtherAttribute : MyAttribute
40+
{
4141
4242
}";
4343

@@ -56,8 +56,8 @@ public class OtherAttribute : MyAttribute
5656
public async Task NotApplySealedWhenClassThatInheritsFromSystemAttributeClassIsAbstract()
5757
{
5858
const string test = @"
59-
public abstract class MyAttribute : System.Attribute
60-
{
59+
public abstract class MyAttribute : System.Attribute
60+
{
6161
6262
}";
6363

@@ -68,8 +68,8 @@ public abstract class MyAttribute : System.Attribute
6868
public async Task NotApplySealedWhenClassThatInheritsFromSystemAttributeClassIsSealed()
6969
{
7070
const string test = @"
71-
public sealed class MyAttribute : System.Attribute
72-
{
71+
public sealed class MyAttribute : System.Attribute
72+
{
7373
7474
}";
7575

@@ -80,8 +80,8 @@ public sealed class MyAttribute : System.Attribute
8080
public async Task NotApplySealedWhenIsStruct()
8181
{
8282
const string test = @"
83-
public struct MyStruct
84-
{
83+
public struct MyStruct
84+
{
8585
8686
}";
8787

@@ -92,8 +92,8 @@ public struct MyStruct
9292
public async Task NotApplySealedWhenIsInterface()
9393
{
9494
const string test = @"
95-
public interface ITest
96-
{
95+
public interface ITest
96+
{
9797
9898
}";
9999

@@ -104,13 +104,13 @@ public interface ITest
104104
public async Task WhenSealedModifierIsAppliedOnClass()
105105
{
106106
const string source = @"
107-
public class MyAttribute : System.Attribute
108-
{
107+
public class MyAttribute : System.Attribute
108+
{
109109
}";
110110

111111
const string fixtest = @"
112-
public sealed class MyAttribute : System.Attribute
113-
{
112+
public sealed class MyAttribute : System.Attribute
113+
{
114114
}";
115115

116116
await VerifyCSharpFixAsync(source, fixtest, 0);
@@ -120,21 +120,27 @@ public sealed class MyAttribute : System.Attribute
120120
public async Task WhenSealedModifierIsAppliedOnClassFixAll()
121121
{
122122
const string source1 = @"
123-
public class MyAttribute1 : System.Attribute
124-
{
123+
public class MyAttribute1 : System.Attribute
124+
{
125+
}
126+
public class MyAttribute3 : System.Attribute
127+
{
125128
}";
126129
const string fixtest1 = @"
127-
public sealed class MyAttribute1 : System.Attribute
128-
{
130+
public sealed class MyAttribute1 : System.Attribute
131+
{
132+
}
133+
public sealed class MyAttribute3 : System.Attribute
134+
{
129135
}";
130136

131137
const string source2 = @"
132-
public class MyAttribute2 : System.Attribute
133-
{
138+
public class MyAttribute2 : System.Attribute
139+
{
134140
}";
135141
const string fixtest2 = @"
136-
public sealed class MyAttribute2 : System.Attribute
137-
{
142+
public sealed class MyAttribute2 : System.Attribute
143+
{
138144
}";
139145

140146
await VerifyCSharpFixAllAsync(new string[] { source1, source2 }, new string[] { fixtest1, fixtest2 });

test/CSharp/CodeCracker.Test/Reliability/UseConfigureAwaitFalseTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public async Task FixAddsConfigureAwaitFalse(string original, string result)
7676
"System.Threading.Tasks.Task t; await t;",
7777
"System.Threading.Tasks.Task t; await t.ConfigureAwait(false);")]
7878
[InlineData(
79-
"System.Threading.Tasks.Task t; await t.ContinueWith(_ => 42);",
80-
"System.Threading.Tasks.Task t; await t.ContinueWith(_ => 42).ConfigureAwait(false);")]
79+
"System.Threading.Tasks.Task t; await t.ContinueWith(_ => 42); await t.ContinueWith(_ => 42);",
80+
"System.Threading.Tasks.Task t; await t.ContinueWith(_ => 42).ConfigureAwait(false); await t.ContinueWith(_ => 42).ConfigureAwait(false);")]
8181
[InlineData(
8282
"await System.Threading.Tasks.Task.Delay(1000);",
8383
"await System.Threading.Tasks.Task.Delay(1000).ConfigureAwait(false);")]
8484
[InlineData(
85-
"await System.Threading.Tasks.Task.FromResult(0);",
86-
"await System.Threading.Tasks.Task.FromResult(0).ConfigureAwait(false);")]
85+
"await System.Threading.Tasks.Task.FromResult(0);await System.Threading.Tasks.Task.FromResult(0);",
86+
"await System.Threading.Tasks.Task.FromResult(0).ConfigureAwait(false);await System.Threading.Tasks.Task.FromResult(0).ConfigureAwait(false);")]
8787
[InlineData(
8888
"await System.Threading.Tasks.Task.Run(() => {});",
8989
"await System.Threading.Tasks.Task.Run(() => {}).ConfigureAwait(false);")]

test/CSharp/CodeCracker.Test/Style/InterfaceNameTests.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ public interface IFoo2
146146
public async Task ChangeAllInterfaceNamesWithoutIAndClassImplementation()
147147
{
148148
const string source1 = @"
149+
using ConsoleApplication2;
149150
namespace ConsoleApplication1
150151
{
151-
public interface Foo1
152+
public interface Foo2
152153
{
153154
void Test();
154155
}
@@ -162,9 +163,10 @@ public void Test()
162163
}
163164
}";
164165
const string source2 = @"
166+
using ConsoleApplication1;
165167
namespace ConsoleApplication2
166168
{
167-
public interface Foo2
169+
public interface Foo1
168170
{
169171
void Test();
170172
}
@@ -178,9 +180,10 @@ public void Test()
178180
}
179181
}";
180182
const string fixtest1 = @"
183+
using ConsoleApplication2;
181184
namespace ConsoleApplication1
182185
{
183-
public interface IFoo1
186+
public interface IFoo2
184187
{
185188
void Test();
186189
}
@@ -194,9 +197,10 @@ public void Test()
194197
}
195198
}";
196199
const string fixtest2 = @"
200+
using ConsoleApplication1;
197201
namespace ConsoleApplication2
198202
{
199-
public interface IFoo2
203+
public interface IFoo1
200204
{
201205
void Test();
202206
}
@@ -209,7 +213,7 @@ public void Test()
209213
}
210214
}
211215
}";
212-
await VerifyCSharpFixAllAsync(new string[] { source1, source2 }, new string[]{ fixtest1, fixtest2 });
216+
await VerifyCSharpFixAllAsync(new string[] { source1, source2 }, new string[] { fixtest1, fixtest2 });
213217
}
214218
}
215219
}

0 commit comments

Comments
 (0)