Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void Select_Succeeds()
        {
            // Run the test
            var collectibleStatuses = CollectibleStatusCodeService.Select();


            // Verify results match expected results
            Assert.NotNull(collectibleStatuses);
            Assert.True(collectibleStatuses.Count > 0);
        }
Exemplo n.º 3
0
        public void Select_WithValidId_Succeeds()
        {
            int availableId = CollectibleStatusCodeService.Available.Id;

            // Run test
            var collectibleStatus = CollectibleStatusCodeService.Select(availableId);

            // Verify that card was returned
            Assert.NotNull(collectibleStatus);
            Assert.Equal(collectibleStatus.Id, availableId);
        }
Exemplo n.º 4
0
        public void Select_WithInvalidId_Fails()
        {
            try
            {
                int invalidCollectibleStatusId = CollectibleStatusCodeService.Select().Count + 1;

                // Run test
                var collectibleStatus = CollectibleStatusCodeService.Select(invalidCollectibleStatusId);

                // 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);
            }
        }
Exemplo n.º 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();
            }
        }