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); } }
/// <summary> /// Finds the town wished to be updated. /// Makes the user to enter the new information. /// Then passes it to TownsBusiness, using the method "UpdateTown". /// </summary> public void UpdateTown() { Console.Write("Enter Id: "); int id = int.Parse(Console.ReadLine()); Towns town = townsBusiness.GetTownById(id); if (town != null) { Console.Write("Enter new name: "); town.Name = Console.ReadLine(); Console.Write("Enter country name: "); town.CountryId = countriesBusiness.GetCountryByName(Console.ReadLine()).Id; townsBusiness.UpdateTown(town); } else { Console.WriteLine("Town not found!"); } Console.WriteLine("Town successfully updated!"); }