-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add functional test for LocalizationSample * fixed path for JsonStringSerializer * test: add more functional tests, LocalizatinSample.Mvc * Remove unnecessary functional test project * Fix culture querystring * Add cookie to HttpClient header * Revert JsonStringLocalizer changes * Revert LocalizationSample/Program changes Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
- Loading branch information
1 parent
17fe21a
commit b14339e
Showing
6 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace My.Extensions.Localization.Json.Internal | ||
{ | ||
public static class PathHelpers | ||
{ | ||
// http://codebuckets.com/2017/10/19/getting-the-root-directory-path-for-net-core-applications/ | ||
public static string GetApplicationRoot() | ||
{ | ||
var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); | ||
var appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)"); | ||
var appRoot = appPathMatcher.Match(exePath).Value; | ||
|
||
return appRoot; | ||
} | ||
=> Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/My.Extensions.Localization.Json.FunctionalTests/LocalizationMvcSampleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Localization; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Xunit; | ||
|
||
namespace LocalizationSample.Mvc.FunctionalTest | ||
{ | ||
public class LocalizationMvcSampleTests : IClassFixture<WebApplicationFactory<Startup>> | ||
{ | ||
private readonly HttpClient _client; | ||
|
||
public LocalizationMvcSampleTests(WebApplicationFactory<Startup> factory) | ||
{ | ||
_client = factory.CreateClient(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("en-US", "Privacy Policy")] | ||
[InlineData("fr-FR", "Politique de confidentialité")] | ||
public async Task LocalizePrivacyView(string culture, string expected) | ||
{ | ||
// Arrange | ||
var url = "/Home/Privacy"; | ||
var request = new HttpRequestMessage(HttpMethod.Get, url); | ||
var cookieValue = $"c={culture}|uic={culture}"; | ||
request.Headers.Add("Cookie", $"{CookieRequestCultureProvider.DefaultCookieName}={cookieValue}"); | ||
|
||
// Act | ||
var response = await _client.SendAsync(request); | ||
var content = await response.Content.ReadAsStringAsync(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.Contains(expected, content); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
....Localization.Json.FunctionalTests/My.Extensions.Localization.Json.FunctionalTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.2" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="Moq" Version="4.13.1" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\samples\LocalizationSample.Mvc\LocalizationSample.Mvc.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters