public async Task ShouldNotCreateDefaultAdminAccountWhenExisting()
        {
            // Arrange
            var configuration = await _fixture.ExecuteScopeAsync(async sp => sp.GetService <IConfiguration>());

            var expectedAdminCredentials = configuration.GetAdminCredentials();

            await _fixture.SendAsync(new Register
            {
                Id        = Guid.NewGuid(),
                Email     = expectedAdminCredentials.Email,
                Password  = expectedAdminCredentials.Password,
                FirstName = "Some",
                LastName  = "Account"
            });

            // Act
            await _fixture.ExecuteScopeAsync(async sp =>
            {
                var userManager = sp.GetService <UserManager <User> >();

                var result = await DatabaseConfiguration
                             .AddDefaultAdminAccountIfNoneExisting(userManager, configuration);

                // Assert
                result.HasValue.ShouldBeFalse();
            });
        }
        /// <summary>
        /// This method gets called by the runtime.
        /// Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app">
        /// Provides the mechanisms to configure an application's request pipeline.
        /// </param>
        /// <param name="env">
        /// Provides information about the web hosting environment an application is running in.
        /// </param>
        /// <param name="loggerFactory">
        /// Represents a type used to configure the logging system
        /// and create instances of ILogger from the registered ILoggerProviders.
        /// </param>
        /// <param name="userManager">
        /// Managing user in a persistence store.
        /// </param>
        /// <param name="dbContext">
        /// Application class for the Entity Framework database context used for identity.
        /// </param>
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            UserManager <User> userManager,
            ApplicationDbContext dbContext,
            DatabaseSeeder seeder)
        {
            // ensure data stores
            dbContext.Database.EnsureCreated();
            DatabaseConfiguration.EnsureEventStoreIsCreated(Configuration);

            if (!env.IsEnvironment(Environment.IntegrationTests))
            {
                DatabaseConfiguration.AddDefaultAdminAccountIfNoneExisting(userManager, Configuration).Wait();
                seeder.SeedDatabase().Wait();
            }

            if (!env.IsDevelopment())
            {
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseCors(builder => builder
                        .SetIsOriginAllowedToAllowWildcardSubdomains()
                        .WithOrigins("http://localhost:3000", "https://jbet.net")
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            loggerFactory.AddLogging(Configuration.GetSection("Logging"));

            app.UseSwagger("Jbet");

            app.UseStaticFiles();
            app.UseAuthentication();

            // soon app.UseSignalR

            app.UseMvc();
        }
Beispiel #3
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UserManager <User> userManager, ApplicationDbContext dbContext, DatabaseSeeder seeder)
        {
            dbContext.Database.EnsureCreated();
            DatabaseConfiguration.EnsureEventStoreIsCreated(Configuration);

            if (!env.IsEnvironment(Environment.IntegrationTests))
            {
                DatabaseConfiguration.AddDefaultAdminAccountIfNoneExisting(userManager, Configuration).Wait();
                seeder.SeedDatabase().Wait();
            }

            if (!env.IsDevelopment())
            {
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseCors(builder => builder
                        .SetIsOriginAllowedToAllowWildcardSubdomains()
                        .WithOrigins("http://localhost:3000", "https://*.devadventures.net")
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            loggerFactory.AddLogging(Configuration.GetSection("Logging"));

            app.UseSwagger("Cafe");
            app.UseStaticFiles();
            app.UseAuthentication();

            // It's very important that UseAuthentication is called before UseSignalR
            app.UseSignalR(routes =>
            {
                routes.MapHub <ConfirmedOrdersHub>("/confirmedOrders");
                routes.MapHub <HiredWaitersHub>("/hiredWaiters");
                routes.MapHub <TableActionsHub>("/tableActions");
            });

            app.UseMvc();
        }
        public async Task ShouldCreateDefaultAdminAccountWhenNotExisting()
        {
            // Arrange
            var configuration = await _fixture.ExecuteScopeAsync(async sp => sp.GetService <IConfiguration>());

            var expectedAdminCredentials = configuration.GetAdminCredentials();

            // Act
            await _fixture.ExecuteScopeAsync(async sp =>
            {
                var userManager = sp.GetService <UserManager <User> >();

                var result = await DatabaseConfiguration
                             .AddDefaultAdminAccountIfNoneExisting(userManager, configuration);

                // Assert
                result.Exists(credentials =>
                              credentials.Email == expectedAdminCredentials.Email &&
                              credentials.Password == expectedAdminCredentials.Password)
                .ShouldBeTrue();
            });
        }