// 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; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.TestHost; using RazorWebSite; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class ViewEngineTests { private readonly IServiceProvider _provider = TestHelper.CreateServices("RazorWebSite"); private readonly Action _app = new Startup().Configure; public static IEnumerable RazorView_ExecutesPageAndLayoutData { get { yield return new[] { "ViewWithoutLayout", @"ViewWithoutLayout-Content" }; yield return new[] { "ViewWithLayout", @" ViewWithLayout-Content " }; yield return new[] { "ViewWithFullPath", @" ViewWithFullPath-content " }; yield return new[] { "ViewWithNestedLayout", @" /ViewEngine/ViewWithNestedLayout ViewWithNestedLayout-Content " }; } } [Theory] [MemberData("RazorView_ExecutesPageAndLayoutData")] public async Task RazorView_ExecutesPageAndLayout(string actionName, string expected) { var server = TestServer.Create(_provider, _app); var client = server.Handler; // Act var result = await client.GetAsync("http://localhost/ViewEngine/" + actionName); // Assert var body = await result.HttpContext.Response.ReadBodyAsStringAsync(); Assert.Equal(expected, body.Trim()); } [Fact] public async Task RazorView_ExecutesPartialPagesWithCorrectContext() { var expected = @"98052 test-value"; var server = TestServer.Create(_provider, _app); var client = server.Handler; // Act var result = await client.GetAsync("http://localhost/ViewEngine/ViewWithPartial"); // Assert var body = await result.HttpContext.Response.ReadBodyAsStringAsync(); Assert.Equal(expected, body.Trim()); } } }