// 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.Collections.Generic; using System.Reflection; using System.Threading.Tasks; using LocalizationWebSite; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Testing; using Microsoft.Framework.DependencyInjection; using Microsoft.Net.Http.Headers; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class LocalizationTest { private const string SiteName = nameof(LocalizationWebSite); private static readonly Assembly _assembly = typeof(LocalizationTest).GetTypeInfo().Assembly; private readonly Action _app = new Startup().Configure; private readonly Action _configureServices = new Startup().ConfigureServices; public static IEnumerable LocalizationData { get { var expected1 = @" en-gb-index partial mypartial "; yield return new[] { "en-GB", expected1 }; var expected2 = @" fr-index fr-partial mypartial "; yield return new[] { "fr", expected2 }; if (!TestPlatformHelper.IsMono) { // https://github.com/aspnet/Mvc/issues/2759 var expected3 = @" index partial mypartial "; yield return new[] { "!-invalid-!", expected3 }; } } } [Theory] [MemberData(nameof(LocalizationData))] public async Task Localization_SuffixViewName(string value, string expected) { // Arrange var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var client = server.CreateClient(); var cultureCookie = "c=" + value + "|uic=" + value; client.DefaultRequestHeaders.Add( "Cookie", new CookieHeaderValue("ASPNET_CULTURE", cultureCookie).ToString()); // Act var body = await client.GetStringAsync("http://localhost/"); // Assert Assert.Equal(expected, body.Trim(), ignoreLineEndingDifferences: true); } } }