Skip to content

Commit

Permalink
GH-186 - ConflictingArgumentAssignmentAnalyzer support for ThrowsAsyn…
Browse files Browse the repository at this point in the history
…c like methods
  • Loading branch information
tpodolak committed Jul 22, 2022
1 parent 4d9a706 commit f7fcddc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@

namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.ConflictingArgumentAssignmentsAnalyzerTests;

[CombinatoryData("Throws", "ThrowsForAnyArgs")]
[CombinatoryData("Throws", "ThrowsAsync", "ThrowsForAnyArgs", "ThrowsAsyncForAnyArgs")]
public class ThrowsAsExtensionMethodTests : ConflictingArgumentAssignmentsDiagnosticVerifier
{
public override async Task ReportsDiagnostic_When_AndDoesMethod_SetsSameArgument_AsPreviousSetupMethod(string method, string call, string previousCallArgAccess, string andDoesArgAccess)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
int Barr {{ get; }}
Task<int> Barr {{ get; }}
int this[int x] {{ get; }}
Task<int> this[int x] {{ get; }}
}}
public class FooTests
Expand All @@ -46,14 +47,15 @@ public void Test()
public override async Task ReportsNoDiagnostics_WhenSubstituteMethodCannotBeInferred(string method)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
}}
public class FooTests
Expand All @@ -80,6 +82,7 @@ public void Test()
public override async Task ReportsNoDiagnostics_WhenUsedWithUnfortunatelyNamedMethod(string method)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.Core;
using NSubstitute.ExceptionExtensions;
Expand All @@ -88,7 +91,7 @@ namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
}}
public class FooTests
Expand Down Expand Up @@ -121,18 +124,19 @@ public static void AndDoes(this ConfiguredCall call, Action<CallInfo> firstCall,
public override async Task ReportsNoDiagnostics_When_AndDoesMethod_SetsDifferentArgument_AsPreviousSetupMethod(string method, string call, string andDoesArgAccess)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
int Barr {{ get; }}
Task<int> Barr {{ get; }}
int this[int x] {{ get; }}
Task<int> this[int x] {{ get; }}
}}
public class FooTests
Expand All @@ -158,18 +162,19 @@ public void Test()
public override async Task ReportsNoDiagnostics_When_AndDoesMethod_AccessSameArguments_AsPreviousSetupMethod(string method, string call, string argAccess)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
int Barr {{ get; }}
Task<int> Barr {{ get; }}
int this[int x] {{ get; }}
Task<int> this[int x] {{ get; }}
}}
public class FooTests
Expand All @@ -195,14 +200,15 @@ public void Test()
public override async Task ReportsNoDiagnostics_When_AndDoesMethod_SetSameArguments_AsPreviousSetupMethod_SetsIndirectly(string method)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
}}
public class FooTests
Expand Down Expand Up @@ -230,18 +236,19 @@ public void Test()
public override async Task ReportsNoDiagnostic_When_AndDoesMethod_SetArgument_AndPreviousMethod_IsNotUsedWithCallInfo(string method, string call, string andDoesArgAccess)
{
var source = $@"using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
namespace MyNamespace
{{
public interface Foo
{{
int Bar(int x);
Task<int> Bar(int x);
int Barr {{ get; }}
Task<int> Barr {{ get; }}
int this[int x] {{ get; }}
Task<int> this[int x] {{ get; }}
}}
public class FooTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

namespace NSubstitute.Analyzers.Tests.VisualBasic.DiagnosticAnalyzersTests.ConflictingArgumentAssignmentsAnalyzerTests;

[CombinatoryData("Throws", "ThrowsForAnyArgs")]
[CombinatoryData("Throws", "ThrowsAsync", "ThrowsForAnyArgs", "ThrowsAsyncForAnyArgs")]
public class ThrowsAsExtensionMethodTests : ConflictingArgumentAssignmentsDiagnosticVerifier
{
public override async Task ReportsDiagnostic_When_AndDoesMethod_SetsSameArgument_AsPreviousSetupMethod(string method, string call, string previousCallArgAccess, string andDoesArgAccess)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
ReadOnly Property Barr As Integer
Default ReadOnly Property Item(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
ReadOnly Property Barr As Task(Of Integer)
Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand All @@ -39,12 +40,13 @@ End Namespace
public override async Task ReportsNoDiagnostics_WhenSubstituteMethodCannotBeInferred(string method)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand All @@ -67,14 +69,15 @@ End Class
public override async Task ReportsNoDiagnostics_WhenUsedWithUnfortunatelyNamedMethod(string method)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports System.Runtime.CompilerServices
Imports NSubstitute
Imports NSubstitute.Core
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand Down Expand Up @@ -107,14 +110,15 @@ End Module
public override async Task ReportsNoDiagnostics_When_AndDoesMethod_SetsDifferentArgument_AsPreviousSetupMethod(string method, string call, string andDoesArgAccess)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
ReadOnly Property Barr As Integer
Default ReadOnly Property Item(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
ReadOnly Property Barr As Task(Of Integer)
Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand All @@ -136,14 +140,15 @@ End Class
public override async Task ReportsNoDiagnostics_When_AndDoesMethod_AccessSameArguments_AsPreviousSetupMethod(string method, string call, string argAccess)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
ReadOnly Property Barr As Integer
Default ReadOnly Property Item(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
ReadOnly Property Barr As Task(Of Integer)
Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand All @@ -165,12 +170,13 @@ End Class
public override async Task ReportsNoDiagnostics_When_AndDoesMethod_SetSameArguments_AsPreviousSetupMethod_SetsIndirectly(string method)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand All @@ -195,14 +201,15 @@ End Class
public override async Task ReportsNoDiagnostic_When_AndDoesMethod_SetArgument_AndPreviousMethod_IsNotUsedWithCallInfo(string method, string call, string andDoesArgAccess)
{
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface Foo
Function Bar(ByVal x As Integer) As Integer
ReadOnly Property Barr As Integer
Default ReadOnly Property Item(ByVal x As Integer) As Integer
Function Bar(ByVal x As Integer) As Task(Of Integer)
ReadOnly Property Barr As Task(Of Integer)
Default ReadOnly Property Item(ByVal x As Integer) As Task(Of Integer)
End Interface
Public Class FooTests
Expand Down
Loading

0 comments on commit f7fcddc

Please sign in to comment.