Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit 5d31162

Browse files
committed
Add inheritance tests
1 parent 4a3cba2 commit 5d31162

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/Usage/IncludeCancellationParameterUnitTests.cs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,126 @@ struct CancellationToken
284284
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
285285
}
286286

287+
[Fact]
288+
public async Task TestInheritedMethodAsync()
289+
{
290+
string testCode = @"
291+
using System.Threading.Tasks;
292+
class BaseName
293+
{
294+
protected virtual Task MethodAsync() { return Task.FromResult(0); }
295+
}
296+
class ClassName : BaseName
297+
{
298+
protected override Task MethodAsync() { return Task.FromResult(0); }
299+
}
300+
";
301+
302+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(5, 28);
303+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
304+
}
305+
306+
[Fact]
307+
public async Task TestExplicitInterfaceMethodAsync()
308+
{
309+
string testCode = @"
310+
using System.Threading.Tasks;
311+
interface InterfaceName
312+
{
313+
Task MethodAsync();
314+
}
315+
class ClassName : InterfaceName
316+
{
317+
Task InterfaceName.MethodAsync() { return Task.FromResult(0); }
318+
}
319+
";
320+
321+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(5, 10);
322+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
323+
}
324+
325+
[Fact]
326+
public async Task TestExplicitInterfaceMethodPlusExtraAsync()
327+
{
328+
string testCode = @"
329+
using System.Threading.Tasks;
330+
interface InterfaceName
331+
{
332+
Task MethodAsync();
333+
}
334+
class ClassName : InterfaceName
335+
{
336+
public Task MethodAsync() { return Task.FromResult(0); }
337+
Task InterfaceName.MethodAsync() { return Task.FromResult(0); }
338+
}
339+
";
340+
341+
DiagnosticResult[] expected =
342+
{
343+
this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(5, 10),
344+
this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(9, 17)
345+
};
346+
347+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
348+
}
349+
350+
[Fact]
351+
public async Task TestImplicitInterfaceMethodAsync()
352+
{
353+
string testCode = @"
354+
using System.Threading.Tasks;
355+
interface InterfaceName
356+
{
357+
Task MethodAsync();
358+
}
359+
class ClassName : InterfaceName
360+
{
361+
public Task MethodAsync() { return Task.FromResult(0); }
362+
}
363+
";
364+
365+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(5, 10);
366+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
367+
}
368+
369+
[Fact]
370+
public async Task TestImplicitGenericInterfaceMethodAsync()
371+
{
372+
string testCode = @"
373+
using System.Threading.Tasks;
374+
interface InterfaceName<T>
375+
{
376+
Task MethodAsync(T value);
377+
}
378+
class ClassName : InterfaceName<int>
379+
{
380+
public Task MethodAsync(int value) { return Task.FromResult(0); }
381+
}
382+
";
383+
384+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(5, 10);
385+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
386+
}
387+
388+
[Fact]
389+
public async Task TestImplicitInterfaceGenericMethodAsync()
390+
{
391+
string testCode = @"
392+
using System.Threading.Tasks;
393+
interface InterfaceName
394+
{
395+
Task MethodAsync<T>(T value);
396+
}
397+
class ClassName : InterfaceName
398+
{
399+
public Task MethodAsync<T>(T value) { return Task.FromResult(0); }
400+
}
401+
";
402+
403+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("MethodAsync").WithLocation(5, 10);
404+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
405+
}
406+
287407
[Theory]
288408
[MemberData(nameof(AsynchronousUnitTestWithReturnValue))]
289409
public async Task TestAsynchronousUnitTestMethodAsync(string declaration, string testAttribute)

0 commit comments

Comments
 (0)