Skip to content

Commit bb326be

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Added tests for deprecated and advertised API versions
1 parent 1c8bc5b commit bb326be

File tree

5 files changed

+62
-12
lines changed

5 files changed

+62
-12
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Microsoft.Web.Http.Description
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Collections.ObjectModel;
6+
using System.Linq;
7+
using System.Web.Http.Dispatcher;
8+
9+
public class ControllerTypeCollection : Collection<Type>, IHttpControllerTypeResolver
10+
{
11+
public ControllerTypeCollection() { }
12+
13+
public ControllerTypeCollection( params Type[] controllerTypes ) : base( controllerTypes.ToList() ) { }
14+
15+
public ICollection<Type> GetControllerTypes( IAssembliesResolver assembliesResolver ) => this;
16+
}
17+
}

test/Microsoft.AspNet.WebApi.Versioning.ApiExplorer.Tests/Description/TestConfigurations.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
{
33
using Microsoft.Web.Http.Versioning.Conventions;
44
using Models;
5-
using Moq;
65
using Simulators;
7-
using System;
86
using System.Collections;
97
using System.Collections.Generic;
108
using System.Web.Http;
@@ -24,7 +22,7 @@ public IEnumerator<object[]> GetEnumerator()
2422
static HttpConfiguration NewConventionRouteConfiguration()
2523
{
2624
var configuration = new HttpConfiguration();
27-
var controllerTypeResolver = NewControllerTypeResolver(
25+
var controllerTypeResolver = new ControllerTypeCollection(
2826
typeof( ValuesController ),
2927
typeof( Values2Controller ),
3028
typeof( Values3Controller ) );
@@ -38,9 +36,12 @@ static HttpConfiguration NewConventionRouteConfiguration()
3836
.HasApiVersion( 1, 0 );
3937
options.Conventions.Controller<Values2Controller>()
4038
.HasApiVersion( 2, 0 )
39+
.HasDeprecatedApiVersion( 3, 0, "beta" )
4140
.HasApiVersion( 3, 0 )
4241
.Action( c => c.Post( default( ClassWithId ) ) ).MapToApiVersion( 3, 0 );
43-
options.Conventions.Controller<Values3Controller>().HasApiVersion( 4, 0 );
42+
options.Conventions.Controller<Values3Controller>()
43+
.HasApiVersion( 4, 0 )
44+
.AdvertisesApiVersion( 5, 0 );
4445
} );
4546

4647
return configuration;
@@ -49,7 +50,7 @@ static HttpConfiguration NewConventionRouteConfiguration()
4950
static HttpConfiguration NewDirectRouteConfiguration()
5051
{
5152
var configuration = new HttpConfiguration();
52-
var controllerTypeResolver = NewControllerTypeResolver(
53+
var controllerTypeResolver = new ControllerTypeCollection(
5354
typeof( AttributeValues1Controller ),
5455
typeof( AttributeValues2Controller ),
5556
typeof( AttributeValues3Controller ) );
@@ -60,12 +61,5 @@ static HttpConfiguration NewDirectRouteConfiguration()
6061

6162
return configuration;
6263
}
63-
64-
static IHttpControllerTypeResolver NewControllerTypeResolver( params Type[] controllerTypes )
65-
{
66-
var controllerTypeResolver = new Mock<IHttpControllerTypeResolver>();
67-
controllerTypeResolver.Setup( c => c.GetControllerTypes( It.IsAny<IAssembliesResolver>() ) ).Returns( controllerTypes );
68-
return controllerTypeResolver.Object;
69-
}
7064
}
7165
}

test/Microsoft.AspNet.WebApi.Versioning.ApiExplorer.Tests/Description/VersionedApiExplorerTest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public void api_descriptions_should_collate_expected_versions( HttpConfiguration
231231
descriptions.ApiVersions.Should().Equal(
232232
new ApiVersion( 1, 0 ),
233233
new ApiVersion( 2, 0 ),
234+
new ApiVersion( 3, 0, "beta" ),
234235
new ApiVersion( 3, 0 ),
235236
new ApiVersion( 4, 0 ) );
236237
}
@@ -377,6 +378,42 @@ public void api_description_group_should_explore_v3_actions( HttpConfiguration c
377378
options => options.ExcludingMissingMembers() );
378379
}
379380

381+
[Theory]
382+
[ClassData( typeof( TestConfigurations ) )]
383+
public void api_description_group_should_explore_v3_beta_actions( HttpConfiguration configuration )
384+
{
385+
// arrange
386+
var apiExplorer = new VersionedApiExplorer( configuration );
387+
var apiVersion = new ApiVersion( 3, 0, "beta" );
388+
var descriptionGroup = apiExplorer.ApiDescriptions[apiVersion];
389+
390+
// act
391+
var descriptions = descriptionGroup.ApiDescriptions;
392+
var relativePaths = descriptions.Select( d => d.RelativePath ).ToArray();
393+
394+
// assert
395+
descriptionGroup.IsDeprecated.Should().BeTrue();
396+
descriptions.ShouldBeEquivalentTo(
397+
new[]
398+
{
399+
new
400+
{
401+
ID = $"GET{relativePaths[0]}-3.0-beta",
402+
HttpMethod = Get,
403+
RelativePath = relativePaths[0],
404+
Version = apiVersion
405+
},
406+
new
407+
{
408+
ID = $"GET{relativePaths[1]}-3.0-beta",
409+
HttpMethod = Get,
410+
RelativePath = relativePaths[1],
411+
Version = apiVersion
412+
}
413+
},
414+
options => options.ExcludingMissingMembers() );
415+
}
416+
380417
[Theory]
381418
[ClassData( typeof( TestConfigurations ) )]
382419
public void api_description_group_should_explore_v4_actions( HttpConfiguration configuration )

test/Microsoft.AspNet.WebApi.Versioning.ApiExplorer.Tests/Simulators/AttributeValues2Controller.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Web.Http;
55

66
[ApiVersion( "2.0" )]
7+
[ApiVersion( "3.0-beta", Deprecated = true )]
78
[ApiVersion( "3.0" )]
89
[RoutePrefix( "values" )]
910
public class AttributeValues2Controller : ApiController

test/Microsoft.AspNet.WebApi.Versioning.ApiExplorer.Tests/Simulators/AttributeValues3Controller.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using static System.Net.HttpStatusCode;
66

77
[ApiVersion( "4.0" )]
8+
[AdvertiseApiVersions( "5.0" )]
89
[RoutePrefix( "values" )]
910
public class AttributeValues3Controller : ApiController
1011
{

0 commit comments

Comments
 (0)