Beispiel #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);
        }
Beispiel #2
0
        public static int SeedCard(DbContextOptions <QdbContext> options, string leagueIdentifier, int cardNumber, string playerLastName, string playerFirstName, string teamCity, string teamName, int year, string setName, bool auFlag, bool rcFlag, bool notableFlag, bool gradedFlag, decimal value, decimal cost)
        {
            using (var context = new QdbContext(options))
            {
                var league = LeagueCodeService.Select(leagueIdentifier);

                string personIdentifier = string.Format("{0} {1}", playerLastName, playerFirstName);
                string teamIdentifier   = string.Format("{0} {1}", teamCity, teamName);

                var person = context.People.SingleOrDefault(x => x.Identifier == personIdentifier);
                if (person == null)
                {
                    person = AddPerson(context, personIdentifier, playerLastName, playerFirstName, null, null, false, false, false, league.Sport, null);
                }

                var team = context.Teams.SingleOrDefault(x => x.Identifier == teamIdentifier);
                if (team == null)
                {
                    team = AddTeam(context, teamIdentifier, teamCity, teamName, league, false);
                }

                var company = context.Sets.SingleOrDefault(x => x.Name == setName);
                if (company == null)
                {
                    company = AddSet(context, setName);
                }

                var card = AddCollectible(context, league, person, team, company, cardNumber, year, notableFlag, auFlag, rcFlag, gradedFlag, value, cost);

                return(card.Id);
            }
        }
Beispiel #3
0
        public void Select_Succeeds()
        {
            // Run the test
            var leagues = LeagueCodeService.Select();


            // Verify results match expected results
            Assert.NotNull(leagues);
            Assert.True(leagues.Count > 0);
        }
Beispiel #4
0
        public void Select_WithValidId_Succeeds()
        {
            int nflId = LeagueCodeService.NFL.Id;

            // Run test
            var league = LeagueCodeService.Select(nflId);

            // Verify that card was returned
            Assert.NotNull(league);
            Assert.Equal(league.Id, nflId);
        }
Beispiel #5
0
        public List <League> Get()
        {
            var leaguesData = LeagueCodeService.Select();

            var leagues = leaguesData
                          .Select(x => new League
            {
                Id            = x.Id,
                Name          = x.Name,
                SportId       = x.SportId,
                SearchDefault = x.SearchDefault
            })
                          .ToList();

            return(leagues);
        }
Beispiel #6
0
        public League Get(int id)
        {
            var leagueData = LeagueCodeService.Select(id);

            if (leagueData == null)
            {
                throw new DataNotFoundException("League not found.  Invalid id provided.");
            }

            return(new League
            {
                Id = leagueData.Id,
                Name = leagueData.Name,
                SportId = leagueData.SportId,
                SearchDefault = leagueData.SearchDefault
            });
        }
Beispiel #7
0
        public static int SeedTeam(DbContextOptions <QdbContext> options, string identifier, string city, string nickname, string leagueIdentifier, bool notableFlag)
        {
            using (var context = new QdbContext(options))
            {
                var league = LeagueCodeService.Select(leagueIdentifier);

                var team = context.Teams.SingleOrDefault(x => x.Identifier == identifier);
                if (team != null)
                {
                    throw new Exception("Team already exists");
                }

                team = AddTeam(context, identifier, city, nickname, league, notableFlag);

                return(team.Id);
            }
        }
Beispiel #8
0
        public void Select_WithInvalidId_Fails()
        {
            try
            {
                int invalidLeagueId = LeagueCodeService.Select().Count + 1;

                // Run test
                var league = LeagueCodeService.Select(invalidLeagueId);

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