Skip to content

Commit 0966416

Browse files
committed
Failing tests.
1 parent 1d09aa9 commit 0966416

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

  • AspNetCoreAnalyzers.Tests/ASP004ParameterSyntaxTests
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace AspNetCoreAnalyzers.Tests.ASP004ParameterSyntaxTests
2+
{
3+
using Gu.Roslyn.Asserts;
4+
using Microsoft.CodeAnalysis.CodeFixes;
5+
using Microsoft.CodeAnalysis.Diagnostics;
6+
using NUnit.Framework;
7+
8+
[Explicit("Failing tests.")]
9+
public class CodeFix
10+
{
11+
private static readonly DiagnosticAnalyzer Analyzer = new AttributeAnalyzer();
12+
private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(ASP004ParameterSyntax.Descriptor);
13+
private static readonly CodeFixProvider Fix = new ParameterTypeFix();
14+
15+
[TestCase("api/orders/↓id:long}", "api/orders/{id:long}")]
16+
[TestCase("api/orders/↓{id:long", "api/orders/{id:long}")]
17+
public void WhenFixable(string before, string after)
18+
{
19+
var code = @"
20+
namespace ValidCode
21+
{
22+
using Microsoft.AspNetCore.Mvc;
23+
24+
[ApiController]
25+
public class OrdersController : Controller
26+
{
27+
[HttpGet(""api/orders/{id:long}"")]
28+
public IActionResult GetId(long id)
29+
{
30+
return this.Ok(id);
31+
}
32+
}
33+
}".AssertReplace("api/orders/{id:long}", before);
34+
35+
var fixedCode = @"
36+
namespace ValidCode
37+
{
38+
using Microsoft.AspNetCore.Mvc;
39+
40+
[ApiController]
41+
public class OrdersController : Controller
42+
{
43+
[HttpGet(""api/orders/{id:ilongnt}"")]
44+
public IActionResult GetId(long id)
45+
{
46+
return this.Ok(id);
47+
}
48+
}
49+
}".AssertReplace("api/orders/{id:long}", after);
50+
AnalyzerAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, code, fixedCode);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)