aspnetcore/test/Microsoft.AspNet.Mvc.Functi.../RazorEmbeddedViewsTest.cs

50 lines
1.9 KiB
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
using RazorEmbeddedViewsWebSite;
using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class RazorEmbeddedViewsTest
{
private const string SiteName = nameof(RazorEmbeddedViewsWebSite);
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
[Fact]
public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateViews()
{
// Arrange
var expectedMessage = "Hello test-user, this is /RazorEmbeddedViews_Home";
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient();
// Act
var response = await client.GetStringAsync("http://localhost/RazorEmbeddedViews_Home?User=test-user");
// Assert
Assert.Equal(expectedMessage, response);
}
[Fact]
public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateAreaViews()
{
// Arrange
var expectedMessage = "Hello admin-user, this is /Restricted/RazorEmbeddedViews_Admin/Login";
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient();
var target = "http://localhost/Restricted/RazorEmbeddedViews_Admin/Login?AdminUser=admin-user";
// Act
var response = await client.GetStringAsync(target);
// Assert
Assert.Equal(expectedMessage, response);
}
}
}