public async Task Update_Is_Exist_Value() { var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Exist_Value)))) { InMemoryDatabaseHelper.Save(new List <User> { userGenerated }, context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Exist_Value)))) { var repository = new UserRepository(context); var user = await repository.GetById(userGenerated.Id); user.Username = UserSeed.Username; await repository.Update(user); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Exist_Value)))) { var repository = new UserRepository(context); var userList = repository.GetAll(); Assert.NotNull(userList); Assert.Contains(UserSeed.Username, userList.Select(u => u.Username)); } }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <UserContext>(); var context2 = services.GetRequiredService <VariableContext>(); var context3 = services.GetRequiredService <EventContext>(); context.Database.Migrate(); context2.Database.Migrate(); context3.Database.Migrate(); UserSeed.Initialize(services); VariableSeed.Initialize(services); EventSeed.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var logger = services.GetRequiredService <ILogger <Program> >(); // // StateSeed.Initialize(services); RoleSeed.Initialize(services, logger).Wait(); UserSeed.Initialize(services, logger).Wait(); EmployeeCvSeed.Initialize(services, logger).Wait(); EmployeeCvExternalMaterialSeed.Initialize(services, logger).Wait(); EmployeeCvJobHisotriesSeed.Initialize(services, logger).Wait(); EmployeeCvSkillSeed.Initialize(services, logger).Wait(); EmployeeCvWorkDaySeed.Initialize(services, logger).Wait(); EmployerJobProfileSeed.Initialize(services, logger).Wait(); EmployerJobSkillSeed.Initialize(services, logger).Wait(); } catch (Exception ex) { services.GetRequiredService <ILogger <Program> >().LogError(ex, "An error occurred while seeding the database"); throw; } } host.Run(); // BuildWebHost(args).Run(); }
private void MigrateDatabase(IApplicationBuilder app) { var genreConfiguration = Configuration.GetSection("Genre").Get <GenreConfiguration>(); var userConfiguration = Configuration.GetSection("User").Get <UserConfiguration>(); var movieConfiguration = Configuration.GetSection("Movie").Get <MovieConfiguration>(); //var movieGenreConfiguration = Configuration.GetSection("MovieGenre").Get<MovieGenreConfiguration>(); var permissionConfiguration = Configuration.GetSection("Permission").Get <PermissionConfiguration>(); var reservationConfiguration = Configuration.GetSection("Reservation").Get <ReservationConfiguration>(); var roomConfiguration = Configuration.GetSection("Room").Get <RoomConfiguration>(); var roomPlanConfiguration = Configuration.GetSection("RoomPlan").Get <RoomPlanConfiguration>(); var scheduleConfiguration = Configuration.GetSection("Schedule").Get <ScheduleConfiguration>(); var scheduleSlotConfiguration = Configuration.GetSection("ScheduleSlot").Get <ScheduleSlotConfiguration>(); var seatTypeConfiguration = Configuration.GetSection("SeatType").Get <SeatTypeConfiguration>(); var seatPositionConfiguration = Configuration.GetSection("SeatPosition").Get <SeatPositionConfiguration>(); var locationConfiguration = Configuration.GetSection("Location").Get <LocationConfiguration>(); var roomAssignmentConfiguration = Configuration.GetSection("RoomAssignment").Get <RoomAssignmentConfiguration>(); var roomTechnologyConfiguration = Configuration.GetSection("RoomTechnology").Get <RoomTechnologyConfiguration>(); using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <DatabaseContext>(); context.Database.Migrate(); GenreSeed.Seed(context, genreConfiguration.Genres); UserSeed.Seed(context, userConfiguration.Users); PermissionSeed.Seed(context, permissionConfiguration.Permissions); SeatTypeSeed.Seed(context, seatTypeConfiguration.SeatTypes); LocationSeed.Seed(context, locationConfiguration.Locations); RoomTechnologySeed.Seed(context, roomTechnologyConfiguration.RoomTechnologies); } }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); await context.Database.MigrateAsync(); var userManager = services.GetRequiredService <UserManager <Account> >(); var roleManager = services.GetRequiredService <RoleManager <AppRole> >(); await AuthorSeed.SeedAuthor(context); await BookSeed.SeedBooks(context); await UserSeed.SeedUsers(userManager, roleManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred during migration"); } await host.RunAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseCors(builder => { builder .WithOrigins("https://localhost:44315", "http://localhost:58722") .AllowAnyHeader() .AllowCredentials(); }); app.UseResponseCompression(); app.UseAuthentication(); app.UseMvc(); UserSeed.Seed(app.ApplicationServices).Wait(); }
public async Task Delete_Is_Exist_Value(int userCount) { var userGenerated = UserSeed.CreateUserTest(); var users = UserSeed.CreateUsers(userCount); users.Add(userGenerated); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Exist_Value)))) { InMemoryDatabaseHelper.Save(users, context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Exist_Value)))) { var repository = new UserRepository(context); await repository.Delete(userGenerated.Id); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Exist_Value)))) { Assert.NotNull(context.User); Assert.False(context.User.Any(u => u.Id == userGenerated.Id)); Assert.True(context.User.Count() == userCount); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserSeed userSeed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { //error handler app.UseExceptionHandler(builder => { builder.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var error = context.Features.Get <ExceptionHandlerFeature>(); if (error != null) { context.Response.AddApplicationError(error.Error.Message); await context.Response.WriteAsync(error.Error.Message); //writing out http error into a message } }); }); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. } //app.UseHsts(); // app.UseHttpsRedirection(); // userSeed.SeedUsers(); app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); //cors app.UseAuthentication(); //for authentication middleware app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvc(routes => { //for fallback , this was used when we added angulr into wwwroot routes.MapSpaFallbackRoute(name: "spa-fallback", defaults: new{ //this is just telling our app to redirect to the controller if it dosent undertsand the route Controller = "Fallback", Action = "Index" }); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserSeed userSeed, LogLevelSeed levelSeed, EnvironmentSeed environmentSeed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); userSeed.Populate(); levelSeed.Populate(); environmentSeed.Populate(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(); app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "CadeOErro API")); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); var configuration = services.GetRequiredService <IConfiguration>(); var context = services.GetRequiredService <TurboGamesContext>(); UserSeed.CreateRoles(serviceProvider, configuration, context).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "An error occurred while creating roles and users"); } } host.Run(); }
public async Task Delete_Existing_User_Multiple_Users() { var users = UserSeed.CreateUsers(10); var userGenerated = UserSeed.CreateUserTest(); users.Add(userGenerated); var dbName = nameof(Delete_Existing_User_Multiple_Users); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(users, context); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { var controller = CreateUserControllerObject(context); var result = await controller.Delete(userGenerated.Id); Assert.IsType <OkResult>(result); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { Assert.False(context.User.Any(u => u.Id == userGenerated.Id)); Assert.True(context.User.Count() == users.Count() - 1); } }
private async Task Execute_Success() { var userCount = 10; // Arrange using (var context = InMemoryDatabaseHelper.CreateContext(nameof(Execute_Success))) { InMemoryDatabaseHelper.Save(UserSeed.CreateUsers(userCount), context); } using (var context = InMemoryDatabaseHelper.CreateContext(nameof(Execute_Success))) { var user = context.User.FirstOrDefault(); var userDelete = CreateUserDeleteObject(context); var userDto = new UserDto { Id = user.Id, Username = user.Username, Password = user.Password }; // Act var result = await userDelete.Execute(userDto); // Assert Assert.DoesNotContain(user.Id, context.User.Select(u => u.Id)); Assert.Equal(context.User.Count(), userCount - 1); Assert.IsType <UserDto>(result); } }
public async Task Delete_Existing_User() { var dbName = nameof(Delete_Existing_User); var user = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(new List <User> { user }, context); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { var controller = CreateUserControllerObject(context); var result = await controller.Delete(user.Id); Assert.IsType <OkResult>(result); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { Assert.False(context.User.Any(u => u.Id == user.Id)); } }
public async Task Post_Create_User_Success() { var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(nameof(Post_Create_User_Success))) { var controller = CreateUserControllerObject(context); var dto = new UserDto { Id = userGenerated.Id, Username = userGenerated.Username, Password = userGenerated.Password }; var result = await controller.Post(dto); var dtoSuccess = result.Value; Assert.IsType <ActionResult <UserDto> >(result); Assert.IsType <UserDto>(dtoSuccess); } using (var context = InMemoryDatabaseHelper.CreateContext(nameof(Post_Create_User_Success))) { var user = context.User.FirstOrDefault(u => u.Id == userGenerated.Id); Assert.NotNull(user); Assert.True(user.Username == userGenerated.Username); Assert.True(user.Password == userGenerated.Password); } }
public async Task Post_Create_User_Conflict() { var user = UserSeed.CreateUserTest(); var dbName = nameof(Post_Create_User_Conflict); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(new List <User> { user }, context); var controller = CreateUserControllerObject(context); var dto = new UserDto { Id = user.Id, Username = user.Username, Password = user.Password }; var result = await controller.Post(dto); Assert.IsType <BadRequestObjectResult>(result.Result); } }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserSeed userSeed, RoleSeed roleSeed, LevelSeed levelSeed, EnvironmentSeed environmentSeed, LogSeed logSeed, EventSeed eventSeed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); userSeed.Populate(); roleSeed.Populate(); levelSeed.Populate(); environmentSeed.Populate(); logSeed.Populate(); eventSeed.Populate(); } app.UseSwaggerSetup(); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
protected override void OnModelCreating(ModelBuilder builder) { builder.ApplyConfiguration(new UserMap()); var users = UserSeed.Seed(builder.Entity <User> ()); base.OnModelCreating(builder); }
protected virtual void Seed() { using (_context) { UserSeed.Run(_context); OrderSeed.Run(_context); } }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); RoleSeed.Seed(builder); UserSeed.Seed(builder); UserRoleSeed.Seed(builder); }
public static void EnsureSeeded(this BoilerplateContext context) { RolesSeed.Seed(context); context.SaveChanges(); UserSeed.Seed(context); context.SaveChanges(); }
public static void Initialize(MoviesWebAppDbContext context) { context.Database.Migrate(); UserSeed.Seed(context); MovieSeeds.Seed(context); ActorSeeds.Seed(context); ImgUrlSeed.Seed(context); ActorMovieSeeds.Seed(context); }
protected override void Seed(CodeKata.Domain.CodeKataContext context) { // Deletes all data, from all tables, except for __MigrationHistory context.Database.ExecuteSqlCommand("sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'"); context.Database.ExecuteSqlCommand("sp_MSForEachTable 'IF OBJECT_ID(''?'') NOT IN (ISNULL(OBJECT_ID(''[dbo].[__MigrationHistory]''),0)) DELETE FROM ?'"); context.Database.ExecuteSqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'"); // proceed with the seed here var testUsers = UserSeed.Seed(context); SubmittedTaskSeed.Seed(context, testUsers); }
public void Configure(EntityTypeBuilder <User> builder) { builder.ToTable(nameof(User)); builder.HasKey(h => h.Id); builder.Property(h => h.Email).IsRequired(); builder.Property(h => h.Profile).IsRequired(); builder.Property(h => h.CreationDate).IsRequired(); builder.Property(h => h.Name).IsRequired(); builder.Property(h => h.Password).IsRequired(); builder.HasData(UserSeed.DefaultUsers()); }
public async Task Delete_No_Existing_User() { var dbName = nameof(Delete_No_Existing_User); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(UserSeed.CreateUsers(), context); var controller = CreateUserControllerObject(context); Assert.IsType <NotFoundObjectResult>(await controller.Delete(Guid.NewGuid().ToString())); } }
public static void Seed(WebAppContext context) { var db = context.Database.EnsureCreated(); if (context.User.Any()) { return; } ApplicationSeed.CreateApplication(context); RoleSeed.CreateRole(context); UserSeed.CreateUser(context); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <UserContext>(); UserSeed.Seed(context); } host.Run(); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); #region "Mappers" UserMapping.Map(modelBuilder); #endregion #region "Seeders" UserSeed.Seed(modelBuilder); #endregion }
//This class tells Entity Framework where our seed files are, //and to use them to add records to our operational database. //We do them in this order so that foreign keys can be established. protected override async void Seed(OracleContext context) { //System-specific context.Users.AddOrUpdate(UserSeed.ToArray()); await context.SaveChangesAsync(); context.Permissions.AddOrUpdate(PermissionSeed.ToArray()); await context.SaveChangesAsync(); //Operational context.Campuses.AddOrUpdate(CampusSeed.ToArray()); await context.SaveChangesAsync(); context.Countries.AddOrUpdate(CountrySeed.ToArray()); await context.SaveChangesAsync(); context.AcademicYears.AddOrUpdate(AcademicYearSeed.ToArray()); await context.SaveChangesAsync(); context.Modules.AddOrUpdate(ModuleSeed.ToArray()); await context.SaveChangesAsync(); context.Courses.AddOrUpdate(CourseSeed.ToArray()); await context.SaveChangesAsync(); context.CourseModules.AddOrUpdate(CourseModuleSeed.ToArray()); await context.SaveChangesAsync(); context.Lecturers.AddOrUpdate(LecturerSeed.ToArray()); await context.SaveChangesAsync(); context.ModuleRuns.AddOrUpdate(ModuleRunSeed.ToArray()); await context.SaveChangesAsync(); context.Students.AddOrUpdate(StudentSeed.ToArray()); await context.SaveChangesAsync(); context.Enrollments.AddOrUpdate(EnrollmentSeed.ToArray()); await context.SaveChangesAsync(); context.Assignments.AddOrUpdate(AssignmentSeed.ToArray()); await context.SaveChangesAsync(); context.Results.AddOrUpdate(ResultSeed.ToArray()); await context.SaveChangesAsync(); context.Graduations.AddOrUpdate(GraduationSeed.ToArray()); await context.SaveChangesAsync(); context.Complaints.AddOrUpdate(ComplaintSeed.ToArray()); await context.SaveChangesAsync(); }
public async Task Add_Duplicate_Id() { var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Add_Duplicate_Id)))) { InMemoryDatabaseHelper.Save(new List <User> { userGenerated }, context); var repository = new UserRepository(context); await Assert.ThrowsAsync <InvalidOperationException>(async() => await repository.Add(userGenerated)); } }
public async Task Delete_Is_Not_Exist_Value() { using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Not_Exist_Value)))) { InMemoryDatabaseHelper.Save(UserSeed.CreateUsers(), context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Not_Exist_Value)))) { var repository = new UserRepository(context); await Assert.ThrowsAsync <InvalidOperationException>(() => repository.Delete(UserSeed.CreateUserTest().Id)); } }