public PlantCategoriesControllerTest()
        {
            _dbOptions = new DbContextOptionsBuilder <PlantListingContext>()
                         .UseInMemoryDatabase(databaseName: "in-memory plant categories")
                         .Options;

            using (var dbContext = new PlantListingContext(_dbOptions))
            {
                if (!dbContext.PlantCategories.Any())
                {
                    dbContext.PlantCategories.AddRange(PlantListingContextSeed.GetPreconfiguredPlantCategories());
                }

                dbContext.SaveChanges();
            }
        }
示例#2
0
        public WeightUnitsControllerTest()
        {
            _dbOptions = new DbContextOptionsBuilder <PlantListingContext>()
                         .UseInMemoryDatabase(databaseName: "in-memory weight units")
                         .Options;

            using (var dbContext = new PlantListingContext(_dbOptions))
            {
                if (!dbContext.WeightUnits.Any())
                {
                    dbContext.WeightUnits.AddRange(PlantListingContextSeed.GetPreconfiguredWeightUnits());
                }

                dbContext.SaveChanges();
            }
        }
示例#3
0
        public void Configure(EntityTypeBuilder <WeightUnit> builder)
        {
            builder.ToTable("WeightUnit");

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
            .UseHiLo("weight_unit_hilo")
            .IsRequired();

            builder.Property(cb => cb.Unit)
            .IsRequired()
            .HasMaxLength(50);

            // To seed data
            builder.HasData(PlantListingContextSeed.GetPreconfiguredWeightUnits());
        }
示例#4
0
        public void Configure(EntityTypeBuilder <PlantCategory> builder)
        {
            builder.ToTable("PlantCategory");

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
            .UseHiLo("plant_category_hilo")
            .IsRequired();

            builder.Property(cb => cb.Category)
            .IsRequired()
            .HasMaxLength(100);

            // To seed data
            builder.HasData(PlantListingContextSeed.GetPreconfiguredPlantCategories());
        }
        public void Configure(EntityTypeBuilder <PlantDetails> builder)
        {
            builder.ToTable("PlantDetails");

            builder.HasKey(ci => ci.PlantDetailsId);

            builder.Property(ci => ci.PlantDetailsId)
            .UseHiLo("plant_details_hilo")
            .IsRequired();

            builder.Property(ci => ci.Name)
            .IsRequired(true)
            .HasMaxLength(100);

            builder.Property(ci => ci.Description)
            .IsRequired(false)
            .HasMaxLength(500);

            builder.Property(ci => ci.CategoryId)
            .IsRequired(true);

            builder.Property(ci => ci.Price)
            .IsRequired(true)
            .HasPrecision(18, 2);

            builder.Property(ci => ci.Weight)
            .IsRequired(true)
            .HasPrecision(18, 2);

            builder.Property(ci => ci.UnitId)
            .IsRequired(true);

            builder.Property(ci => ci.Stock)
            .IsRequired(true);

            builder.Property(ci => ci.ImageName)
            .IsRequired(false);

            builder.Property(ci => ci.UserId)
            .IsRequired(true)
            .HasMaxLength(100);

            // To seed data
            builder.HasData(PlantListingContextSeed.GetPreconfiguredPlantDetails());
        }
        private void SeedDBContext(DbContextOptions <PlantListingContext> dbOptions)
        {
            using (var dbContext = new PlantListingContext(dbOptions))
            {
                if (!dbContext.PlantCategories.Any())
                {
                    dbContext.PlantCategories.AddRange(PlantListingContextSeed.GetPreconfiguredPlantCategories());
                }

                if (!dbContext.WeightUnits.Any())
                {
                    dbContext.WeightUnits.AddRange(PlantListingContextSeed.GetPreconfiguredWeightUnits());
                }

                if (!dbContext.PlantDetails.Any())
                {
                    dbContext.PlantDetails.AddRange(PlantListingContextSeed.GetPreconfiguredPlantDetails());
                }

                dbContext.SaveChanges();
            }
        }