Skip to content

Commit

Permalink
GH-186 - fixing overload resolution issues when verifying code fixes.…
Browse files Browse the repository at this point in the history
… Adding missing tests for SyncOverAsyncThrowsCodeFixProvider
  • Loading branch information
tpodolak committed Jul 22, 2022
1 parent ad97761 commit a1c04c6
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -104,7 +104,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -155,7 +155,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -100,7 +100,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -149,7 +149,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -108,7 +108,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -161,7 +161,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -104,7 +104,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -155,7 +155,7 @@ public void Test()
}}
}}";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ protected CodeFixVerifier(WorkspaceFactory workspaceFactory)

protected abstract DiagnosticAnalyzer DiagnosticAnalyzer { get; }

protected Task VerifyFix(
string oldSource,
string newSource,
NSubstituteVersion version) => VerifyFix(oldSource, newSource, null, version);

protected async Task VerifyFix(
string oldSource,
string newSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ End Sub
End Class
End Namespace";

await VerifyCodeActions(source, expectedCodeActionTitle);
await VerifyCodeActions(source, NSubstituteVersion.NSubstitute4_2_2, expectedCodeActionTitle);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -88,7 +88,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -131,7 +131,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -84,7 +84,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -125,7 +125,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -92,7 +92,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -137,7 +137,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource, NSubstituteVersion.NSubstitute4_2_2);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using NSubstitute.Analyzers.Tests.Shared;

namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SyncOverAsyncThrowsCodeFixProviderTests;

Expand Down Expand Up @@ -44,7 +45,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInProperty(string method, string updatedMethod)
Expand Down Expand Up @@ -87,7 +88,7 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override async Task ReplacesThrowsWithReturns_WhenUsedInIndexer(string method, string updatedMethod)
Expand Down Expand Up @@ -130,21 +131,135 @@ End Sub
End Class
End Namespace";

await VerifyFix(source, newSource);
await VerifyFix(source, newSource, null, NSubstituteVersion.NSubstitute4_2_2);
}

public override Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInMethod(string method, string updatedMethod)
{
throw new System.NotImplementedException();
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface IFoo
Function Bar() As Task
End Interface
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
ExceptionExtensions.{method}(Of Exception)(substitute.Bar())
ExceptionExtensions.{method}(Of Exception)(value := substitute.Bar())
End Sub
End Class
End Namespace";

var newSource = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface IFoo
Function Bar() As Task
End Interface
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
ExceptionExtensions.{updatedMethod}(Of Exception)(substitute.Bar())
ExceptionExtensions.{updatedMethod}(Of Exception)(value := substitute.Bar())
End Sub
End Class
End Namespace";

await VerifyFix(source, newSource);
}

public override Task ReplacesThrowsWithThrowsAsync_WhenUsedInProperty(string method, string updatedMethod)
public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInProperty(string method, string updatedMethod)
{
throw new System.NotImplementedException();
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface IFoo
Property Bar As Task
End Interface
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
ExceptionExtensions.{method}(Of Exception)(substitute.Bar)
ExceptionExtensions.{method}(Of Exception)(value := substitute.Bar)
End Sub
End Class
End Namespace";

var newSource = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface IFoo
Property Bar As Task
End Interface
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
ExceptionExtensions.{updatedMethod}(Of Exception)(substitute.Bar)
ExceptionExtensions.{updatedMethod}(Of Exception)(value := substitute.Bar)
End Sub
End Class
End Namespace";

await VerifyFix(source, newSource);
}

public override Task ReplacesThrowsWithThrowsAsync_WhenUsedInIndexer(string method, string updatedMethod)
public override async Task ReplacesThrowsWithThrowsAsync_WhenUsedInIndexer(string method, string updatedMethod)
{
throw new System.NotImplementedException();
var source = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface IFoo
Default Property Item(ByVal x As Integer) As Task
End Interface
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
ExceptionExtensions.{method}(Of Exception)(substitute(0))
ExceptionExtensions.{method}(Of Exception)(value := substitute(0))
End Sub
End Class
End Namespace";

var newSource = $@"Imports System
Imports System.Threading.Tasks
Imports NSubstitute
Imports NSubstitute.ExceptionExtensions
Namespace MyNamespace
Interface IFoo
Default Property Item(ByVal x As Integer) As Task
End Interface
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of IFoo)()
ExceptionExtensions.{updatedMethod}(Of Exception)(substitute(0))
ExceptionExtensions.{updatedMethod}(Of Exception)(value := substitute(0))
End Sub
End Class
End Namespace";

await VerifyFix(source, newSource);
}
}

0 comments on commit a1c04c6

Please sign in to comment.