public static void Setup(TestServiceProvider services, Action <CardOverflowDb> setupDb) { if (!services.IsProviderInitialized) { services.AddBlazoredToast(); services.AddScoped <NavigationManager, MockNavigationManager>(); services.AddBootstrapCss(); services.AddTransient <IValidator <FollowCommandViewModel>, FollowCommandViewModelValidator>(); services.AddSingleton <DbExecutor>(); services.AddSingleton <TimeProvider>(); services.AddSingleton <Scheduler>(); services.AddSingleton <RandomProvider>(); services.AddDbContextPool <CardOverflowDb>(x => x.UseInMemoryDatabase(Guid.NewGuid().ToString())); services.AddSingleton <Func <Task <NpgsqlConnection> > >(_ => async() => { var conn = new NpgsqlConnection("Host=localhost;Database=CardOverflow;Username=postgres;"); await conn.OpenAsync(); return(conn); }); } using var databaseContext = services.GetService <CardOverflowDb>(); databaseContext.Database.EnsureDeleted(); databaseContext.Database.EnsureCreated(); setupDb(databaseContext); databaseContext.SaveChanges(); foreach (var entity in databaseContext.ChangeTracker.Entries()) { entity.State = EntityState.Detached; } }
public static void AddBootstrapProviders(TestServiceProvider services) { services.AddSingleton <IIdGenerator>(new IdGenerator()); services.AddSingleton <IEditContextValidator>(new EditContextValidator(new ValidationMessageLocalizerAttributeFinder())); services.AddSingleton <IClassProvider>(new BootstrapClassProvider()); services.AddSingleton <IStyleProvider>(new BootstrapStyleProvider()); services.AddSingleton <IThemeGenerator>(new BootstrapThemeGenerator(new Mock <IThemeCache>().Object)); services.AddSingleton <IIconProvider>(new Mock <IIconProvider>().Object); services.AddSingleton <IValidationHandlerFactory, ValidationHandlerFactory>(); services.AddSingleton <ValidatorValidationHandler>(); services.AddSingleton <PatternValidationHandler>(); services.AddSingleton <DataAnnotationValidationHandler>(); services.AddSingleton <IDateTimeFormatConverter, DateTimeFormatConverter>(); services.AddSingleton <IVersionProvider, VersionProvider>(); services.AddScoped <ITextLocalizerService, TextLocalizerService>(); services.AddScoped(typeof(ITextLocalizer <>), typeof(TextLocalizer <>)); Action <BlazoriseOptions> configureOptions = (options) => { }; services.AddSingleton(configureOptions); services.AddSingleton <BlazoriseOptions>(); services.AddScoped <IJSUtilitiesModule, JSUtilitiesModule>(); services.AddScoped <IJSButtonModule, JSButtonModule>(); services.AddScoped <IJSClosableModule, JSClosableModule>(); services.AddScoped <IJSBreakpointModule, JSBreakpointModule>(); services.AddScoped <IJSTextEditModule, JSTextEditModule>(); services.AddScoped <IJSMemoEditModule, JSMemoEditModule>(); services.AddScoped <IJSNumericPickerModule, JSNumericPickerModule>(); services.AddScoped <IJSDatePickerModule, JSDatePickerModule>(); services.AddScoped <IJSTimePickerModule, JSTimePickerModule>(); services.AddScoped <IJSColorPickerModule, JSColorPickerModule>(); services.AddScoped <IJSFileEditModule, JSFileEditModule>(); services.AddScoped <IJSTableModule, JSTableModule>(); services.AddScoped <IJSSelectModule, JSSelectModule>(); services.AddScoped <IJSInputMaskModule, JSInputMaskModule>(); services.AddScoped <IJSModalModule, Bootstrap.Modules.BootstrapJSModalModule>(); services.AddScoped <IJSTooltipModule, Bootstrap.Modules.BootstrapJSTooltipModule>(); services.AddMemoryCache(); services.AddScoped <Blazorise.Shared.Data.EmployeeData>(); services.AddScoped <Blazorise.Shared.Data.CountryData>(); }