Пример #1
0
        private async Task CreateDbSeedAsync(IServiceProvider serviceProvider)
        {
            _logger.LogInformation("Creating DB seed");
            try
            {
                _logger.LogInformation("Creating users");
                await DbSeed.CreateTestingUserAsync(serviceProvider);

                _logger.LogInformation("Users created");
                _logger.LogInformation("Creating courses");
                await DbSeed.LoadTestingCoursesAsync(serviceProvider);

                _logger.LogInformation("Courses created");
                _logger.LogInformation("Creating exchanges");
                await DbSeed.CreateTestingExchangesAsync(serviceProvider);

                _logger.LogInformation("Exchanges created.");
                _logger.LogInformation("Creating notifications");
                await DbSeed.CreateTestingNotifications(serviceProvider);

                _logger.LogInformation("Notifications created.");
            }
            catch (Exception e)
            {
                _logger.LogError($"Exception during creating DB seed :\n{e.Message}");
            }
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, AppDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            //Seed de data inicial
            DbSeed.SeedData(context);

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Noticias}/{action=Index}/{id?}");
            });
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, DbSeed seed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }



            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "area",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            seed.Seed();
        }
Пример #4
0
        public async Task DeleteProperProductSaleRecords_WhenValidSaleIdIsPassed()
        {
            //Arrange
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = DbSeed.GetOptions(databaseName);

            DbSeed.SeedDatabase(options);
            Sale sale;
            int  totalRecordsInProductSale;

            using (var getContext = new StoreSystemDbContext(options))
            {
                sale = getContext.Sales.Include(x => x.ProductsInSale).First();
                totalRecordsInProductSale = getContext.ProductSales.Count();
            }

            int validSaleId           = sale.SaleID;
            var countOfProductsInSale = sale.ProductsInSale.Count();

            using (var context = new StoreSystemDbContext(options))
            {
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();
                var sut = new SaleService(context, dateTimeNowProvider.Object);

                //Act
                var isExecxuted = await sut.DeleteSaleAsync(validSaleId);

                //Assert
                Assert.IsTrue(isExecxuted);
                Assert.AreEqual(totalRecordsInProductSale - countOfProductsInSale, context.ProductSales.Count());
            }
        }
Пример #5
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    // TwoNoteContext Seed.
                    var context = services.GetService <TwoNoteContext>();
                    DbSeed.SeedAsync(context).Wait();

                    // AppIdentityDbContext Seed.
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    AppIdentityDbContextSeed.SeedAsync(userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured while seeding the database");
                }
            }

            host.Run();
        }
Пример #6
0
 private static void InitializeMigrations(IApplicationBuilder app)
 {
     using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
     {
         DbSeed.DbInit(serviceScope);
     }
 }
Пример #7
0
        // 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, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Products}/{action=Index}/{id?}/{slug?}");
            });

            DbSeed.Seed(context, userManager, roleManager);
        }
Пример #8
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            using (var context = new TicketingSystemDbContext())
            {
                context.Database.Migrate();
                if (!context.Users.Any())
                {
                    DbSeed.SeedUsers(context);
                }
            }

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseAuthentication();

            app.UseStaticFiles();

            app.UseMvcWithDefaultRoute();
        }
Пример #9
0
        public async Task ShouldReturnTotalSumOfFiltredSales_WhenValidDatesArePassed()
        {
            //Arrange
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = DbSeed.GetOptions(databaseName);

            DbSeed.SeedDatabase(options);

            var     validStartDate = new DateTime(2019, 2, 2);
            var     validEndDate   = new DateTime(2019, 4, 4);
            decimal expectedTotal  = (decimal)((1 * 1 + 1 * 3 * 2) * (1 - 0.1 / 100));

            using (var context = new StoreSystemDbContext(options))
            {
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();
                var sut = new SaleService(context, dateTimeNowProvider.Object);

                //Act
                var actualTotal = await sut.GetSaleQuantityAsync(startDate : validStartDate, endDate : validEndDate);

                //Assert
                Assert.AreEqual(expectedTotal, actualTotal);
            }
        }
Пример #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext dBcontext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            DbSeed.Seed(dBcontext);
        }
Пример #11
0
 public static void ConfigureServices(IServiceCollection services, string connString)
 {
     DbSeed.ConfigureContext(services, connString);
     services.AddScoped(typeof(ICRUD <Cinema>), typeof(CinemaService));
     services.AddScoped(typeof(ICRUD <Hall>), typeof(HallService));
     services.AddScoped(typeof(ICRUD <Movie>), typeof(MovieService));
 }
