Beispiel #1
0
        public void TestUpdateTowns()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "TestUpdateTownsDB")
                          .Options;

            var data = new List <Towns>()
            {
                new Towns {
                    Id = 1, Name = "Town1"
                },
                new Towns {
                    Id = 2, Name = "Town2"
                },
                new Towns {
                    Id = 3, Name = "Town3"
                },
            }.AsQueryable();

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

                Towns c = business.GetTownById(2); c.Name = "Town22";
                business.UpdateTown(c);

                Assert.AreEqual("Town22", business.GetTownById(2).Name);
            }
        }
Beispiel #2
0
        /// <summary>
        /// After the user has inputed id, the program "Calls" method "GetTownById" from TownsBusiness.
        /// Shows the Town who has this id.
        /// </summary>
        public void GetTownById()
        {
            Console.WriteLine("Enter Town Id to fetch: ");
            int   id   = int.Parse(Console.ReadLine());
            Towns town = townsBusiness.GetTownById(id);

            if (town != null)
            {
                PrintTown(town);
            }
            else
            {
                Console.WriteLine($"There is no town with id = {id} in the table!");
            }
        }
Beispiel #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));
            }
        }
Beispiel #4
0
        public void GetTownById()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetTownByIdDB")
                          .Options;

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                business.AddTown(new Towns {
                    Id = 1, Name = "Town1"
                });
                business.AddTown(new Towns {
                    Id = 2, Name = "Town2"
                });
                business.AddTown(new Towns {
                    Id = 3, Name = "Town3"
                });

                Towns c = business.GetTownById(1);
                Assert.AreEqual(1, c.Id);
            }
        }