Minor Fixes

Remove the blank line before conditional block

Remove versions from project.json in test projects

Address feedback

Address feedback

Add CommandLine configuration package to avoid breaking test

Add missing using
This commit is contained in:
hishamco 2016-11-07 07:56:00 +03:00
parent ed9a0d28bf
commit 40e54bf77d
15 changed files with 34 additions and 15 deletions

View File

@ -155,7 +155,9 @@ $@"<!doctype html>
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()

View File

@ -19,6 +19,5 @@ namespace Microsoft.AspNetCore.Localization
/// <inheritdoc />
public abstract Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext);
}
}

View File

@ -14,7 +14,7 @@ using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Localization
{
/// <summary>
/// Enables automatic setting of the culture for <see cref="Http.HttpRequest"/>s based on information
/// Enables automatic setting of the culture for <see cref="HttpRequest"/>s based on information
/// sent by the client in headers and logic provided by the application.
/// </summary>
public class RequestLocalizationMiddleware

View File

@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Localization
/// <summary>
/// Provides strings for <typeparamref name="TResourceSource"/>.
/// </summary>
/// <typeparam name="TResourceSource">The <see cref="System.Type"/> to provide strings for.</typeparam>
/// <typeparam name="TResourceSource">The <see cref="Type"/> to provide strings for.</typeparam>
public class StringLocalizer<TResourceSource> : IStringLocalizer<TResourceSource>
{
private IStringLocalizer _localizer;

View File

@ -15,8 +15,6 @@ namespace Microsoft.Extensions.Localization.Internal
public class AssemblyResourceStringProvider : IResourceStringProvider
{
private const string AssemblyElementDelimiter = ", ";
private static readonly string[] _assemblyElementDelimiterArray = new[] { AssemblyElementDelimiter };
private static readonly char[] _assemblyEqualDelimiter = new[] { '=' };
private readonly AssemblyWrapper _assembly;
private readonly string _resourceBaseName;
@ -65,6 +63,7 @@ namespace Microsoft.Extensions.Localization.Internal
public IList<string> GetAllResourceStrings(CultureInfo culture, bool throwOnMissing)
{
var cacheKey = GetResourceCacheKey(culture);
return _resourceNamesCache.GetOrAdd(cacheKey, _ =>
{
var assembly = GetAssembly(culture);

View File

@ -106,6 +106,7 @@ namespace Microsoft.Extensions.Localization
}
var value = GetStringSafely(name, null);
return new LocalizedString(name, value ?? name, resourceNotFound: value == null);
}
}
@ -122,6 +123,7 @@ namespace Microsoft.Extensions.Localization
var format = GetStringSafely(name, null);
var value = string.Format(format ?? name, arguments);
return new LocalizedString(name, value, resourceNotFound: format == null);
}
}

View File

@ -117,6 +117,7 @@ namespace Microsoft.Extensions.Localization
}
var value = GetStringSafely(name, _culture);
return new LocalizedString(name, value ?? name);
}
}
@ -133,6 +134,7 @@ namespace Microsoft.Extensions.Localization
var format = GetStringSafely(name, _culture);
var value = string.Format(_culture, format ?? name, arguments);
return new LocalizedString(name, value ?? name, resourceNotFound: format == null);
}
}

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// 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.
namespace LocalizationWebsite.Models
{

View File

@ -19,6 +19,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task RunSite_WindowsOnly()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponseHeading(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,
@ -27,10 +28,12 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
"fr-FR",
"<h1>Bonjour</h1>");
}
[Fact]
public Task RunSite_AnyOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponseHeading(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,

View File

@ -17,6 +17,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_CustomCulture_AllOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,
@ -32,6 +33,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_CustomCulture_Windows()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,
@ -45,6 +47,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInClassLibrary_ReturnLocalizedValue_AllOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,
@ -60,6 +63,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInClassLibrary_ReturnLocalizedValue_Windows()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,
@ -73,6 +77,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_AllOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,
@ -88,6 +93,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_Windows()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,
@ -101,6 +107,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_AllOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,
@ -116,6 +123,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInFolder_ReturnLocalizedValue_WithCultureFallback_Windows()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,
@ -129,6 +137,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInFolder_ReturnNonLocalizedValue_CultureHierarchyTooDeep_AllOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,
@ -144,6 +153,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesInFolder_ReturnNonLocalizedValue_CultureHierarchyTooDeep_Windows()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,
@ -157,6 +167,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_AllOS()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64,
@ -172,6 +183,7 @@ namespace Microsoft.AspNetCore.Localization.FunctionalTests
public Task Localization_ResourcesAtRootFolder_ReturnLocalizedValue_Windows()
{
var testRunner = new TestRunner(_applicationPath);
return testRunner.RunTestAndVerifyResponse(
RuntimeFlavor.Clr,
RuntimeArchitecture.x64,

View File

@ -106,6 +106,7 @@ namespace Microsoft.AspNetCore.Localization.Routing
{
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
var requestCulture = requestCultureFeature.RequestCulture;
return context.Response.WriteAsync(
$"{requestCulture.Culture.Name},{requestCulture.UICulture.Name}");
});
@ -168,6 +169,7 @@ namespace Microsoft.AspNetCore.Localization.Routing
{
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
var requestCulture = requestCultureFeature.RequestCulture;
return context.Response.WriteAsync(
$"{requestCulture.Culture.Name},{requestCulture.UICulture.Name}");
});

View File

@ -137,6 +137,7 @@ namespace Microsoft.Extensions.Localization.Tests
{
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
var requestCulture = requestCultureFeature.RequestCulture;
Assert.Equal("ar-YE", requestCulture.Culture.Name);
Assert.Equal("ar-YE", requestCulture.UICulture.Name);
return Task.FromResult(0);

View File

@ -93,6 +93,7 @@ namespace Microsoft.Extensions.Localization.Tests
using (var server = new TestServer(builder))
{
var client = server.CreateClient();
client.DefaultRequestHeaders.Add("Cookie", new CookieHeaderValue("Preferences", "uic=ar-SA").ToString());
var response = await client.GetAsync(string.Empty);
}

View File

@ -273,6 +273,7 @@ namespace Microsoft.Extensions.Localization.Tests
}
};
var provider = new QueryStringRequestCultureProvider();
provider.QueryStringKey = "c";
provider.UIQueryStringKey = "uic";
options.RequestCultureProviders.Insert(0, provider);

View File

@ -56,7 +56,6 @@ namespace Microsoft.Extensions.Localization.Tests
var resourceManager2 = new TestResourceManager(baseName, resourceAssembly2.Assembly);
var resourceStreamManager1 = new TestResourceStringProvider(resourceNamesCache, resourceAssembly1, baseName);
var resourceStreamManager2 = new TestResourceStringProvider(resourceNamesCache, resourceAssembly2, baseName);
var localizer1 = new ResourceManagerStringLocalizer(
resourceManager1,
resourceStreamManager1,
@ -194,17 +193,15 @@ namespace Microsoft.Extensions.Localization.Tests
public class TestAssemblyWrapper : AssemblyWrapper
{
private readonly string _name;
public TestAssemblyWrapper(string name = nameof(TestAssemblyWrapper))
: base(typeof(TestAssemblyWrapper).GetTypeInfo().Assembly)
{
_name = name;
FullName = name;
}
public int GetManifestResourceStreamCallCount { get; private set; }
public override string FullName => _name;
public override string FullName { get; }
public override Stream GetManifestResourceStream(string name)
{