예제 #1
0
        public async void ReturnsCorrectSupportedForUnConfiguredFallbackLanguage(string expected, string fallBackLanguage, string supported, string acceptable)
        {
            var context = new ApiRequestContext
            {
                Configuration = new DeepSleepRequestConfiguration
                {
                    LanguageSupport = new ApiLanguageSupportConfiguration
                    {
                        FallBackLanguage   = fallBackLanguage,
                        SupportedLanguages = supported?.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                    }
                },
                Request = new ApiRequestInfo
                {
                    AcceptCulture  = new CultureInfo("ru"),
                    AcceptLanguage = acceptable
                }
            };


            var processed = await context.ProcessHttpRequestLocalization().ConfigureAwait(false);

            processed.Should().BeTrue();
            context.Request.AcceptCulture.Name.Should().Be(expected);

            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
        }
예제 #2
0
        public async void ReturnsFalseForCancelledRequest()
        {
            var set = new CultureInfo("es");

            CultureInfo.CurrentCulture   = set;
            CultureInfo.CurrentUICulture = set;

            var currentCultureCode   = CultureInfo.CurrentCulture.Name;
            var currentUiCultureCode = CultureInfo.CurrentUICulture.Name;

            var context = new ApiRequestContext
            {
                RequestAborted = new System.Threading.CancellationToken(true)
            };

            var processed = await context.ProcessHttpRequestLocalization().ConfigureAwait(false);

            processed.Should().BeFalse();

            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();

            CultureInfo.CurrentCulture.Name.Should().Be(currentCultureCode);
            CultureInfo.CurrentUICulture.Name.Should().Be(currentUiCultureCode);
        }
예제 #3
0
        public async void ReturnsEnUsForUnConfiguredFallbackLanguage()
        {
            var set = new CultureInfo("es");

            CultureInfo.CurrentCulture   = set;
            CultureInfo.CurrentUICulture = set;

            var context   = new ApiRequestContext();
            var processed = await context.ProcessHttpRequestLocalization().ConfigureAwait(false);

            processed.Should().BeTrue();
            context.Request.AcceptCulture.Name.Should().Be("es");

            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeNull();
        }