// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, CustomerContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInit.Initialize(context); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CatalogueDbRepository catalogueDB) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // 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(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); //appel methode pour charger qlq donnéé DbInit.initData(catalogueDB); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ServiceContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); DbInit.Initialize(context); }
/// <summary> /// 初始化 /// </summary> public void Init() { if (!Util.VerifyUser(ConfigurationManager.AppSettings["IsLogin"])) { // 非法软件操作 HandyControl.Controls.MessageBox.Error("非法软件操作!!!"); this.Close(); return; } Util.CreateKeyFile(); new Thread(new ThreadStart(() => { DbInit init = new DbInit(); init.initTable(); Thread.Sleep(2000); this.Dispatcher?.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => { LoginWindow loginWindow = new LoginWindow(); loginWindow.Show(); this.Close(); })); })) { IsBackground = true }.Start(); }
void ResetTable(SqlConnection connection) { ScriptExecutor exe = new ScriptExecutor(); int c = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Classroom')", connection).ExecuteScalar(); if (c > 0) { new SqlCommand("DROP TABLE Classroom", connection).ExecuteScalar(); } int s = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Student')", connection).ExecuteScalar(); if (s > 0) { new SqlCommand("DROP TABLE Student", connection).ExecuteScalar(); } int t = (int)new SqlCommand(@"use itiSchoolDB SELECT count(*) as IsExists FROM dbo.sysobjects where id = object_id('Teacher')", connection).ExecuteScalar(); if (t > 0) { new SqlCommand("DROP TABLE Teacher", connection).ExecuteScalar(); } exe.ScriptExe(DbInit.CreateTableTeacher(), connection); exe.ScriptExe(DbInsert.InsertTeacherTable(), connection); exe.ScriptExe(DbInit.CreateTableStudent(), connection); exe.ScriptExe(DbInsert.InsertStudentTable(), connection); exe.ScriptExe(DbInit.CreateTableClassroom(), connection); exe.ScriptExe(DbInsert.InsertClassroomTable(), connection); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInit.Init(context); // new UserRoleSeed(roleManager).Seed(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Reading Is Good V1"); }); DbInit.SeedProduct(app); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.ConfigureExceptionHandler(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ProyAnfContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // 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(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); DbInit.Inicio(context); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationDbContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInit.Initialize(context); }
private static void InitializeMigrations(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { DbInit.Initialize(serviceScope); } }
public void EntityIsNotNullAfterCreate() { EntityOps entityOps = new EntityOps(DbInit.DBInit().Context); Person person = entityOps.CreateAndGetPersoFromRelatedCollection(saveChanges: true); Assert.IsNotNull(person); }
protected void Application_Start() { using (var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { // CreateDatabase will fail on azure because I can't connect to tempdb; var builder = new SqlConnectionStringBuilder(cn.ConnectionString); var createDbError = DbInit.CreateDatabase(builder); DbInit.InitLog4NetDb(cn); } var log = LogManager.GetLogger(GetType()); log.Info("Calling Application_Start"); log.Debug("Performing Area Registration"); AreaRegistration.RegisterAllAreas(); log.Debug("Performing Global Configuration"); GlobalConfiguration.Configure(WebApiConfig.Register); log.Debug("Registering GLobal Filters"); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); log.Debug("Registering Routes"); RouteConfig.RegisterRoutes(RouteTable.Routes); log.Debug("Registering Bundles"); BundleConfig.RegisterBundles(BundleTable.Bundles); // Force creation of auth schema. DbInit.CreateAuthContext(); // Force creation of Purchasing schema. DbInit.CreatePurchasingContext(); log.InfoFormat("Application_Start exiting"); }
public void T5_check_if_tables_are_filled() { using (SqlConnection connection = new SqlConnection(DbInit.GetConnectionString())) { connection.Open(); ResetTables(connection); ScriptExecutor exe = new ScriptExecutor(); exe.ScriptExe(DbInsert.InsertTeacherTable(), connection); exe.ScriptExe(DbInsert.InsertStudentTable(), connection); exe.ScriptExe(DbInsert.InsertClassroomTable(), connection); DataTable datatableStudent = new DataTable(); DataTable datatableTeacher = new DataTable(); DataTable datatableClassroom = new DataTable(); string teachers = "select count(*) from Teacher"; string students = "select count(*) from Student"; string classrooms = "select count(*) from Classroom"; SqlCommand cmd1 = new SqlCommand(teachers, connection); SqlCommand cmd2 = new SqlCommand(students, connection); SqlCommand cmd3 = new SqlCommand(classrooms, connection); int sqlresult1 = (Int32)cmd1.ExecuteScalar(); int sqlresult2 = (Int32)cmd2.ExecuteScalar(); int sqlresult3 = (Int32)cmd3.ExecuteScalar(); sqlresult1.Should().Be(9); sqlresult2.Should().Be(11); sqlresult3.Should().Be(8); connection.Close(); } }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { // create code-first db context from contacts model var context = services.GetRequiredService <AppDbContext>(); // check if local db exists, create if not context.Database.EnsureCreated(); // load db with mock data if empty DbInit.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); } } host.Run(); }
public void T1_check_if_firstName_lastname_column_in_student_table_are_created_and_filled() { using (SqlConnection connection = new SqlConnection(DbInit.GetConnectionString())) { connection.Open(); ResetTables(connection); ScriptExecutor exe = new ScriptExecutor(); DataTable StudentDataTableBefore = new DataTable(); string queryBefore = "use itiSchoolDB select * from Student"; SqlCommand cmdBefore = new SqlCommand(queryBefore, connection); SqlDataAdapter daBefore = new SqlDataAdapter(cmdBefore); daBefore.Fill(StudentDataTableBefore); StudentDataTableBefore.Columns.Count.Should().Be(6); exe.ScriptExe(DbModificationScheme.UpdateTableStudent(), connection); DataTable datatable = new DataTable(); string query = "select * from Student"; SqlCommand cmd = new SqlCommand(query, connection); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(datatable); datatable.Columns.Contains("Guid").Should().BeTrue(); datatable.Columns.Contains("Name").Should().BeTrue(); datatable.Columns.Contains("Semestre").Should().BeTrue(); datatable.Columns.Contains("Orientation").Should().BeTrue(); datatable.Columns.Contains("BirthDate").Should().BeTrue(); datatable.Columns.Contains("MainTeacher").Should().BeTrue(); datatable.Columns.Contains("Lastname").Should().BeTrue(); datatable.Columns.Contains("Firstname").Should().BeTrue(); datatable.Columns.Count.Should().Be(8); string students = "use itiSchoolDB select Name, Firstname, Lastname from Student"; SqlCommand cmd1 = new SqlCommand(students, connection); SqlDataReader reader = cmd1.ExecuteReader(); string fullNameConcat = ""; string baseName = ""; try { while (reader.Read()) { baseName = (String.Format("{0}", reader["Name"])); fullNameConcat = (String.Format("{0} {1}", reader["Firstname"], reader["Lastname"])); fullNameConcat.Should().Be(baseName); } } finally { reader.Close(); } connection.Close(); } }
public void EntityIsNullAfterDelete() { EntityOps entityOps = new EntityOps(DbInit.DBInit().Context); Person newPerson = entityOps.CreateAndSavePerson(); Person deletedPerson = entityOps.DeleteAndGetPersonFromRelatedCollection(newPerson.Id, saveChanges: true); Assert.IsNull(deletedPerson); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, FunnyHistoryContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseCors("SiteCorsPolicy"); app.UseMvc(); DbInit.Initialize(context); }
public void EntityIsNullAfterCreateNotExpectedBehaviour() { EntityOps entityOps = new EntityOps(DbInit.DBInit().Context); Person person = entityOps.CreateAndGetPersoFromRelatedCollection(); string error = @"Person received from collection of team is null. We need it not null. SaveChanges or DetectChagnes helps but frequent execution of save make app slow"; Assert.IsNotNull(person, error); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DbInit.InitDb(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, HikingContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseMvc(); DbInit.Init(context); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var newScope = host.Services.CreateScope()) { var context = newScope.ServiceProvider.GetRequiredService <AppDbContext>(); DbInit.InitializeWithFakeData(context); } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var dbContext = services.GetService <CustomerApiContext>(); DbInit.Initialize(dbContext); } host.Run(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); //using (var scope = host.Services.CreateScope()) //{ // var context = scope.ServiceProvider.GetRequiredService<AppDbContext>(); // DbInit.Init(context); //} DbInit.Init(); host.Run(); }
public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup <Startup>() .UseApplicationInsights() .Build(); DbInit.SeedData(); host.Run(); }
private async Task SuperAdminEnsureCreate(string email, AppUser user = null) { var isNayUser = await _userManager.Users.Where(i => i.Email != email).AnyAsync(); if (!isNayUser) { await DbInit.InitialRoles(_configuration, _roleManager); var _user = user ?? await _userManager.FindByEmailAsync(email); await _userManager.AddToRolesAsync(_user, _configuration.GetRoles()); } }
public void T2_View_Returns_Expected_Values_Programmaticaly() { using (SqlConnection connection = new SqlConnection(DbInit.GetDbConnectionString())) { connection.Open(); ResetTable(connection); List <View> results = DbViews.GetViewValues(connection).ToList(); Compare(results, GetAllUser()).Should().BeTrue(); } }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var newScope = host.Services.CreateScope()) { Console.WriteLine("Seeding Database"); var context = newScope.ServiceProvider.GetRequiredService <AppDbContext>(); DbInit.SeedFakeData(context); } host.Run(); }
public void T2_Return_Classroom_Where_You_Can_Find_Student_Whose_Name_Starts_With_Thibau_When_They_Are_With_Their_MainTeacher() { using (SqlConnection connection = new SqlConnection(DbInit.GetConnectionString())) { connection.Open(); ScriptExecutor exe = new ScriptExecutor(); List <string> response = exe.ScriptReader(RequestsScripts[1], connection, "Name").ToList(); Assert.AreEqual(response.Count, 2); Assert.Contains("E07", response); Assert.Contains("E03", response); } }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <SchoolContext>(); DbInit.Initialize(context); context.Database.EnsureCreated(); } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var newScope = host.Services.CreateScope()) { // Register the context class var context = newScope.ServiceProvider.GetRequiredService <AppDbContext>(); // Call DbInit DbInit.InitializeWithFakeData(context); } //* NotFORGET host.Run(); }