示例#1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Set up the many to many relationship between Person and Sport
            modelBuilder.Entity <PersonSport>()
            .HasKey(sc => new { sc.PersonId, sc.SportId });

            modelBuilder.Entity <PersonSport>()
            .HasOne <Person>(sc => sc.Person)
            .WithMany(s => s.PersonSports)
            .HasForeignKey(sc => sc.PersonId);

            modelBuilder.Entity <PersonSport>()
            .HasOne <Sport>(sc => sc.Sport)
            .WithMany(s => s.PersonSports)
            .HasForeignKey(sc => sc.SportId);

            //modelBuilder.Entity<PersonSport>()
            //    .HasOne<Sport>(sc => sc.Sport)
            //    .WithMany(s => s.PersonSports)
            //    .HasForeignKey(sc => sc.SportId);

            // Seed the data in code tables constant values
            modelBuilder.Entity <Sport>().HasData(SportCodeService.Select());
            modelBuilder.Entity <CollectibleStatus>().HasData(CollectibleStatusCodeService.Select());
            modelBuilder.Entity <CardType>().HasData(CardTypeCodeService.Select());
            modelBuilder.Entity <CollectibleType>().HasData(CollectibleTypeCodeService.Select());
            modelBuilder.Entity <League>().HasData(LeagueCodeService.Select());
            modelBuilder.Entity <ProductStatus>().HasData(ProductStatusCodeService.Select());
            modelBuilder.Entity <ProductType>().HasData(ProductTypeCodeService.Select());

            base.OnModelCreating(modelBuilder);
        }
示例#2
0
        public void Select_Succeeds()
        {
            // Run the test
            var productStatuses = ProductStatusCodeService.Select();


            // Verify results match expected results
            Assert.NotNull(productStatuses);
            Assert.True(productStatuses.Count > 0);
        }
示例#3
0
        public void Select_WithValidId_Succeeds()
        {
            int forSaleId = ProductStatusCodeService.ForSale.Id;

            // Run test
            var productStatus = ProductStatusCodeService.Select(forSaleId);

            // Verify that card was returned
            Assert.NotNull(productStatus);
            Assert.Equal(productStatus.Id, forSaleId);
        }
示例#4
0
        public void Select_WithInvalidId_Fails()
        {
            try
            {
                int invalidProductStatusId = ProductStatusCodeService.Select().Count + 1;

                // Run test
                var productStatus = ProductStatusCodeService.Select(invalidProductStatusId);

                // Fail test if exception is not thrown
                Assert.Equal(1, 0);
            }
            catch (InvalidIdException invalidIdException)
            {
                Assert.NotNull(invalidIdException);
            }
            catch
            {
                // Fail test if expected exception not thrown
                Assert.Equal(1, 0);
            }
        }
示例#5
0
        public static void SeedCodeValues(DbContextOptions <QdbContext> options)
        {
            using (var context = new QdbContext(options))
            {
                if (context.CollectibleStatuses.Count() > 0)
                {
                    return;
                }

                foreach (var cardType in CardTypeCodeService.Select())
                {
                    context.CardTypes.Add(cardType);
                }
                foreach (var collectibleStatus in CollectibleStatusCodeService.Select())
                {
                    context.CollectibleStatuses.Add(collectibleStatus);
                }
                foreach (var collectibleType in CollectibleTypeCodeService.Select())
                {
                    context.CollectibleTypes.Add(collectibleType);
                }
                foreach (var league in LeagueCodeService.Select())
                {
                    context.Leagues.Add(league);
                }
                foreach (var productStatus in ProductStatusCodeService.Select())
                {
                    context.ProductStatuses.Add(productStatus);
                }
                foreach (var sport in SportCodeService.Select())
                {
                    context.Sports.Add(sport);
                }

                context.SaveChanges();
            }
        }