зеркало из https://github.com/aspnet/Mvc.git
Updating FunctionalTests to use HttpClient abstractions
This commit is contained in:
Родитель
ccc20a38c1
Коммит
b8692c2c21
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expectedMessage = "TODO: No service for type 'ActivatorWebSite.CannotBeActivatedController+FakeType' " +
|
||||
"has been registered.";
|
||||
|
||||
|
@ -34,15 +34,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expected = "4|some-text";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Plain?foo=some-text");
|
||||
var response = await client.GetAsync("http://localhost/Plain?foo=some-text");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Fake-Value", result.HttpContext.Response.Headers["X-Fake-Header"]);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
var headerValue = Assert.Single(response.Headers.GetValues("X-Fake-Header"));
|
||||
Assert.Equal("Fake-Value", headerValue);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expected, body);
|
||||
}
|
||||
|
||||
|
@ -51,14 +52,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expected = "Hello world";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Regular");
|
||||
var body = await client.GetStringAsync("http://localhost/Regular");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body);
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task ViewActivator_ActivatesDefaultInjectedProperties()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expected = @"<label for=""Hello"">Hello</label> world! /View/ConsumeServicesFromBaseType";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/View/ConsumeDefaultProperties");
|
||||
var body = await client.GetStringAsync("http://localhost/View/ConsumeDefaultProperties");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
|
||||
|
@ -81,14 +80,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task ViewActivator_ActivatesAndContextualizesInjectedServices()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expected = "4 test-value";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/View/ConsumeInjectedService?test=test-value");
|
||||
var body = await client.GetStringAsync("http://localhost/View/ConsumeInjectedService?test=test-value");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
|
||||
|
@ -96,15 +94,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task ViewActivator_ActivatesServicesFromBaseType()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expected =
|
||||
@"/content/scripts/test.js";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/View/ConsumeServicesFromBaseType");
|
||||
var body = await client.GetStringAsync("http://localhost/View/ConsumeServicesFromBaseType");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
|
@ -11,32 +13,28 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
public class AntiForgeryTests
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IServiceProvider _services = TestHelper.CreateServices("AntiForgeryWebSite");
|
||||
private readonly Action<IBuilder> _app = new AntiForgeryWebSite.Startup().Configure;
|
||||
|
||||
public AntiForgeryTests()
|
||||
{
|
||||
_services = TestHelper.CreateServices("AntiForgeryWebSite");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MultipleAFTokensWithinTheSamePage_AreAllowed()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Account/Login");
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal("SAMEORIGIN", response.Headers["X-Frame-Options"]);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
var header = Assert.Single(response.Headers.GetValues("X-Frame-Options"));
|
||||
Assert.Equal("SAMEORIGIN", header);
|
||||
|
||||
var setCookieHeader = response.Headers.GetCommaSeparatedValues("Set-Cookie");
|
||||
Assert.Equal(2, setCookieHeader.Count);
|
||||
Assert.Equal(true, setCookieHeader[0].StartsWith("__RequestVerificationToken"));
|
||||
Assert.Equal(true, setCookieHeader[1].StartsWith("__RequestVerificationToken"));
|
||||
var setCookieHeader = response.Headers.GetValues("Set-Cookie").ToArray();
|
||||
Assert.Equal(2, setCookieHeader.Length);
|
||||
Assert.True(setCookieHeader[0].StartsWith("__RequestVerificationToken"));
|
||||
Assert.True(setCookieHeader[1].StartsWith("__RequestVerificationToken"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
// 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.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using BasicWebSite;
|
||||
|
@ -13,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
public class BasicTests
|
||||
{
|
||||
private readonly IServiceProvider _provider;
|
||||
private readonly IServiceProvider _provider = TestHelper.CreateServices("BasicWebSite");
|
||||
private readonly Action<IBuilder> _app = new Startup().Configure;
|
||||
|
||||
// Some tests require comparing the actual response body against an expected response baseline
|
||||
|
@ -22,11 +24,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
// use it on all the rest of the tests.
|
||||
private readonly Assembly _resourcesAssembly = typeof(BasicTests).GetTypeInfo().Assembly;
|
||||
|
||||
public BasicTests()
|
||||
{
|
||||
_provider = TestHelper.CreateServices("BasicWebSite");
|
||||
}
|
||||
|
||||
[InlineData("http://localhost/")]
|
||||
[InlineData("http://localhost/Home")]
|
||||
[InlineData("http://localhost/Home/Index")]
|
||||
|
@ -36,7 +33,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
|
||||
|
||||
// The K runtime compiles every file under compiler/resources as a resource at runtime with the same name
|
||||
// as the file name, in order to update a baseline you just need to change the file in that folder.
|
||||
|
@ -45,12 +43,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
// Act
|
||||
|
||||
// The host is not important as everything runs in memory and tests are isolated from each other.
|
||||
var result = await client.GetAsync(url);
|
||||
var responseContent = await result.ReadBodyAsStringAsync();
|
||||
var response = await client.GetAsync(url);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
Assert.Equal(result.ContentType, "text/html; charset=utf-8");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);
|
||||
Assert.Equal(expectedContent, responseContent);
|
||||
}
|
||||
|
||||
|
@ -59,16 +57,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var expectedContent = await _resourcesAssembly.ReadResourceAsStringAsync("compiler/resources/BasicWebSite.Home.PlainView.html");
|
||||
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
|
||||
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Home/PlainView");
|
||||
var responseContent = await result.ReadBodyAsStringAsync();
|
||||
var response = await client.GetAsync("http://localhost/Home/PlainView");
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
Assert.Equal(result.ContentType, "text/html; charset=utf-8");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);
|
||||
Assert.Equal(expectedContent, responseContent);
|
||||
}
|
||||
|
||||
|
@ -77,17 +77,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Home/NoContentResult");
|
||||
var response = await client.GetAsync("http://localhost/Home/NoContentResult");
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(204, result.StatusCode);
|
||||
Assert.Null(result.ContentType);
|
||||
Assert.Null(result.ContentLength);
|
||||
Assert.NotNull(result.Body);
|
||||
Assert.Equal(0, result.Body.Length);
|
||||
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
|
||||
Assert.Null(response.Content.Headers.ContentType);
|
||||
Assert.Equal(0, response.Content.Headers.ContentLength);
|
||||
Assert.Equal(0, responseContent.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -95,14 +95,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Home/ActionReturningTask");
|
||||
var response = await client.GetAsync("http://localhost/Home/ActionReturningTask");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(204, result.StatusCode);
|
||||
var body = await result.ReadBodyAsStringAsync();
|
||||
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal("Hello world", body);
|
||||
}
|
||||
|
||||
|
@ -111,25 +111,19 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
var expectedContent = "1";
|
||||
|
||||
// Call the server 3 times, and make sure the return value remains the same.
|
||||
var results = new string[3];
|
||||
|
||||
// Act
|
||||
for (int i = 0; i < 3; i++)
|
||||
// Act and Assert
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
var result = await client.GetAsync("http://localhost/Monitor/CountActionDescriptorInvocations");
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
results[i] = await result.ReadBodyAsStringAsync();
|
||||
}
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
var responseContent = await result.Content.ReadAsStringAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContent, results[0]);
|
||||
Assert.Equal(expectedContent, results[1]);
|
||||
Assert.Equal(expectedContent, results[2]);
|
||||
Assert.Equal(expectedContent, responseContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,26 +11,20 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
public class CompositeViewEngineTests
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IServiceProvider _services = TestHelper.CreateServices("CompositeViewEngine");
|
||||
private readonly Action<IBuilder> _app = new CompositeViewEngine.Startup().Configure;
|
||||
|
||||
public CompositeViewEngineTests()
|
||||
{
|
||||
_services = TestHelper.CreateServices("CompositeViewEngine");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompositeViewEngine_FindsPartialViewsAcrossAllEngines()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/");
|
||||
var body = await client.GetStringAsync("http://localhost/");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("Hello world", body.Trim());
|
||||
}
|
||||
|
||||
|
@ -39,13 +33,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/TestView");
|
||||
var body = await client.GetStringAsync("http://localhost/Home/TestView");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("Content from test view", body.Trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// 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.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using ConnegWebsite;
|
||||
using Microsoft.AspNet.Builder;
|
||||
|
@ -20,18 +22,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Selects custom even though it is last in the list.
|
||||
var expectedContentType = "application/custom;charset=utf-8";
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/custom;charset=utf-8");
|
||||
var expectedBody = "Written using custom format.";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Normal/WriteUserUsingCustomFormat");
|
||||
var response = await client.GetAsync("http://localhost/Normal/WriteUserUsingCustomFormat");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -40,16 +42,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/json;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
|
||||
var expectedBody = "{\r\n \"Name\": \"My name\",\r\n \"Address\": \"My address\"\r\n}";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Normal/MultipleAllowedContentTypes");
|
||||
var response = await client.GetAsync("http://localhost/Normal/MultipleAllowedContentTypes");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -58,16 +60,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "text/plain;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("text/plain;charset=utf-8");
|
||||
var expectedBody = "NormalController";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Normal/ReturnClassName");
|
||||
var response = await client.GetAsync("http://localhost/Normal/ReturnClassName");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -76,15 +78,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/json;charset=utf-8";
|
||||
//var expectedBody = "\"NormalController\"";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Normal/ReturnUser");
|
||||
var response = await client.GetAsync("http://localhost/Normal/ReturnUser");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -92,31 +93,32 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Normal/ReturnUser_NoMatchingFormatter");
|
||||
var response = await client.GetAsync("http://localhost/Normal/ReturnUser_NoMatchingFormatter");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(406, result.HttpContext.Response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.NotAcceptable, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ProducesContentAttribute_OnAction_OverridesTheValueOnClass()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Value on the class is application/json.
|
||||
var expectedContentType = "application/custom_ProducesContentBaseController_Action;charset=utf-8";
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse(
|
||||
"application/custom_ProducesContentBaseController_Action;charset=utf-8");
|
||||
var expectedBody = "ProducesContentBaseController";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/ProducesContentBase/ReturnClassName");
|
||||
var response = await client.GetAsync("http://localhost/ProducesContentBase/ReturnClassName");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -124,17 +126,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task ProducesContentAttribute_OnDerivedClass_OverridesTheValueOnBaseClass()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/custom_ProducesContentOnClassController;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse(
|
||||
"application/custom_ProducesContentOnClassController;charset=utf-8");
|
||||
var expectedBody = "ProducesContentOnClassController";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync(
|
||||
var response = await client.GetAsync(
|
||||
"http://localhost/ProducesContentOnClass/ReturnClassNameWithNoContentTypeOnAction");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -142,16 +145,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task ProducesContentAttribute_OnDerivedAction_OverridesTheValueOnBaseClass()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/custom_NoProducesContentOnClassController_Action;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse(
|
||||
"application/custom_NoProducesContentOnClassController_Action;charset=utf-8");
|
||||
var expectedBody = "NoProducesContentOnClassController";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/NoProducesContentOnClass/ReturnClassName");
|
||||
var response = await client.GetAsync("http://localhost/NoProducesContentOnClass/ReturnClassName");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -159,16 +163,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task ProducesContentAttribute_OnDerivedAction_OverridesTheValueOnBaseAction()
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/custom_NoProducesContentOnClassController_Action;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse(
|
||||
"application/custom_NoProducesContentOnClassController_Action;charset=utf-8");
|
||||
var expectedBody = "NoProducesContentOnClassController";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/NoProducesContentOnClass/ReturnClassName");
|
||||
var response = await client.GetAsync("http://localhost/NoProducesContentOnClass/ReturnClassName");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -177,16 +182,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/custom_ProducesContentOnClassController_Action;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse(
|
||||
"application/custom_ProducesContentOnClassController_Action;charset=utf-8");
|
||||
var expectedBody = "ProducesContentOnClassController";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/ProducesContentOnClass/ReturnClassNameContentTypeOnDerivedAction");
|
||||
var response = await client.GetAsync("http://localhost/ProducesContentOnClass/ReturnClassNameContentTypeOnDerivedAction");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
[Fact]
|
||||
|
@ -194,16 +200,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/json;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
|
||||
var expectedBody = "{\"MethodName\":\"Produces_WithNonObjectResult\"}";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/JsonResult/Produces_WithNonObjectResult");
|
||||
var response = await client.GetAsync("http://localhost/JsonResult/Produces_WithNonObjectResult");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -212,16 +218,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/json;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
|
||||
var expectedBody = "{\"MethodName\":\"ReturnJsonResult\"}";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/JsonResult/ReturnJsonResult");
|
||||
var response = await client.GetAsync("http://localhost/JsonResult/ReturnJsonResult");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -230,16 +236,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/custom-json;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/custom-json;charset=utf-8");
|
||||
var expectedBody = "{ MethodName = ReturnJsonResult_WithCustomMediaType }";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/JsonResult/ReturnJsonResult_WithCustomMediaType");
|
||||
var response = await client.GetAsync("http://localhost/JsonResult/ReturnJsonResult_WithCustomMediaType");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -248,16 +254,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/json;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
|
||||
var expectedBody = "{\"MethodName\":\"ReturnJsonResult_WithCustomMediaType_NoFormatter\"}";
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/JsonResult/ReturnJsonResult_WithCustomMediaType_NoFormatter");
|
||||
var response = await client.GetAsync("http://localhost/JsonResult/ReturnJsonResult_WithCustomMediaType_NoFormatter");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#if NET45
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using AutofacWebSite;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Xunit;
|
||||
|
||||
|
@ -20,20 +19,19 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
// Arrange
|
||||
var provider = TestHelper.CreateServices("AutofacWebSite");
|
||||
Action<IBuilder> app = new Startup().Configure;
|
||||
TestServer server = null;
|
||||
HttpResponse response = null;
|
||||
HttpResponseMessage response = null;
|
||||
|
||||
// Act & Assert
|
||||
await Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
// This essentially calls into the Startup.Configuration method
|
||||
server = TestServer.Create(provider, app);
|
||||
var server = TestServer.Create(provider, app);
|
||||
|
||||
// Make a request to start resolving DI pieces
|
||||
response = await server.Handler.GetAsync(url);
|
||||
response = await server.CreateClient().GetAsync(url);
|
||||
});
|
||||
|
||||
var actualResponseBody = new StreamReader(response.Body).ReadToEnd();
|
||||
var actualResponseBody = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedResponseBody, actualResponseBody);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
|
@ -21,13 +20,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
var expected = @"Hello Person1";
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Directives/ViewInheritsInjectAndUsingsFromViewStarts");
|
||||
var body = await client.GetStringAsync("http://localhost/Directives/ViewInheritsInjectAndUsingsFromViewStarts");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
|
||||
|
@ -36,15 +34,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
var expected = @"WriteLiteral says:layout:Write says:Write says:Hello Person2";
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Directives/ViewInheritsBasePageFromViewStarts");
|
||||
var body = await client.GetStringAsync("http://localhost/Directives/ViewInheritsBasePageFromViewStarts");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||
{
|
||||
// This class contains methods to make easier to read responses in different formats
|
||||
// until there is a built-in easier way to do it.
|
||||
public static class HttpResponseHelpers
|
||||
{
|
||||
public static async Task<string> ReadBodyAsStringAsync(this HttpResponse response)
|
||||
{
|
||||
using (var streamReader = new StreamReader(response.Body))
|
||||
{
|
||||
return await streamReader.ReadToEndAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,20 +2,13 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using InlineConstraints;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.Fallback;
|
||||
using Microsoft.Framework.Runtime;
|
||||
using Microsoft.Framework.Runtime.Infrastructure;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||
|
@ -24,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
private readonly IServiceProvider _provider;
|
||||
private readonly Action<IBuilder> _app = new Startup().Configure;
|
||||
|
||||
|
||||
public InlineConstraintTests()
|
||||
{
|
||||
_provider = TestHelper.CreateServices("InlineConstraintsWebSite");
|
||||
|
@ -37,20 +30,20 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction()
|
||||
{
|
||||
var svc = _provider.GetService<ICommandLineArgumentBuilder>();
|
||||
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue="+
|
||||
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue=" +
|
||||
"{area:exists}/{controller=Home}/{action=Index}");
|
||||
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue="+
|
||||
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue=" +
|
||||
"{controller=Home}/{action=Index}");
|
||||
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/Users");
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
var response = await client.GetAsync("http://localhost/Users");
|
||||
|
||||
// Assert
|
||||
var returnValue = await result.ReadBodyAsStringAsync();
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
var returnValue = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal("Users.Index", returnValue);
|
||||
}
|
||||
|
||||
|
@ -59,17 +52,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var svc = _provider.GetService<ICommandLineArgumentBuilder>();
|
||||
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue="+
|
||||
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue=" +
|
||||
"{area}/{controller=Home}/{action=Index}");
|
||||
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue"+
|
||||
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue" +
|
||||
"={controller=Home}/{action=Index}");
|
||||
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act & Assert
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>
|
||||
(async () => await client.GetAsync("http://localhost/Users"));
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => client.GetAsync("http://localhost/Users"));
|
||||
|
||||
Assert.Equal("The view 'Index' was not found." +
|
||||
" The following locations were searched:\r\n/Areas/Users/Views/Home/Index.cshtml\r\n" +
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
// 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.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
|
@ -12,30 +16,26 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
public class InputFormatterTests
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IServiceProvider _services = TestHelper.CreateServices("FormatterWebSite");
|
||||
private readonly Action<IBuilder> _app = new FormatterWebSite.Startup().Configure;
|
||||
|
||||
public InputFormatterTests()
|
||||
{
|
||||
_services = TestHelper.CreateServices("FormatterWebSite");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CheckIfXmlInputFormatterIsBeingCalled()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var sampleInputInt = 10;
|
||||
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<DummyClass><SampleInt>" + sampleInputInt.ToString() + "</SampleInt></DummyClass>";
|
||||
var content = new StringContent(input, Encoding.UTF8, "application/xml");
|
||||
|
||||
// Act
|
||||
var response = await client.PostAsync("http://localhost/Home/Index", input, "application/xml");
|
||||
var response = await client.PostAsync("http://localhost/Home/Index", content);
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(sampleInputInt.ToString(), await response.ReadBodyAsStringAsync());
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(sampleInputInt.ToString(), await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -48,16 +48,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var sampleInputInt = 10;
|
||||
var input = "{\"SampleInt\":10}";
|
||||
var content = new StringContent(input, Encoding.UTF8, requestContentType);
|
||||
|
||||
// Act
|
||||
var response = await client.PostAsync("http://localhost/Home/Index", input, requestContentType);
|
||||
var response = await client.PostAsync("http://localhost/Home/Index", content);
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(sampleInputInt.ToString(), await response.ReadBodyAsStringAsync());
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(sampleInputInt.ToString(), await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -71,24 +72,27 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
[InlineData("invalid", false)]
|
||||
[InlineData("application/custom", false)]
|
||||
[InlineData("image/jpg", false)]
|
||||
public async Task ModelStateErrorValidation_NoInputFormatterFound_ForGivenContetType(string requestContentType,
|
||||
bool filterHandlesModelStateError)
|
||||
public async Task ModelStateErrorValidation_NoInputFormatterFound_ForGivenContentType(string requestContentType,
|
||||
bool filterHandlesModelStateError)
|
||||
{
|
||||
// Arrange
|
||||
var actionName = filterHandlesModelStateError ? "ActionFilterHandlesError" : "ActionHandlesError";
|
||||
var expectedSource = filterHandlesModelStateError ? "filter" : "action";
|
||||
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
var input = "{\"SampleInt\":10}";
|
||||
var content = new StringContent(input);
|
||||
content.Headers.Clear();
|
||||
content.Headers.TryAddWithoutValidation("Content-Type", requestContentType);
|
||||
|
||||
// Act
|
||||
var response = await client.PostAsync("http://localhost/InputFormatter/" + actionName,
|
||||
input,
|
||||
requestContentType,
|
||||
(request) => request.Accept = "application/json");
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/InputFormatter/" + actionName);
|
||||
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
request.Content = content;
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
var responseBody = await response.ReadBodyAsStringAsync();
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<FormatterWebSite.ErrorInfo>(responseBody);
|
||||
|
||||
// Assert
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
|
@ -11,27 +12,22 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
public class ModelBindingTests
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IServiceProvider _services = TestHelper.CreateServices("ModelBindingWebSite");
|
||||
private readonly Action<IBuilder> _app = new ModelBindingWebSite.Startup().Configure;
|
||||
|
||||
public ModelBindingTests()
|
||||
{
|
||||
_services = TestHelper.CreateServices("ModelBindingWebSite");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ModelBindingBindsBase64StringsToByteArrays()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/Index?byteValues=SGVsbG9Xb3JsZA==");
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal("HelloWorld", await response.ReadBodyAsStringAsync());
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("HelloWorld", await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -39,14 +35,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/Index?byteValues=");
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal("\0", await response.ReadBodyAsStringAsync());
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("\0", await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
// 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.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using ConnegWebsite;
|
||||
using Microsoft.AspNet.Builder;
|
||||
|
@ -24,16 +26,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "text/plain;charset=utf-8";
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("text/plain;charset=utf-8");
|
||||
var expectedBody = actionName;
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/TextPlain/" + actionName);
|
||||
var response = await client.GetAsync("http://localhost/TextPlain/" + actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
}
|
||||
|
||||
|
@ -44,41 +46,36 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var expectedContentType = "application/json;charset=utf-8";
|
||||
var expectedBody = actionName;
|
||||
var client = server.CreateClient();
|
||||
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/TextPlain/" + actionName);
|
||||
var response = await client.GetAsync("http://localhost/TextPlain/" + actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("ReturnTaskOfString_NullValue")]
|
||||
[InlineData("ReturnTaskOfObject_NullValue")]
|
||||
[InlineData("ReturnTaskOfObject_NullValue")]
|
||||
[InlineData("ReturnObject_NullValue")]
|
||||
public async Task NoContentFormatter_ForNullValue_GetsSelectedAndWritesResponse(string actionName)
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
string expectedContentType = null;
|
||||
|
||||
// ReadBodyAsString returns empty string instead of null.
|
||||
string expectedBody = "";
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/NoContent/" + actionName);
|
||||
var response = await client.GetAsync("http://localhost/NoContent/" + actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContentType, result.HttpContext.Response.ContentType);
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expectedBody, body);
|
||||
Assert.Equal(204, result.HttpContext.Response.StatusCode);
|
||||
Assert.Equal(0, result.HttpContext.Response.ContentLength);
|
||||
Assert.Null(response.Content.Headers.ContentType);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
// Response body is empty instead of null.
|
||||
Assert.Empty(body);
|
||||
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
|
||||
Assert.Equal(0, response.Content.Headers.ContentLength);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,40 +4,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||
{
|
||||
public class RoutingTests
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IServiceProvider _services = TestHelper.CreateServices("RoutingWebSite");
|
||||
private readonly Action<IBuilder> _app = new RoutingWebSite.Startup().Configure;
|
||||
|
||||
public RoutingTests()
|
||||
{
|
||||
_services = TestHelper.CreateServices("RoutingWebSite");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConventionRoutedController_ActionIsReachable()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/Index");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Home/Index", result.ExpectedUrls);
|
||||
|
@ -57,15 +53,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/", result.ExpectedUrls);
|
||||
|
@ -85,13 +81,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/NotAnAction");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(404, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -99,15 +95,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Travel/Flight/Index");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Travel/Flight/Index", result.ExpectedUrls);
|
||||
|
@ -128,13 +124,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Travel/Flight/BuyTickets");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(404, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -142,15 +138,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Store/Shop/Products");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Store/Shop/Products", result.ExpectedUrls);
|
||||
|
@ -172,13 +168,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Store/ListProducts");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(404, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
|
||||
// There's two actions at this URL - but attribute routes go in the route table
|
||||
|
@ -188,15 +184,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/About");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Home/About", result.ExpectedUrls);
|
||||
|
@ -209,15 +205,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Blog/Edit/5");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Blog/Edit/5", result.ExpectedUrls);
|
||||
|
@ -243,15 +239,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/api/Employee");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -268,15 +264,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync(verb, "http://localhost/api/Employee");
|
||||
var message = new HttpRequestMessage(new HttpMethod(verb), "http://localhost/api/Employee");
|
||||
var response = await client.SendAsync(message);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -290,15 +287,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("MERGE", "http://localhost/api/Employee/5");
|
||||
var message = new HttpRequestMessage(new HttpMethod("MERGE"), "http://localhost/api/Employee/5");
|
||||
var response = await client.SendAsync(message);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -315,15 +313,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync(verb, "http://localhost/api/Employee/5/Administrator");
|
||||
var message = new HttpRequestMessage(new HttpMethod(verb), "http://localhost/api/Employee/5/Administrator");
|
||||
var response = await client.SendAsync(message);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/api/Employee/5/Administrator", result.ExpectedUrls);
|
||||
|
@ -340,15 +339,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Manager/5");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Manager/5", result.ExpectedUrls);
|
||||
|
@ -365,15 +364,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Team/5");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Team/5", result.ExpectedUrls);
|
||||
|
@ -390,15 +389,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Teams");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/Teams", result.ExpectedUrls);
|
||||
|
@ -411,7 +410,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetStringAsync("http://localhost/Organization/5");
|
||||
|
@ -426,7 +425,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetStringAsync("http://localhost/Teams/AllTeams");
|
||||
|
@ -441,15 +440,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/api/Employee").To(new { });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -464,15 +463,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/api/Employee").To(new { action = "Get", id = 5 });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -487,16 +486,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/api/Employee").To(new { action = "ShowPosts", controller = "Blog" });
|
||||
var response = await client.GetAsync(url);
|
||||
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -511,15 +510,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/api/Employee").To(new { action = "Index", controller = "Home" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -536,14 +535,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync(method, "http://localhost/api/Company/5");
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
var message = new HttpRequestMessage(new HttpMethod(method), "http://localhost/api/Company/5");
|
||||
var response = await client.SendAsync(message);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -559,14 +559,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("DELETE", "http://localhost/api/Company/5");
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
var response = await client.DeleteAsync("http://localhost/api/Company/5");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -582,17 +582,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
var url = LinkFrom("http://localhost")
|
||||
.To(new { id = 5 });
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("GET", "http://localhost/api/Company/5/Employees");
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
var response = await client.GetAsync("http://localhost/api/Company/5/Employees");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -608,14 +608,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("GET", "http://localhost/api/Company/5/Departments");
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
var response = await client.GetAsync("http://localhost/api/Company/5/Departments");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -635,13 +635,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
var expectedMessage = "The supplied route name 'DuplicateRoute' is ambiguous and matched more than one route.";
|
||||
|
||||
// Act
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||
await client.SendAsync("GET", url));
|
||||
await client.GetAsync(url));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedMessage, ex.Message);
|
||||
|
@ -652,16 +652,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/")
|
||||
.To(new { action = "BuyTickets", controller = "Flight", area = "Travel" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -676,15 +676,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/Travel/Flight").To(new { action = "BuyTickets" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -699,15 +699,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/Travel/Flight").To(new { action = "Index", controller = "Home", area = "" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -722,15 +722,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/Travel/Flight").To(new { action = "Contact", controller = "Home", });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -745,16 +745,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/api/Employee")
|
||||
.To(new { action = "Schedule", controller = "Rail", area = "Travel" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -769,15 +769,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/ContosoCorp/Trains/CheckSchedule").To(new { action = "Index" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -792,16 +792,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/ContosoCorp/Trains/CheckSchedule")
|
||||
.To(new { action = "Index", controller = "Home", area = "" });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -816,16 +816,16 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/ContosoCorp/Trains")
|
||||
.To(new { action = "Contact", controller = "Home", });
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -840,17 +840,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/ContosoCorp/Trains")
|
||||
.To(new { action = "Index", controller = "Flight", });
|
||||
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -865,17 +865,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/Travel/Flight")
|
||||
.To(new { action = "Index", controller = "Rail", });
|
||||
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -890,17 +890,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/Travel/Flight")
|
||||
.To(new { action = "ListUsers", controller = "UserManagement", area = "Admin" });
|
||||
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -915,17 +915,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url = LinkFrom("http://localhost/ContosoCorp/Trains")
|
||||
.To(new { action = "ListUsers", controller = "UserManagement", area = "Admin" });
|
||||
|
||||
var response = await client.GetAsync(url);
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -940,15 +940,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/api/Products/US/GetProducts");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
Assert.Contains("/api/Products/US/GetProducts", result.ExpectedUrls);
|
||||
|
@ -970,13 +970,13 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Products/GetProducts");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(404, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -984,7 +984,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url =
|
||||
|
@ -992,7 +992,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
.To(new { action = "GetProducts", controller = "Products", country = "US" });
|
||||
var response = await client.GetAsync(url);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -1004,7 +1004,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url =
|
||||
|
@ -1012,7 +1012,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
.To(new { action = "GetProducts", controller = "Products", country = "CA" });
|
||||
var response = await client.GetAsync(url);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
@ -1024,7 +1024,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var url =
|
||||
|
@ -1032,7 +1032,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
.To(new { action = "GetProducts", controller = "Products", country = (string)null });
|
||||
var response = await client.GetAsync(url);
|
||||
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
|
||||
|
||||
// Assert
|
||||
|
|
|
@ -3,35 +3,29 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ValueProvidersSite;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using ValueProvidersSite;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||
{
|
||||
public class ValueProviderTest
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IServiceProvider _services = TestHelper.CreateServices("ValueProvidersSite");
|
||||
private readonly Action<IBuilder> _app = new Startup().Configure;
|
||||
|
||||
public ValueProviderTest()
|
||||
{
|
||||
_services = TestHelper.CreateServices("ValueProvidersSite");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ValueProviderFactories_AreVisitedInSequentialOrder_ForValueProviders()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/TestValueProvider?test=not-test-value");
|
||||
var body = await client.GetStringAsync("http://localhost/Home/TestValueProvider?test=not-test-value");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("custom-value-provider-value", body.Trim());
|
||||
}
|
||||
|
||||
|
@ -40,13 +34,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/DefaultValueProviders?test=query-value");
|
||||
var body = await client.GetStringAsync("http://localhost/Home/DefaultValueProviders?test=query-value");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("query-value", body.Trim());
|
||||
}
|
||||
|
||||
|
@ -55,13 +48,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/RouteTest/route-value");
|
||||
var body = await client.GetStringAsync("http://localhost/RouteTest/route-value");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("route-value", body.Trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,13 +57,12 @@ ViewWithNestedLayout-Content
|
|||
public async Task RazorView_ExecutesPageAndLayout(string actionName, string expected)
|
||||
{
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/ViewEngine/" + actionName);
|
||||
var body = await client.GetStringAsync("http://localhost/ViewEngine/" + actionName);
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
|
||||
|
@ -76,13 +75,12 @@ ViewWithNestedLayout-Content
|
|||
</partial>
|
||||
test-value";
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/ViewEngine/ViewWithPartial");
|
||||
var body = await client.GetStringAsync("http://localhost/ViewEngine/ViewWithPartial");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
|
||||
|
@ -95,13 +93,12 @@ test-value";
|
|||
partial-content
|
||||
component-content";
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.Handler;
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await client.GetAsync("http://localhost/ViewEngine/ViewPassesViewDataToLayout");
|
||||
var body = await client.GetStringAsync("http://localhost/ViewEngine/ViewPassesViewDataToLayout");
|
||||
|
||||
// Assert
|
||||
var body = await result.HttpContext.Response.ReadBodyAsStringAsync();
|
||||
Assert.Equal(expected, body.Trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
|
@ -27,20 +28,19 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var headers = new Dictionary<string, string[]>();
|
||||
headers.Add("Accept", new string[] { "application/xml;charset=utf-8" });
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("POST",
|
||||
"http://localhost/Home/GetDummyClass?sampleInput=10", headers, null, null);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Home/GetDummyClass?sampleInput=10");
|
||||
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
||||
"xmlns=\"http://schemas.datacontract.org/2004/07/FormatterWebSite\">" +
|
||||
"<SampleInt>10</SampleInt></DummyClass>",
|
||||
new StreamReader(response.Body, Encoding.UTF8).ReadToEnd());
|
||||
await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -48,19 +48,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var headers = new Dictionary<string, string[]>();
|
||||
headers.Add("Accept", new string[] { "application/xml;charset=utf-8" });
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("POST",
|
||||
"http://localhost/XmlSerializer/GetDummyClass?sampleInput=10", headers, null, null);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/XmlSerializer/GetDummyClass?sampleInput=10");
|
||||
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("<DummyClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
||||
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><SampleInt>10</SampleInt></DummyClass>",
|
||||
new StreamReader(response.Body, Encoding.UTF8).ReadToEnd());
|
||||
await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -68,20 +67,20 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
var headers = new Dictionary<string, string[]>();
|
||||
headers.Add("Accept", new string[] { "application/xml;charset=utf-8" });
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync("POST",
|
||||
"http://localhost/DataContractSerializer/GetPerson?name=HelloWorld", headers, null, null);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post,
|
||||
"http://localhost/DataContractSerializer/GetPerson?name=HelloWorld");
|
||||
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
//Assert
|
||||
Assert.Equal(200, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("<Person xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
||||
"xmlns=\"http://schemas.datacontract.org/2004/07/FormatterWebSite\">" +
|
||||
"<Name>HelloWorld</Name></Person>",
|
||||
new StreamReader(response.Body, Encoding.UTF8).ReadToEnd());
|
||||
await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,9 @@ namespace BasicWebSite.Controllers
|
|||
|
||||
public async Task ActionReturningTask()
|
||||
{
|
||||
// TODO: #1077. With HttpResponseMessage, there seems to be a race between the write operation setting the
|
||||
// header to 200 and NoContentResult returned by the action invoker setting it to 204.
|
||||
Context.Response.StatusCode = 204;
|
||||
await Context.Response.WriteAsync("Hello world");
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче