public void DeleteCoach() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "DeleteCoachDB") .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(); //да не забравяш options using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { CoachesBusiness business = new CoachesBusiness(context); data.ToList().ForEach(c => business.AddCoach(c)); business.DeleteCoachById(2); Assert.AreEqual(2, business.GetAllCoaches().Count); } }
/// <summary> /// Finds the town wished to be deleted. /// Passes the information to CoachesBusinessiness, using the method "DeleteCoachById". /// </summary> public void DeleteCoachById() { Console.Write("Enter ID to delete: "); int id = int.Parse(Console.ReadLine()); if (coachesBusiness.GetCoachById(id) == null) { Console.WriteLine($"There is no club with ID = {id} in the table!"); } else { coachesBusiness.DeleteCoachById(id); Console.WriteLine("Done!"); } }