public void TestUpdateCoaches() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "TestUpdateCoachesDB") .Options; var data = new List <Coaches>() { new Coaches { Id = 1, Name = "Coach1" }, new Coaches { Id = 2, Name = "Coach2" }, new Coaches { Id = 3, Name = "Coach3" }, }.AsQueryable(); using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { CoachesBusiness business = new CoachesBusiness(context); data.ToList().ForEach(c => business.AddCoach(c)); Coaches c = business.GetCoachById(2); c.Name = "Coach22"; business.UpdateCoach(c); Assert.AreEqual("Coach22", business.GetCoachById(2).Name); } }
/// <summary> /// Finds the coach wished to be updated. /// Makes the user to enter the new information. /// Then passes it to CoachesBusinessiness, using the method "UpdateCoach". /// </summary> public void UpdateCoach() { Console.Write("Enter ID to update: "); int id = int.Parse(Console.ReadLine()); Coaches coach = coachesBusiness.GetCoachById(id); if (coach == null) { Console.WriteLine($"There is no club with ID = {id} in the table!"); } else { Console.Write("Enter Coach Name: "); coach.Name = Console.ReadLine(); Console.Write("Enter Sport Name: "); string sportName = Console.ReadLine(); coach.SportId = sportsBusiness.GetSportByName(sportName).Id; coachesBusiness.UpdateCoach(coach); Console.WriteLine("Coach successfully updated!"); } }