public static TheoryData <IMvcBuilder> MvcBuilderExtensionsData()
        {
            var builder1 = new TestMvcBuilder();

            builder1.AddMvcLocalization();

            var builder2 = new TestMvcBuilder();

            builder2.AddMvcLocalization(LanguageViewLocationExpanderFormat.SubFolder);

            var builder3 = new TestMvcBuilder();

            builder3.AddMvcLocalization(localizationOptionsSetupAction: l => l.ResourcesPath = "Resources");

            var builder4 = new TestMvcBuilder();

            builder4.AddMvcLocalization(
                localizationOptionsSetupAction: l => l.ResourcesPath = "Resources",
                format: LanguageViewLocationExpanderFormat.SubFolder);

            return(new TheoryData <IMvcBuilder>()
            {
                builder1, builder2, builder3, builder4
            });
        }
        public void SetsLocalizationOptions_AsExpected()
        {
            // Arrange
            var builder = new TestMvcBuilder();

            // Act
            builder.AddMvcLocalization(
                localizationOptionsSetupAction: options => options.ResourcesPath = "TestResources");

            // Assert
            var serviceProvider = builder.Services.BuildServiceProvider();
            var actualOptions   = serviceProvider.GetRequiredService <IOptions <LocalizationOptions> >();

            Assert.Equal("TestResources", actualOptions.Value.ResourcesPath);
        }
Пример #3
0
        public void SetsDataAnnotationsOptions_AsExpected()
        {
            // Arrange
            var builder = new TestMvcBuilder();
            var dataAnnotationLocalizerProvider = new Func <Type, IStringLocalizerFactory, IStringLocalizer>((type, factory) =>
            {
                return(null);
            });

            // Act
            builder.AddMvcLocalization(
                dataAnnotationsLocalizationOptionsSetupAction: options
                => options.DataAnnotationLocalizerProvider = dataAnnotationLocalizerProvider);

            // Assert
            var serviceProvider = builder.Services.BuildServiceProvider();
            var actualOptions   = serviceProvider.GetRequiredService <IOptions <MvcDataAnnotationsLocalizationOptions> >();

            Assert.Same(dataAnnotationLocalizerProvider, actualOptions.Value.DataAnnotationLocalizerProvider);
        }