Skip to content

Commit 4a65018

Browse files
author
Chris Martinez
committed
Assert 'Location' header in POST tests
1 parent 2d5cbde commit 4a65018

File tree

12 files changed

+24
-4
lines changed

12 files changed

+24
-4
lines changed

test/Microsoft.AspNet.WebApi.Acceptance.Tests/Http/Basic/given a versioned ApiController/when using a url segment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public async Task then_post_should_return_201()
4848
var entity = default( object );
4949

5050
// act
51-
var response = await PostAsync( "api/v1/helloworld", entity ).EnsureSuccessStatusCode();
51+
var response = await PostAsync( "api/v1/helloworld", entity );
5252

5353
// assert
54+
response.StatusCode.Should().Be( Created );
5455
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/v1/helloworld/42" ) );
5556
}
5657

test/Microsoft.AspNet.WebApi.Acceptance.Tests/Http/Basic/given a versioned ApiController/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.Web;
55
using Microsoft.Web.Http.Basic;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -40,6 +41,7 @@ public async Task then_post_should_return_201( string requestUrl )
4041

4142
// assert
4243
response.StatusCode.Should().Be( Created );
44+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/orders/42" ) );
4345
}
4446

4547
[Fact]

test/Microsoft.AspNet.WebApi.Acceptance.Tests/Http/ByNamespace/given a versioned ApiController per namespace/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.Web;
55
using Microsoft.Web.Http.ByNamespace;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -37,6 +38,7 @@ public async Task then_post_should_return_201( string requestUrl )
3738

3839
// assert
3940
response.StatusCode.Should().Be( Created );
41+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/orders/42" ) );
4042
}
4143

4244
[Fact]

test/Microsoft.AspNet.WebApi.Acceptance.Tests/Http/Conventions/given a versioned ApiController using conventions/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.Web;
55
using Microsoft.Web.Http.Conventions;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -40,6 +41,7 @@ public async Task then_post_should_return_201( string requestUrl )
4041

4142
// assert
4243
response.StatusCode.Should().Be( Created );
44+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/orders/42" ) );
4345
}
4446

4547
[Fact]

test/Microsoft.AspNet.WebApi.Acceptance.Tests/Http/MediaTypeNegotiation/given a versioned ApiController/when using media type negotiation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ public async Task then_post_should_return_201()
7676
var content = new ObjectContent( entity.GetType(), entity, new JsonMediaTypeFormatter(), mediaType );
7777

7878
// act
79-
var response = await PostAsync( "api/helloworld", content ).EnsureSuccessStatusCode();
79+
var response = await PostAsync( "api/helloworld", content );
8080

8181
// assert
82+
response.StatusCode.Should().Be( Created );
8283
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/helloworld/42" ) );
8384
}
8485

test/Microsoft.AspNet.WebApi.Acceptance.Tests/OData/Basic/given a versioned ODataController/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using FluentAssertions;
44
using Microsoft.AspNet.OData.Basic;
5+
using System;
56
using System.Threading.Tasks;
67
using Xunit;
78
using static System.Net.HttpStatusCode;
@@ -39,6 +40,7 @@ public async Task then_post_should_return_201( string requestUrl )
3940

4041
// assert
4142
response.StatusCode.Should().Be( Created );
43+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/Customers(42)" ) );
4244
}
4345

4446
[Fact]

test/Microsoft.AspNet.WebApi.Acceptance.Tests/OData/Conventions/given a versioned ODataController using conventions/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.AspNet.OData;
55
using Microsoft.AspNet.OData.Conventions;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -41,6 +42,7 @@ public async Task then_post_should_return_201( string requestUrl )
4142

4243
// assert
4344
response.StatusCode.Should().Be( Created );
45+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/Customers(42)" ) );
4446
}
4547

4648
[Fact]

test/Microsoft.AspNetCore.Mvc.Acceptance.Tests/Mvc/Basic/given a versioned Controller/when using a url segment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ public async Task then_post_should_return_201( string version )
5757
var entity = default( object );
5858

5959
// act
60-
var response = await PostAsync( $"api/{version}/helloworld", entity ).EnsureSuccessStatusCode();
60+
var response = await PostAsync( $"api/{version}/helloworld", entity );
6161

6262
// assert
63+
response.StatusCode.Should().Be( Created );
6364
response.Headers.Location.Should().Be( new Uri( $"http://localhost/api/{version}/HelloWorld/42" ) );
6465
}
6566

test/Microsoft.AspNetCore.Mvc.Acceptance.Tests/Mvc/Basic/given a versioned Controller/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.AspNetCore.Mvc.Basic;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -40,6 +41,7 @@ public async Task then_post_should_return_201( string requestUrl )
4041

4142
// assert
4243
response.StatusCode.Should().Be( Created );
44+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/Orders/42" ) );
4345
}
4446

4547
[Fact]

test/Microsoft.AspNetCore.Mvc.Acceptance.Tests/Mvc/ByNamespace/given a versioned Controller per namespace/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.AspNetCore.Mvc.ByNamespace;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -37,6 +38,7 @@ public async Task then_post_should_return_201( string requestUrl )
3738

3839
// assert
3940
response.StatusCode.Should().Be( Created );
41+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/Orders/42" ) );
4042
}
4143

4244
[Fact]

test/Microsoft.AspNetCore.Mvc.Acceptance.Tests/Mvc/Conventions/given a versioned Controller using conventions/when using an action.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.AspNetCore.Mvc.Conventions;
6+
using System;
67
using System.Threading.Tasks;
78
using Xunit;
89
using static System.Net.HttpStatusCode;
@@ -40,6 +41,7 @@ public async Task then_post_should_return_201( string requestUrl )
4041

4142
// assert
4243
response.StatusCode.Should().Be( Created );
44+
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/Orders/42" ) );
4345
}
4446

4547
[Fact]

test/Microsoft.AspNetCore.Mvc.Acceptance.Tests/Mvc/MediaTypeNegotiation/given a versioned Controller/when using media type negotiation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ public async Task then_post_should_return_201()
8080
content.Headers.ContentType = Parse( "application/json;v=1.0" );
8181

8282
// act
83-
var response = await PostAsync( "api/helloworld", content ).EnsureSuccessStatusCode();
83+
var response = await PostAsync( "api/helloworld", content );
8484

8585
// assert
86+
response.StatusCode.Should().Be( Created );
8687
response.Headers.Location.Should().Be( new Uri( "http://localhost/api/HelloWorld/42" ) );
8788
}
8889

0 commit comments

Comments
 (0)