public static TheoryData <IMvcCoreBuilder> MvcCoreBuilderExtensionsData() { var builder1 = new TestMvcCoreBuilder(); builder1.AddMvcLocalization(); var builder2 = new TestMvcCoreBuilder(); builder2.AddMvcLocalization(LanguageViewLocationExpanderFormat.SubFolder); var builder3 = new TestMvcCoreBuilder(); builder3.AddMvcLocalization(localizationOptionsSetupAction: l => l.ResourcesPath = "Resources"); var builder4 = new TestMvcCoreBuilder(); builder4.AddMvcLocalization( localizationOptionsSetupAction: l => l.ResourcesPath = "Resources", format: LanguageViewLocationExpanderFormat.SubFolder); return(new TheoryData <IMvcCoreBuilder>() { builder1, builder2, builder3, builder4 }); }
private void Initialize() { IServiceCollection services = new ServiceCollection(); IMvcCoreBuilder builder = new TestMvcCoreBuilder { Services = services }; builder.AddOData(); services.AddDbContext <MyDbContext> ( options => { options.UseInMemoryDatabase("MyDbContext"); options.UseInternalServiceProvider(new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider()); }, ServiceLifetime.Transient ) .AddSingleton <IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly))) .AddTransient <IMapper>(sp => new Mapper(sp.GetRequiredService <IConfigurationProvider>(), sp.GetService)) .AddTransient <IApplicationBuilder>(sp => new ApplicationBuilder(sp)) .AddRouting() .AddLogging(); serviceProvider = services.BuildServiceProvider(); MyDbContext context = serviceProvider.GetRequiredService <MyDbContext>(); context.Database.EnsureCreated(); DatabaseInitializer.SeedDatabase(context); }
public void SetsLocalizationOptions_AsExpected() { // Arrange var builder = new TestMvcCoreBuilder(); // 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); }
private void Initialize() { IServiceCollection services = new ServiceCollection(); IMvcCoreBuilder builder = new TestMvcCoreBuilder { Services = services }; builder.AddOData(); services.AddTransient <TestDbContext>(_ => new TestDbContext()) .AddSingleton <IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly))) .AddTransient <IMapper>(sp => new Mapper(sp.GetRequiredService <IConfigurationProvider>(), sp.GetService)) .AddTransient <IApplicationBuilder>(sp => new ApplicationBuilder(sp)) .AddRouting() .AddLogging(); serviceProvider = services.BuildServiceProvider(); }
public void SetsDataAnnotationsOptions_AsExpected() { // Arrange var builder = new TestMvcCoreBuilder(); 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); }