Пример #12
0
        // 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)
        {
            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();

            DbSeed.Seed(app);

            // 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?}");
            });
        }
Пример #13
0
        public async Task CreateAndAddNewSaleInDB_WhenValidParametersArePassed()
        {
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            using (var context = new StoreSystemDbContext(DbSeed.GetOptions(databaseName)))
            {
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();

                var validDate       = new DateTime(2019, 4, 1);
                var validClientName = "Pesho";

                dateTimeNowProvider.Setup(x => x.Now).Returns(validDate);
                var sut    = new SaleService(context, dateTimeNowProvider.Object);
                var client = new Client()
                {
                    Name = validClientName
                };
                var address = new Address();
                var city    = new City();
                var country = new Country();
                await sut.CreateSaleAsync(client, 0.15m, 3, address, city, country);

                Assert.AreEqual(1, context.Sales.Count());
                Assert.AreEqual(validClientName, context.Sales.Single(x => x.Client == client).Client.Name);
            }
        }
Пример #14
0
        public async Task CreateAndAddNewSaleWithIDsInDB_WhenValidParametersArePassed()
        {
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            using (var context = new StoreSystemDbContext(DbSeed.GetOptions(databaseName)))
            {
                //Arrange
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();

                var validDate = new DateTime(2019, 1, 1);

                dateTimeNowProvider.Setup(x => x.Now).Returns(validDate);
                var sut      = new SaleService(context, dateTimeNowProvider.Object);
                var client   = 1;
                var address  = 1;
                var city     = 1;
                var country  = 1;
                var deadline = new DateTime(2019, 5, 10);
                var discount = 0.10m;

                //Act
                await sut.CreateSaleAsync(client, discount, deadline, address, city, country);

                //Assert
                Assert.AreEqual(1, context.Sales.Count());
                Assert.AreEqual(client, context.Sales.Single(x => x.ClientID == client).ClientID);
            }
        }
Пример #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext dbContext, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.Use((request, next) =>
            {
                var sv = new CultureInfo("sv-SE");
                System.Threading.Thread.CurrentThread.CurrentCulture   = sv;
                System.Threading.Thread.CurrentThread.CurrentUICulture = sv;
                return(next());
            });

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=People}/{action=Index}/{id?}/{slug?}");
            });

            // DbSeed.Seed(context);
            DbSeed.Seed(dbContext);
        }
Пример #16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            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();

            DbSeed.SeedData(userManager, roleManager);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
        public async Task CreateSaleFromOffer_WhenValidOfferIdIsPassed()
        {
            //Arrange
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = DbSeed.GetOptions(databaseName);

            DbSeed.SeedDatabase(options);

            Offer validOffer;

            using (var getContext = new StoreSystemDbContext(options))
            {
                validOffer = getContext.Offers.Include(x => x.Client).First();
            }

            using (var context = new StoreSystemDbContext(options))
            {
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();
                var validDate           = new DateTime(2019, 4, 1);
                var sut = new SaleService(context, dateTimeNowProvider.Object);

                //Act
                var saleActual = await sut.CreateSaleByOfferIDAsync(validOffer.OfferID);

                //Assert
                Assert.AreEqual(validOffer.OfferID, saleActual.OfferID);
                Assert.AreEqual(validOffer.ClientID, context.Sales.FirstOrDefault(x => x.OfferID == validOffer.OfferID).ClientID);
                Assert.AreEqual(validOffer.AddressID, context.Sales.FirstOrDefault(x => x.OfferID == validOffer.OfferID).AddressID);
                Assert.AreEqual(validOffer.CityID, context.Sales.FirstOrDefault(x => x.OfferID == validOffer.OfferID).CityID);
                Assert.AreEqual(validOffer.CountryID, context.Sales.FirstOrDefault(x => x.OfferID == validOffer.OfferID).CountryID);
            }
        }
        public async Task ThrowsArgumentException_WhenInvalidSaleIdIsPassed()
        {
            //Arrange
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = DbSeed.GetOptions(databaseName);

            DbSeed.SeedDatabase(options);

            int invalidSaleID = 100;

            using (var context = new StoreSystemDbContext(options))
            {
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();
                var validDate           = new DateTime(2019, 4, 1);
                var sut = new SaleService(context, dateTimeNowProvider.Object);
                ProductIdQuantityDto[] products = new ProductIdQuantityDto[0];
                var errorText = string.Format(
                    Consts.ObjectIDNotExist,
                    nameof(Sale),
                    invalidSaleID);
                //Act
                //Assert
                Assert.AreEqual(
                    errorText,
                    (await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.AddProductsByIdToSaleAsync(invalidSaleID, products))).Message);
            }
        }
