using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.TestHost; using Newtonsoft.Json; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class JsonOutputFormatterTests { private readonly IServiceProvider _provider = TestHelper.CreateServices("FormatterWebSite"); private readonly Action _app = new FormatterWebSite.Startup().Configure; [Fact] public async Task JsonOutputFormatter_ReturnsIndentedJson() { // Arrange var user = new FormatterWebSite.User() { Id = 1, Alias = "john", description = "Administrator", Designation = "Administrator", Name = "John Williams" }; var serializerSettings = new JsonSerializerSettings(); serializerSettings.Formatting = Formatting.Indented; var expectedBody = JsonConvert.SerializeObject(user, serializerSettings); var server = TestServer.Create(_provider, _app); var client = server.CreateClient(); // Act var response = await client.GetAsync("http://localhost/JsonFormatter/ReturnsIndentedJson"); // Assert var actualBody = await response.Content.ReadAsStringAsync(); Assert.Equal(expectedBody, actualBody); } } }