aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/IntegratedTests/I18nTest.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-25 18:46:01 +0800
committerGitHub <noreply@github.com>2019-10-25 18:46:01 +0800
commita175f8328d7a6c36464676d54fc50d03e64be0af (patch)
treec6ec0a916c78a02b36113fb62f0e919019df6cfc /Timeline.Tests/IntegratedTests/I18nTest.cs
parent681e2cc9ecaeefd883a7c6645374926c184fba5d (diff)
parent5790142f81f2a94ad073834b1534acbf9b02ea3c (diff)
downloadtimeline-a175f8328d7a6c36464676d54fc50d03e64be0af.tar.gz
timeline-a175f8328d7a6c36464676d54fc50d03e64be0af.tar.bz2
timeline-a175f8328d7a6c36464676d54fc50d03e64be0af.zip
Merge pull request #52 from crupest/i18n
Add NeutralResourcesLanguage. Conform to best practices.
Diffstat (limited to 'Timeline.Tests/IntegratedTests/I18nTest.cs')
-rw-r--r--Timeline.Tests/IntegratedTests/I18nTest.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/Timeline.Tests/IntegratedTests/I18nTest.cs b/Timeline.Tests/IntegratedTests/I18nTest.cs
new file mode 100644
index 00000000..67bbea5c
--- /dev/null
+++ b/Timeline.Tests/IntegratedTests/I18nTest.cs
@@ -0,0 +1,63 @@
+using Microsoft.AspNetCore.Mvc.Testing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using Timeline.Tests.Helpers;
+using Xunit;
+using FluentAssertions;
+
+namespace Timeline.Tests.IntegratedTests
+{
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1054:Uri parameters should not be strings")]
+ public class I18nTest : IClassFixture<WebApplicationFactory<Startup>>, IDisposable
+ {
+ private readonly TestApplication _testApp;
+ private readonly HttpClient _client;
+
+ public I18nTest(WebApplicationFactory<Startup> factory)
+ {
+ _testApp = new TestApplication(factory);
+ _client = _testApp.Factory.CreateDefaultClient();
+ }
+
+ public void Dispose()
+ {
+ _client.Dispose();
+ _testApp.Dispose();
+ }
+
+ private const string DirectUrl = "testing/i18n/direct";
+ private const string LocalizerUrl = "testing/i18n/localizer";
+
+ [Theory]
+ [InlineData(DirectUrl)]
+ [InlineData(LocalizerUrl)]
+ public async Task DefaultShouldReturnEnglish(string url)
+ {
+ (await _client.GetStringAsync(url)).Should().ContainEquivalentOf("English");
+ }
+
+ [Theory]
+ [InlineData(DirectUrl, "en", true)]
+ [InlineData(LocalizerUrl, "en", true)]
+ [InlineData(DirectUrl, "en-US", true)]
+ [InlineData(LocalizerUrl, "en-US", true)]
+ [InlineData(DirectUrl, "zh", false)]
+ [InlineData(LocalizerUrl, "zh", false)]
+ public async Task ShouldWork(string url, string acceptLanguage, bool english)
+ {
+ var request = new HttpRequestMessage
+ {
+ Method = HttpMethod.Get,
+ RequestUri = new Uri(url, UriKind.RelativeOrAbsolute)
+ };
+ request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(acceptLanguage));
+ var body = await (await _client.SendAsync(request)).Content.ReadAsStringAsync();
+ body.Should().ContainEquivalentOf(english ? "English" : "中文");
+ request.Dispose();
+ }
+ }
+}