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

            var data = new List <Clubs>()
            {
                new Clubs {
                    Id = 1, Name = "Club1"
                },
                new Clubs {
                    Id = 2, Name = "Club2"
                },
                new Clubs {
                    Id = 3, Name = "Club3"
                },
            }.AsQueryable();

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

                Clubs c = business.GetClubById(2); c.Name = "Club22";
                business.UpdateClub(c);

                Assert.AreEqual("Club22", business.GetClubById(2).Name);
            }
        }
        /// <summary>
        /// Finds the club wished to be updated.
        /// Makes the user to enter the new information.
        /// Then passes it to ClubsBusiness, using the method "UpdateClub".
        /// </summary>
        public void UpdateClub()
        {
            Console.Write("Enter Club ID to update: ");
            int   id   = int.Parse(Console.ReadLine());
            Clubs club = clubsBusiness.GetClubById(id);

            if (club == null)
            {
                Console.WriteLine($"There is no club with ID = {id} in the table!");
            }
            else
            {
                Console.WriteLine("Enter Club Name: ");
                club.Name = Console.ReadLine();
                clubsBusiness.UpdateClub(club);

                Console.WriteLine("Club successfully updated!");
            }
        }