Updated FormatFilter tests to include Accept header
This commit is contained in:
parent
bf93c7d7a4
commit
f888ced1f2
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -10,6 +11,10 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
{
|
{
|
||||||
public class FormatFilterSampleTest : IClassFixture<MvcTestFixture<FormatFilterSample.Web.Startup>>
|
public class FormatFilterSampleTest : IClassFixture<MvcTestFixture<FormatFilterSample.Web.Startup>>
|
||||||
{
|
{
|
||||||
|
// Typical accept header sent by Chrome browser
|
||||||
|
private const string ChromeAcceptHeader = "text/html,application/xhtml+xml," +
|
||||||
|
"application/xml;q=0.9,image/webp,*/*;q=0.8";
|
||||||
|
|
||||||
public FormatFilterSampleTest(MvcTestFixture<FormatFilterSample.Web.Startup> fixture)
|
public FormatFilterSampleTest(MvcTestFixture<FormatFilterSample.Web.Startup> fixture)
|
||||||
{
|
{
|
||||||
Client = fixture.Client;
|
Client = fixture.Client;
|
||||||
|
|
@ -42,8 +47,12 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FormatFilter_ExtensionInRequest_Optional()
|
public async Task FormatFilter_ExtensionInRequest_Optional()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange
|
||||||
var response = await Client.GetAsync("http://localhost/FormatFilter/GetProduct.json");
|
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/FormatFilter/GetProduct.json");
|
||||||
|
request.Headers.Add("Accept", ChromeAcceptHeader);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var response = await Client.SendAsync(request);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
|
@ -53,8 +62,12 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FormatFilter_ExtensionInRequest_Custom()
|
public async Task FormatFilter_ExtensionInRequest_Custom()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange
|
||||||
var response = await Client.GetAsync("http://localhost/FormatFilter/GetProduct/5.custom");
|
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/FormatFilter/GetProduct/5.custom");
|
||||||
|
request.Headers.Add("Accept", ChromeAcceptHeader);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var response = await Client.SendAsync(request);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
|
@ -75,8 +88,12 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FormatFilter_ExtensionInRequest_NonExistant()
|
public async Task FormatFilter_ExtensionInRequest_NonExistant()
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange
|
||||||
var response = await Client.GetAsync("http://localhost/FormatFilter/GetProduct/5.xml");
|
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/FormatFilter/GetProduct/5.xml");
|
||||||
|
request.Headers.Add("Accept", ChromeAcceptHeader);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var response = await Client.SendAsync(request);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue