当前位置: 首页>>代码示例>>C#>>正文


C# ServiceCollection.AddJsonLocalization方法代码示例

本文整理汇总了C#中Microsoft.Framework.DependencyInjection.ServiceCollection.AddJsonLocalization方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.AddJsonLocalization方法的具体用法?C# ServiceCollection.AddJsonLocalization怎么用?C# ServiceCollection.AddJsonLocalization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Framework.DependencyInjection.ServiceCollection的用法示例。


在下文中一共展示了ServiceCollection.AddJsonLocalization方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: json_collection_with_default_culture_test

        public void json_collection_with_default_culture_test()
        {
            // Arrange
            var req = new Mock<HttpRequest>();
            req.Setup(x => x.Headers)
                .Returns(new HeaderDictionary(new Dictionary<string, StringValues> { }));
            req.Setup(x => x.Cookies)
                .Returns(new RequestCookiesCollection());
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(x => x.Request)
                .Returns(req.Object);
            var accessor = new Mock<IHttpContextAccessor>();
            accessor.Setup(x => x.HttpContext)
                .Returns(httpContext.Object);

            var collection = new ServiceCollection();
            collection.AddJsonLocalization()
                .AddCookieCulture()
                .AddInstance(accessor.Object)
                .AddInstance(CallContextServiceLocator.Locator.ServiceProvider.GetRequiredService<IApplicationEnvironment>());

            var service = collection.BuildServiceProvider();

            // Act
            var SR = service.GetService<ILocalizationStringCollection>();
            var actual_1 = SR["Hello world."];
            var actual_2 = SR["My name is {0}.", "Yuuko"];

            // Assert
            Assert.Equal("你好,世界。", actual_1);
            Assert.Equal("我的名字是Yuuko", actual_2);
        }
开发者ID:CodeComb,项目名称:Localization,代码行数:32,代码来源:JsonCollectionTests.cs

示例2: add_string_and_remove_test

        public void add_string_and_remove_test()
        {
            // Arrange
            var req = new Mock<HttpRequest>();
            req.Setup(x => x.Headers)
                .Returns(new HeaderDictionary(new Dictionary<string, StringValues> { { "Accept-Language", new string[] { "writing-test" } } }));
            req.Setup(x => x.Cookies)
                .Returns(new RequestCookiesCollection());
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(x => x.Request)
                .Returns(req.Object);
            var accessor = new Mock<IHttpContextAccessor>();
            accessor.Setup(x => x.HttpContext)
                .Returns(httpContext.Object);

            var collection = new ServiceCollection();
            collection.AddJsonLocalization()
                .AddCookieCulture()
                .AddInstance(accessor.Object)
                .AddInstance(CallContextServiceLocator.Locator.ServiceProvider.GetRequiredService<IApplicationEnvironment>());

            var service = collection.BuildServiceProvider();

            // Act 1
            var SR = service.GetService<ILocalizationStringCollection>();
            SR.SetString("writing-test", "Test", "I am xUnit.");
            var actual_1 = SR["Test"];

            // Assert 1
            Assert.Equal("I am xUnit.", actual_1);

            // Act 2
            SR.RemoveString("Test");
            var actual_2 = SR["Test"];

            // Assert 2
            Assert.Equal("Test", actual_2);
        }
开发者ID:CodeComb,项目名称:Localization,代码行数:38,代码来源:JsonCollectionTests.cs


注:本文中的Microsoft.Framework.DependencyInjection.ServiceCollection.AddJsonLocalization方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。