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); } }
public void GetTownByName() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "GetTownByNameDB") .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(t => business.AddTown(t)); Towns t = business.GetTownByName("Town1"); Assert.AreEqual("Town1", t.Name); } }
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 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); } }
public void GetTownById() { var options = new DbContextOptionsBuilder <OlympicGamesDBContext>() .UseInMemoryDatabase(databaseName: "GetTownByIdDB") .Options; using (OlympicGamesDBContext context = new OlympicGamesDBContext(options)) { TownsBusiness business = new TownsBusiness(context); business.AddTown(new Towns { Id = 1, Name = "Town1" }); business.AddTown(new Towns { Id = 2, Name = "Town2" }); business.AddTown(new Towns { Id = 3, Name = "Town3" }); Towns c = business.GetTownById(1); Assert.AreEqual(1, c.Id); } }
/// <summary> /// Makes the user to input data about the town. /// Passes the information to TownsBusiness, using the method "AddTown" /// </summary> public void AddTown() { Towns town = new Towns(); Console.Write("Enter name: "); town.Name = Console.ReadLine(); Console.Write("Enter Country Name: "); string countryName = Console.ReadLine(); town.CountryId = countriesBusiness.GetCountryByName(countryName).Id; townsBusiness.AddTown(town); Console.WriteLine($"New town successfully added!"); }