You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/samples/BookStore/test/Acme.BookStore.Web.Tests/BookStoreWebTestModule.cs

86 lines
2.9 KiB

using System.Collections.Generic;
using System.Globalization;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Acme.BookStore.Localization;
using Acme.BookStore.Web;
using Acme.BookStore.Web.Menus;
using Volo.Abp;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Localization;
using Volo.Abp.Localization.Resources.AbpValidation;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
namespace Acme.BookStore
{
[DependsOn(
typeof(AbpAspNetCoreTestBaseModule),
typeof(BookStoreWebModule),
typeof(BookStoreApplicationTestModule)
)]
public class BookStoreWebTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.PreConfigure<IMvcBuilder>(builder =>
{
builder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(BookStoreWebModule).Assembly));
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
ConfigureLocalizationServices(context.Services);
ConfigureNavigationServices(context.Services);
}
private static void ConfigureLocalizationServices(IServiceCollection services)
{
var cultures = new List<CultureInfo> { new CultureInfo("en"), new CultureInfo("tr") };
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new RequestCulture("en");
options.SupportedCultures = cultures;
options.SupportedUICultures = cultures;
});
services.Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<BookStoreResource>()
.AddBaseTypes(
typeof(AbpValidationResource),
typeof(AbpUiResource)
);
});
}
private static void ConfigureNavigationServices(IServiceCollection services)
{
services.Configure<NavigationOptions>(options =>
{
options.MenuContributors.Add(new BookStoreMenuContributor());
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
//app.UseErrorPage();
app.UseVirtualFiles();
app.UseAuthentication();
app.UseRequestLocalization(app.ApplicationServices.GetRequiredService<IOptions<RequestLocalizationOptions>>().Value);
app.UseMvcWithDefaultRouteAndArea();
}
}
}