Beispiel #1
0
        public void GetCompetitorByName()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetCompetitorByNameDB")
                          .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.GetCompetitorByName("Competitor1");
                Assert.AreEqual("Competitor1", c.FullName);
            }
        }
Beispiel #2
0
        /// <summary>
        /// After the user has inputed name, the program "Calls" method "GetCompetitorByName" from CompetitorsBusiness.
        /// Shows the Competitor who has this name.
        /// </summary>
        public void GetCompetitorByName()
        {
            Console.Write("Enter Competitor Name to fetch: ");
            string name       = Console.ReadLine();
            var    competitor = competitorsBusiness.GetCompetitorByName(name);
            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 Name = {name} in the table!");
            }
        }