Ejemplo n.º 1
0
        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 AddAuthenticationServices(this TestServiceProvider services, Task <AuthenticationState> initialAuthState = null, AuthorizationResult nextAuth = null)
 {
     if (nextAuth == null)
     {
         nextAuth = AuthorizationResult.Success();
     }
     services.AddSingleton <IAuthorizationService>(new TestAuthorizationService()
     {
         NextResult = nextAuth
     });
     services.AddSingleton <IAuthorizationPolicyProvider>(new TestAuthorizationPolicyProvider());
     services.AddSingleton <AuthenticationStateProvider>(new TestAuthenticationStateProvider(initialAuthState));
 }
Ejemplo n.º 3
0
        public static MockSignOutSessionStateManager AddSignOutManager(this TestServiceProvider services)
        {
            var mockSignOutManager = new MockSignOutSessionStateManager();

            services.AddSingleton <SignOutSessionStateManager>(mockSignOutManager);
            return(mockSignOutManager);
        }
Ejemplo n.º 4
0
        public static MockNavigationManager AddMockNavigationManager(this TestServiceProvider services, string path)
        {
            var mockNavigationManager = new MockNavigationManager(path);

            services.AddSingleton <NavigationManager>(mockNavigationManager);
            return(mockNavigationManager);
        }
Ejemplo n.º 5
0
        public static MockHttpMessageHandler AddMockHttpClient(this TestServiceProvider services)
        {
            var mockHttpHandler = new MockHttpMessageHandler();
            var httpClient      = mockHttpHandler.ToHttpClient();

            httpClient.BaseAddress = new Uri("http://localhost");
            services.AddSingleton(httpClient);
            return(mockHttpHandler);
        }
Ejemplo n.º 6
0
        public static void AddBootstrapProviders(TestServiceProvider services)
        {
            services.AddSingleton <IEditContextValidator>(new EditContextValidator(new ValidationMessageLocalizerAttributeFinder()));
            services.AddSingleton <IClassProvider>(new BootstrapClassProvider());
            services.AddSingleton <IStyleProvider>(new BootstrapStyleProvider());
            services.AddSingleton <IJSRunner>(new BootstrapJSRunner(new Mock <IJSRuntime>().Object));
            services.AddSingleton <IComponentMapper>(new ComponentMapper());
            services.AddSingleton <IThemeGenerator>(new BootstrapThemeGenerator());
            services.AddSingleton <IIconProvider>(new Mock <IIconProvider>().Object);

            Action <BlazoriseOptions> configureOptions = (options) =>
            {
            };

            services.AddSingleton(configureOptions);
            services.AddSingleton <BlazoriseOptions>();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds the <see cref="MockJsRuntimeInvokeHandler"/> to the <see cref="TestServiceProvider"/>.
        /// </summary>
        /// <returns>The added <see cref="MockJsRuntimeInvokeHandler"/>.</returns>
        public static MockJsRuntimeInvokeHandler AddMockJsRuntime(this TestServiceProvider serviceProvider, JsRuntimeMockMode mode = JsRuntimeMockMode.Loose)
        {
            if (serviceProvider is null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var result = new MockJsRuntimeInvokeHandler(mode);

            serviceProvider.AddSingleton(result.ToJsRuntime());

            return(result);
        }
Ejemplo n.º 8
0
        public static void AddBootstrapProviders(TestServiceProvider services)
        {
            services.AddSingleton <IClassProvider>(new BootstrapClassProvider());
            services.AddSingleton <IStyleProvider>(new BootstrapStyleProvider());
            services.AddSingleton <IJSRunner>(new BootstrapJSRunner(new Mock <IJSRuntime>().Object));
            services.AddSingleton <IComponentMapper>(new ComponentMapper());
            services.AddSingleton <IThemeGenerator>(new BootstrapThemeGenerator());
            services.AddSingleton <IIconProvider>(new Mock <IIconProvider>().Object);

            services.AddSingleton <BlazoriseOptions>(new BlazoriseOptions());
        }
Ejemplo n.º 9
0
        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 <IJSRunner>(new BootstrapJSRunner(new Mock <IJSRuntime>().Object));
            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>();

            Action <BlazoriseOptions> configureOptions = (options) =>
            {
            };

            services.AddSingleton(configureOptions);
            services.AddSingleton <BlazoriseOptions>();
        }
Ejemplo n.º 10
0
        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>();
        }