Skip to content

Commit

Permalink
Another couple tests for the fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBoike committed Feb 23, 2021
1 parent 35800b6 commit 1c2d1bf
Showing 1 changed file with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,94 @@ public class TestMessage : ICommand {}
return VerifyFix(test, fixedTest);
}

[Test]
public Task DontMessUpGenericTypeParams()
{
var test = @"
using NServiceBus;
using System.Threading;
using System.Threading.Tasks;
public class Foo : IHandleMessages<TestMessage>
{
public async Task Handle(TestMessage message, IMessageHandlerContext context)
{
int answer1 = await TestMethod(42);
int answer2 = await TestMethod<int>(42);
string msg1 = await TestMethod(""Hello"");
string msg2 = await TestMethod<string>(""World"");
}
Task<T> TestMethod<T>(T value, CancellationToken token = default(CancellationToken)) { return Task.FromResult(value); }
}
public class TestMessage : ICommand {}
";

var fixedTest = @"
using NServiceBus;
using System.Threading;
using System.Threading.Tasks;
public class Foo : IHandleMessages<TestMessage>
{
public async Task Handle(TestMessage message, IMessageHandlerContext context)
{
int answer1 = await TestMethod(42, context.CancellationToken);
int answer2 = await TestMethod<int>(42, context.CancellationToken);
string msg1 = await TestMethod(""Hello"", context.CancellationToken);
string msg2 = await TestMethod<string>(""World"", context.CancellationToken);
}
Task<T> TestMethod<T>(T value, CancellationToken token = default(CancellationToken)) { return Task.FromResult(value); }
}
public class TestMessage : ICommand {}
";

return VerifyFix(test, fixedTest);
}

[Test]
public Task DontMessUpTrivia()
{
var test = @"
using NServiceBus;
using System.Threading;
using System.Threading.Tasks;
public class Foo : IHandleMessages<TestMessage>
{
public async Task Handle(TestMessage message, IMessageHandlerContext context)
{
await TestMethod(1, 2, // comment
3, /*comment*/ 4, // comment
//comment
5);
}
Task TestMethod(int a, int b, int c, int d, int e, CancellationToken token = default(CancellationToken)) { return Task.CompletedTask; }
}
public class TestMessage : ICommand {}
";

var fixedTest = @"
using NServiceBus;
using System.Threading;
using System.Threading.Tasks;
public class Foo : IHandleMessages<TestMessage>
{
public async Task Handle(TestMessage message, IMessageHandlerContext context)
{
await TestMethod(1, 2, // comment
3, /*comment*/ 4, // comment
//comment
5, context.CancellationToken);
}
Task TestMethod(int a, int b, int c, int d, int e, CancellationToken token = default(CancellationToken)) { return Task.CompletedTask; }
}
public class TestMessage : ICommand {}
";

return VerifyFix(test, fixedTest);
}

protected override DiagnosticAnalyzer GetAnalyzer() => new ForwardCancellationTokenAnalyzer();

protected override CodeFixProvider GetCodeFixProvider() => new ForwardCancellationTokenFixer();
Expand Down

0 comments on commit 1c2d1bf

Please sign in to comment.