Use `TheoryData` properties to avoid duplicate test data
- couldn't just remove duplicate `[TheoryData]` in `GlobalRoutingTest` - xUnit analyzers don't understand `[InlineData]` is inherited (though runtime certainly does)
This commit is contained in:
parent
498fa2d72f
commit
0d427a60e5
|
|
@ -105,10 +105,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
|
|
||||||
// Global routing exposes HTTP 405s for HTTP method mismatches
|
// Global routing exposes HTTP 405s for HTTP method mismatches
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("http://localhost/api/v1/Maps/5", "PATCH")]
|
[MemberData(nameof(AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraintsData))]
|
||||||
[InlineData("http://localhost/api/v2/Maps/5", "PATCH")]
|
|
||||||
[InlineData("http://localhost/api/v1/Maps/PartialUpdate/5", "PUT")]
|
|
||||||
[InlineData("http://localhost/api/v2/Maps/PartialUpdate/5", "PUT")]
|
|
||||||
public override async Task AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraints(
|
public override async Task AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraints(
|
||||||
string url,
|
string url,
|
||||||
string method)
|
string method)
|
||||||
|
|
@ -125,11 +122,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
|
|
||||||
// Global routing exposes HTTP 405s for HTTP method mismatches
|
// Global routing exposes HTTP 405s for HTTP method mismatches
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Post", "/Friends")]
|
[MemberData(nameof(AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheActionData))]
|
||||||
[InlineData("Put", "/Friends")]
|
|
||||||
[InlineData("Patch", "/Friends")]
|
|
||||||
[InlineData("Options", "/Friends")]
|
|
||||||
[InlineData("Head", "/Friends")]
|
|
||||||
public override async Task AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheAction(
|
public override async Task AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheAction(
|
||||||
string method,
|
string method,
|
||||||
string url)
|
string url)
|
||||||
|
|
@ -144,11 +137,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
|
Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// These verbs don't match
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("/Bank/Deposit", "GET")]
|
[MemberData(nameof(AttributeRouting_MixedAcceptVerbsAndRoute_UnreachableData))]
|
||||||
[InlineData("/Bank/Deposit/5", "DELETE")]
|
|
||||||
[InlineData("/Bank/Withdraw/5", "GET")]
|
|
||||||
public override async Task AttributeRouting_MixedAcceptVerbsAndRoute_Unreachable(string path, string verb)
|
public override async Task AttributeRouting_MixedAcceptVerbsAndRoute_Unreachable(string path, string verb)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -161,4 +151,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
|
Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -248,12 +247,23 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TheoryData<string, string> AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheActionData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new TheoryData<string, string>
|
||||||
|
{
|
||||||
|
{ "Post", "/Friends" },
|
||||||
|
{ "Put", "/Friends" },
|
||||||
|
{ "Patch", "/Friends" },
|
||||||
|
{ "Options", "/Friends" },
|
||||||
|
{ "Head", "/Friends" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Post", "/Friends")]
|
[MemberData(nameof(AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheActionData))]
|
||||||
[InlineData("Put", "/Friends")]
|
|
||||||
[InlineData("Patch", "/Friends")]
|
|
||||||
[InlineData("Options", "/Friends")]
|
|
||||||
[InlineData("Head", "/Friends")]
|
|
||||||
public virtual async Task AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheAction(
|
public virtual async Task AttributeRoutedAction_RejectsRequestsWithWrongMethods_InRoutesWithoutExtraTemplateSegmentsOnTheAction(
|
||||||
string method,
|
string method,
|
||||||
string url)
|
string url)
|
||||||
|
|
@ -390,11 +400,22 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
result.ExpectedUrls);
|
result.ExpectedUrls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TheoryData<string, string> AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraintsData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new TheoryData<string, string>
|
||||||
|
{
|
||||||
|
{ "http://localhost/api/v1/Maps/5", "PATCH" },
|
||||||
|
{ "http://localhost/api/v2/Maps/5", "PATCH" },
|
||||||
|
{ "http://localhost/api/v1/Maps/PartialUpdate/5", "PUT" },
|
||||||
|
{ "http://localhost/api/v2/Maps/PartialUpdate/5", "PUT" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("http://localhost/api/v1/Maps/5", "PATCH")]
|
[MemberData(nameof(AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraintsData))]
|
||||||
[InlineData("http://localhost/api/v2/Maps/5", "PATCH")]
|
|
||||||
[InlineData("http://localhost/api/v1/Maps/PartialUpdate/5", "PUT")]
|
|
||||||
[InlineData("http://localhost/api/v2/Maps/PartialUpdate/5", "PUT")]
|
|
||||||
public virtual async Task AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraints(
|
public virtual async Task AttributeRoutedAction_MultipleRouteAttributes_WithMultipleHttpAttributes_RespectsConstraints(
|
||||||
string url,
|
string url,
|
||||||
string method)
|
string method)
|
||||||
|
|
@ -1208,10 +1229,21 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
// These verbs don't match
|
// These verbs don't match
|
||||||
|
public static TheoryData<string, string> AttributeRouting_MixedAcceptVerbsAndRoute_UnreachableData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new TheoryData<string, string>
|
||||||
|
{
|
||||||
|
{ "/Bank/Deposit", "GET" },
|
||||||
|
{ "/Bank/Deposit/5", "DELETE" },
|
||||||
|
{ "/Bank/Withdraw/5", "GET" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("/Bank/Deposit", "GET")]
|
[MemberData(nameof(AttributeRouting_MixedAcceptVerbsAndRoute_UnreachableData))]
|
||||||
[InlineData("/Bank/Deposit/5", "DELETE")]
|
|
||||||
[InlineData("/Bank/Withdraw/5", "GET")]
|
|
||||||
public virtual async Task AttributeRouting_MixedAcceptVerbsAndRoute_Unreachable(string path, string verb)
|
public virtual async Task AttributeRouting_MixedAcceptVerbsAndRoute_Unreachable(string path, string verb)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -1277,8 +1309,10 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
{
|
{
|
||||||
Url = url;
|
Url = url;
|
||||||
|
|
||||||
Values = new Dictionary<string, object>();
|
Values = new Dictionary<string, object>
|
||||||
Values.Add("link", string.Empty);
|
{
|
||||||
|
{ "link", string.Empty }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue