Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8d7ff7

Browse files
Chris Martinezcommonsensesoftware
Chris Martinez
authored andcommittedNov 9, 2018
Add acceptance tests for action-level API version declarations
1 parent 03497ff commit c8d7ff7

File tree

46 files changed

+1455
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1455
-21
lines changed
 

‎test/Microsoft.AspNet.WebApi.Acceptance.Tests/Http/Basic/BasicAcceptanceTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Microsoft.Web.Http.Basic
22
{
3-
using Controllers;
3+
using Microsoft.Web.Http.Basic.Controllers;
44
using Microsoft.Web.Http.Routing;
55
using System.Web.Http;
66
using System.Web.Http.Routing;
@@ -19,6 +19,7 @@ protected BasicAcceptanceTest()
1919
FilteredControllerTypes.Add( typeof( HelloWorldController ) );
2020
FilteredControllerTypes.Add( typeof( PingController ) );
2121
FilteredControllerTypes.Add( typeof( OverlappingRouteTemplateController ) );
22+
FilteredControllerTypes.Add( typeof( OrdersController ) );
2223
Configuration.AddApiVersioning( options => options.ReportApiVersions = true );
2324
Configuration.MapHttpAttributeRoutes( constraintResolver );
2425
Configuration.EnsureInitialized();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
namespace Microsoft.Web.Http.Basic.Controllers
2+
{
3+
using Microsoft.Web.Http;
4+
using System.Web.Http;
5+
using static System.Net.HttpStatusCode;
6+
7+
[RoutePrefix( "api/orders" )]
8+
public class OrdersController : ApiController
9+
{
10+
[Route]
11+
[ApiVersion( "1.0" )]
12+
[ApiVersion( "2.0" )]
13+
public IHttpActionResult Get() => Ok();
14+
15+
[Route( "{id}", Name = "GetOrderById" )]
16+
[ApiVersion( "0.9" )]
17+
[ApiVersion( "1.0" )]
18+
[ApiVersion( "2.0" )]
19+
public IHttpActionResult Get( int id ) => Ok();
20+
21+
[Route]
22+
[ApiVersion( "1.0" )]
23+
[ApiVersion( "2.0" )]
24+
public IHttpActionResult Post( [FromBody] Order order )
25+
{
26+
order.Id = 42;
27+
return CreatedAtRoute( "GetOrderById", new { id = order.Id }, order );
28+
}
29+
30+
[Route( "{id}" )]
31+
[ApiVersion( "2.0" )]
32+
public IHttpActionResult Put( int id, [FromBody] Order order ) => StatusCode( NoContent );
33+
34+
[Route( "{id}" )]
35+
[ApiVersionNeutral]
36+
public IHttpActionResult Delete( int id ) => StatusCode( NoContent );
37+
}
38+
39+
public class Order
40+
{
41+
public int Id { get; set; }
42+
43+
public string Customer { get; set; }
44+
}
45+
}

0 commit comments

Comments
 (0)
Please sign in to comment.