Example #1
0
        public void GetsAllCompetitorsFromDatabase()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetsAllCompetitorsFromDatabaseDB")
                          .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));

                Assert.AreEqual(data.ToList(), business.GetAllCompetitors());
            }
        }
Example #2
0
        public void DeleteCompetitor()
        {
            var data = new List <Competitors>()
            {
                new Competitors {
                    Id = 1, FullName = "Competitor1"
                },
                new Competitors {
                    Id = 2, FullName = "Competitor2"
                },
                new Competitors {
                    Id = 3, FullName = "Competitor3"
                },
            }.AsQueryable();
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteCompetitorDB")
                          .Options;

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

                business.DeleteCompetitorById(2);

                Assert.AreEqual(2, business.GetAllCompetitors().Count);
            }
        }
Example #3
0
        /// <summary>
        /// "Calls" method "GetAllCompetitors" from CompetitorsBusiness.
        /// Then it shows all competitors in table Competitors.
        /// </summary>
        public void GetAllCompetitors()
        {
            Console.WriteLine("Competitors: ");
            List <Competitors> competitors = competitorsBusiness.GetAllCompetitors();

            if (competitors.Count == 0)
            {
                Console.WriteLine("There are no competitors in the table!");
            }
            else
            {
                Console.WriteLine(new string(' ', 2) + "Id" + new string(' ', 2)            //6
                                  + new string(' ', 13) + "FullName" + new string(' ', 13)  //34
                                  + new string(' ', 5) + "BirthDate" + new string(' ', 5)   //19
                                  + new string(' ', 2) + "Age" + new string(' ', 2)         //8
                                  + new string(' ', 2) + "Gender" + new string(' ', 2)      //10
                                  + new string(' ', 2) + "Weight" + new string(' ', 2)      //10
                                  + new string(' ', 10) + "TownName" + new string(' ', 10)  //28
                                  + new string(' ', 18) + "ClubName" + new string(' ', 18)  //44
                                  + new string(' ', 10) + "CoachName" + new string(' ', 10) //29
                                  + new string(' ', 6) + "SportName" + new string(' ', 6)); //21
                Console.WriteLine(new string('-', 210));
                foreach (var competitor in competitors)
                {
                    var    town      = townsBusiness.GetTownById(competitor.TownId);
                    string clubName  = GetClubAndCoachNames(competitor, "club");
                    string coachName = GetClubAndCoachNames(competitor, "coach");
                    var    sport     = sportsBusiness.GetSportById(competitor.SportId);
                    string output    = $"{competitor.Id}" + new string(' ', 6 - competitor.Id.ToString().Length)
                                       + $"{competitor.FullName}" + new string(' ', 34 - competitor.FullName.Length)
                                       + $"{competitor.BirthDate}" + new string(' ', 19 - competitor.BirthDate.Length)
                                       + new string(' ', 2) + $"{competitor.Age}" + new string(' ', 2)
                                       + new string(' ', 3) + $"{competitor.Gender}" + new string(' ', 8 - competitor.Gender.Length)
                                       + new string(' ', 3) + $"{competitor.Weight}" + new string(' ', 9 - competitor.Weight.Length)
                                       + $"{town.Name}" + new string(' ', 28 - town.Name.Length)
                                       + $"{clubName}" + new string(' ', 44 - clubName.Length)
                                       + $"{coachName}" + new string(' ', 29 - coachName.Length)
                                       + $"{sport.Name}" + new string(' ', 21 - sport.Name.Length);
                    Console.WriteLine(output);
                }
                Console.WriteLine(new string('-', 210));
            }
        }