예제 #1
0
        public void TestUpdateCompetitors()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "TestUpdateCompetitorsDB")
                          .Options;

            var data = new List <Competitors>()
            {
                new Competitors {
                    Id = 1, FullName = "Competitor1"
                },
                new Competitors {
                    Id = 2, FullName = "Competitor2"
                },
                new Competitors {
                    Id = 3, FullName = "Competitor3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                CompetitorsBusiness business = new CompetitorsBusiness(context);
                data.ToList().ForEach(c => business.AddCompetitors(c));

                Competitors c = business.GetCompetitorById(2); c.FullName = "Competitor22";
                business.UpdateCompetitor(c);

                Assert.AreEqual("Competitor22", business.GetCompetitorById(2).FullName);
            }
        }
예제 #2
0
        /// <summary>
        /// After the user has inputed id, the program "Calls" method "GetCompetitorById" from CompetitorsBusiness.
        /// Shows the Competitor who has this id.
        /// </summary>
        public void GetCompetitorById()
        {
            Console.Write("Enter Competitor ID to fetch: ");
            int    id         = int.Parse(Console.ReadLine());
            var    competitor = competitorsBusiness.GetCompetitorById(id);
            var    town       = townsBusiness.GetTownById(competitor.TownId);
            string clubName   = GetClubAndCoachNames(competitor, "club");
            string coachName  = GetClubAndCoachNames(competitor, "coach");
            var    sport      = sportsBusiness.GetSportById(competitor.SportId);

            if (competitor != null)
            {
                PrintCompetitor(competitor, town, clubName, coachName, sport);
            }
            else
            {
                Console.WriteLine($"There is no competitor with ID = {id} in the table!");
            }
        }
예제 #3
0
        public void GetCompetitorById()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetCompetitorByIdDB")
                          .Options;

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                CompetitorsBusiness business = new CompetitorsBusiness(context);
                business.AddCompetitors(new Competitors {
                    Id = 1, FullName = "Competitor1"
                });
                business.AddCompetitors(new Competitors {
                    Id = 2, FullName = "Competitor2"
                });
                business.AddCompetitors(new Competitors {
                    Id = 3, FullName = "Competitor3"
                });

                Competitors c = business.GetCompetitorById(1);
                Assert.AreEqual(1, c.Id);
            }
        }