Пример #19
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            DbSeed.Seed(app.ApplicationServices);
            app.UseStaticFiles();
            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseCookiePolicy();
            app.UseStatusCodePages();
            container.AutoCrossWireAspNetComponents(app);
            container.RegisterPageModels(app);
            container.Verify();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #20
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args);

            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (env.Equals("Development", StringComparison.InvariantCultureIgnoreCase))
            {
                using (var scope = host.Services.CreateScope())
                {
                    var services = scope.ServiceProvider;

                    try
                    {
                        DbSeed.SeedAsync(services)
                        .Wait();
                    }
                    catch (Exception ex)
                    {
                        var logger = services.GetRequiredService <ILogger <Program> >();
                        logger.LogError(ex, "An error occurred seeding the DB.");
                    }
                }
            }

            host.Run();
        }
Пример #21
0
        // 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.UseHttpsRedirection();
            app.UseRouting();

            app.UseSwagger();

            app.UseSwaggerUI(s =>
            {
                s.SwaggerEndpoint("/swagger/v1/swagger.json", "Api v1");
                s.RoutePrefix = string.Empty;
            });

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseCors();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            DbSeed.PrepDb(app);
        }
Пример #22
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              PortfolioContext context)
        {
            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.UseCookiePolicy();

            /* Seed projects */
            DbSeed.SeedDatabase(context).Wait();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #23
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, Context context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();
            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            DbSeed.Seed(context);
        }
Пример #24
0
        public static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();

                try
                {
                    // 从 system.IServicec提供程序获取 T 类型的服务。
                    var myContext = services.GetRequiredService <KCDBContext>();
                    if (myContext.Database.GetPendingMigrations().Any())
                    {
                        myContext.Database.Migrate();     //执行迁移
                    }
                    DbSeed.SeedAsync(myContext).Wait();
                }
                catch (Exception e)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(e, "Error occured seeding the Database.");
                }
            }
            host.Run();
        }
Пример #25
0
        public async Task DeleteProperSale_WhenValidSaleIdIsPassed()
        {
            //Arrange
            var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = DbSeed.GetOptions(databaseName);

            DbSeed.SeedDatabase(options);

            int validSaleId;
            int totalCountOfSales;

            using (var getContext = new StoreSystemDbContext(options))
            {
                validSaleId       = getContext.Sales.First().SaleID;
                totalCountOfSales = getContext.Sales.Count();
            }

            using (var context = new StoreSystemDbContext(options))
            {
                var dateTimeNowProvider = new Mock <IDateTimeNowProvider>();
                var sut = new SaleService(context, dateTimeNowProvider.Object);

                //Act
                var isExecxuted = await sut.DeleteSaleAsync(validSaleId);

                //Assert
                Assert.IsTrue(isExecxuted);
                Assert.IsTrue(context.Sales.Find(validSaleId) == null);
                Assert.AreEqual(totalCountOfSales - 1, context.Sales.Count());
            }
        }
Пример #26
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     DbSeed.SeedRolesAndUsers();
 }
Пример #27
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.ApplyConfiguration(new CategoryConfiguration());

            DbSeed.Seed(modelBuilder);
        }
Пример #28
0
        public void TryLogIn_NullInput_ShouldReturnNull()
        {
            DbSeed.Seed(this.fixture.Context);
            UserViewModel  input      = null;
            UserRepository repository = new UserRepository(fixture.Context);

            Assert.Null(repository.TryLogIn(input));
        }
 public static void Main(string[] args)
 {
     using (var seed = new DbSeed(new Context(options: new DbContextOptionsBuilder().UseSqlite(@"Data Source=.\Data\Data.db").Options)))
     {
         seed.Seed();
     }
     CreateHostBuilder(args).Build().Run();
 }
Пример #30
0
 protected void Application_Start()
 {
     CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("es-US");
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     DbSeed.SeedRolesAndUsers();
     DbSeed.SeedMovies().GetAwaiter().GetResult();
 }