public void GetsAllTownsFromDatabase() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "GetsAllCompetitorsFromDatabaseDB") .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)); Assert.AreEqual(data.ToList(), business.GetAllTowns()); } }
public void DeleteTown() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "DeleteTownDB") .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(town => business.AddTown(town)); business.DeleteTownById(2); Assert.AreEqual(2, business.GetAllTowns().Count); } }
/// <summary> /// "Calls" method "GetAllTowns" from TownsBusiness. /// Then it shows all towns in table Towns. /// </summary> public void GetAllTowns() { Console.WriteLine("Towns: "); List <Towns> towns = townsBusiness.GetAllTowns(); if (towns.Count == 0) { Console.WriteLine("There are no towns in the table!"); } else { Console.WriteLine("Id" + new string(' ', 4) + "Name" + new string(' ', 28) + "Country"); Console.WriteLine(new string('-', 68)); foreach (var town in towns) { var country = countriesBusiness.GetCountryById(town.CountryId); string output = $"{town.Id}" + new string(' ', 6 - town.Id.ToString().Length) + $"{town.Name}" + new string(' ', 28 - town.Name.Length) + $"{country.Name}" + new string(' ', 34 - country.Name.Length); Console.WriteLine(output); } Console.WriteLine(new string('-', 68)); } }