コード例 #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 cardTypes = CardTypeCodeService.Select();


            // Verify results match expected results
            Assert.NotNull(cardTypes);
            Assert.True(cardTypes.Count > 0);
        }
コード例 #3
0
        public void Select_WithValidId_Succeeds()
        {
            int playerId = CardTypeCodeService.Player.Id;

            // Run test
            var cardType = CardTypeCodeService.Select(playerId);

            // Verify that card was returned
            Assert.NotNull(cardType);
            Assert.Equal(cardType.Id, playerId);
        }
コード例 #4
0
        public void Select_WithInvalidId_Fails()
        {
            try
            {
                int invalidCardTypeId = CardTypeCodeService.Select().Count + 1;

                // Run test
                var cardType = CardTypeCodeService.Select(invalidCardTypeId);

                // 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();
            }
        }