|
| 1 | +namespace AspNetCoreAnalyzers.Tests.ASP004ParameterSyntaxTests |
| 2 | +{ |
| 3 | + using Gu.Roslyn.Asserts; |
| 4 | + using Microsoft.CodeAnalysis.Diagnostics; |
| 5 | + using NUnit.Framework; |
| 6 | + |
| 7 | + public class ValidCode |
| 8 | + { |
| 9 | + private static readonly DiagnosticAnalyzer Analyzer = new AttributeAnalyzer(); |
| 10 | + |
| 11 | + [TestCase("{value:bool}", "bool")] |
| 12 | + [TestCase("{value:datetime}", "System.DateTime")] |
| 13 | + [TestCase("{value:decimal}", "decimal")] |
| 14 | + [TestCase("{value:double}", "double")] |
| 15 | + [TestCase("{value:float}", "float")] |
| 16 | + [TestCase("{value:int}", "int")] |
| 17 | + [TestCase("api/orders/{value:int:min(1)}", "int")] |
| 18 | + [TestCase("api/orders/{value:int:max(1)}", "int")] |
| 19 | + [TestCase("api/orders/{value:int:range(1,10)}", "int")] |
| 20 | + [TestCase("api/orders/{value:int:required}", "int")] |
| 21 | + [TestCase("{value:long}", "long")] |
| 22 | + [TestCase("api/orders/{value:min(1)}", "long")] |
| 23 | + [TestCase("api/orders/{value:max(1)}", "long")] |
| 24 | + [TestCase("api/orders/{value:range(1,10)}", "long")] |
| 25 | + [TestCase("api/orders/{value:required}", "long")] |
| 26 | + [TestCase("{value:guid}", "System.Guid")] |
| 27 | + [TestCase("api/orders/{value:minlength(1)}", "string")] |
| 28 | + [TestCase("api/orders/{value:maxlength(1)}", "string")] |
| 29 | + [TestCase("api/orders/{value:length(1)}", "string")] |
| 30 | + [TestCase("api/orders/{value:length(1,3)}", "string")] |
| 31 | + [TestCase("api/orders/{value:alpha}", "string")] |
| 32 | + [TestCase("api/orders/{value:regex(a-(0|1))}", "string")] |
| 33 | + [TestCase("api/orders/{value:regex(^\\\\d{{3}}-\\\\d{{2}}-\\\\d{{4}}$)}", "string")] |
| 34 | + [TestCase("api/orders/{value:required}", "string")] |
| 35 | + public void WithParameter(string parameter, string type) |
| 36 | + { |
| 37 | + var code = @" |
| 38 | +namespace ValidCode |
| 39 | +{ |
| 40 | + using System.Threading.Tasks; |
| 41 | + using Microsoft.AspNetCore.Mvc; |
| 42 | + using Microsoft.EntityFrameworkCore; |
| 43 | +
|
| 44 | + [ApiController] |
| 45 | + public class OrdersController : Controller |
| 46 | + { |
| 47 | + [HttpGet(""api/{value}"")] |
| 48 | + public async Task<int> GetOrder(int value) |
| 49 | + { |
| 50 | + return value; |
| 51 | + } |
| 52 | + } |
| 53 | +}".AssertReplace("int", type) |
| 54 | + .AssertReplace("{value}", parameter); |
| 55 | + AnalyzerAssert.Valid(Analyzer, code); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments