Skip to content

Commit

Permalink
Inline SetupShouldNotIncludeAsyncResult tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKotsenas committed Jun 5, 2024
1 parent 0c118b6 commit db0b3cb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 70 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 1 addition & 6 deletions Source/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down Expand Up @@ -41,10 +41,5 @@
<ItemGroup>
<ProjectReference Include="..\Moq.Analyzers\Moq.Analyzers.csproj" AddPackageAsOutput="true" />
</ItemGroup>
<ItemGroup>
<Compile Update="Data\**\*.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,92 @@ public class SetupShouldNotIncludeAsyncResultAnalyzerTests : DiagnosticVerifier
[Fact]
public Task ShouldPassWhenSetupWithoutReturn()
{
return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupShouldNotIncludeAsyncResult.TestOkForTask.cs")));
return Verify(VerifyCSharpDiagnostic(
[
"""
using System.Threading.Tasks;
using Moq;
namespace SetupShouldNotIncludeAsyncResult.TestOkForTask;
public class AsyncClient
{
public virtual Task TaskAsync() => Task.CompletedTask;
public virtual Task<string> GenericTaskAsync() => Task.FromResult(string.Empty);
}
internal class MyUnitTests
{
private void TestOkForTask()
{
var mock = new Mock<AsyncClient>();
mock.Setup(c => c.TaskAsync());
}
}
"""
]));
}

[Fact]
public Task ShouldPassWhenSetupWithReturnsAsync()
{
return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupShouldNotIncludeAsyncResult.TestOkForGenericTaskProperSetup.cs")));
return Verify(VerifyCSharpDiagnostic(
[
"""
using System.Threading.Tasks;
using Moq;
namespace SetupShouldNotIncludeAsyncResult.TestOkForGenericTaskProperSetup;
public class AsyncClient
{
public virtual Task TaskAsync() => Task.CompletedTask;
public virtual Task<string> GenericTaskAsync() => Task.FromResult(string.Empty);
}
internal class MyUnitTests
{
private void TestOkForGenericTaskProperSetup()
{
var mock = new Mock<AsyncClient>();
mock.Setup(c => c.GenericTaskAsync())
.ReturnsAsync(string.Empty);
}
}
"""
]));
}

[Fact]
public Task ShouldFailWhenSetupWithTaskResult()
{
return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupShouldNotIncludeAsyncResult.TestBadForGenericTask.cs")));
return Verify(VerifyCSharpDiagnostic(
[
"""
using System.Threading.Tasks;
using Moq;
namespace SetupShouldNotIncludeAsyncResult.TestBadForGenericTask;
public class AsyncClient
{
public virtual Task TaskAsync() => Task.CompletedTask;
public virtual Task<string> GenericTaskAsync() => Task.FromResult(string.Empty);
}
internal class MyUnitTests
{
private void TestBadForGenericTask()
{
var mock = new Mock<AsyncClient>();
mock.Setup(c => c.GenericTaskAsync().Result);
}
}
"""
]));
}

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
Expand Down

0 comments on commit db0b3cb

Please sign in to comment.