public void AddCity_Should_IncreaseCountBy1() { // Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); //IList<City> list = dao.GetCitiesByCountryCode("USA"); //int cityCountBefore = list.Count; // Above code replaced by GetCount() int cityCountBefore = GetCount("city"); // Act City city = new City(); city.CountryCode = "USA"; city.Name = "East Cleveland"; city.District = "Ohio"; city.Population = 75000; int addedCity = dao.AddCity(city); // Assert - City count goes up by 1 //list = dao.GetCitiesByCountryCode("USA"); //int cityCountAfter = list.Count; int cityCountAfter = GetCount("city"); Assert.AreEqual(cityCountBefore + 1, cityCountAfter); }
public void AddCityTest_BadCountry() { City city = new City() { CountryCode = "XYZ", Name = "Who cares", Population = 1, District = "Who cares" }; CitySqlDAO dao = new CitySqlDAO(connectionString); dao.AddCity(city); }
private City AddNewCity(CitySqlDAO dao) { City city = new City(); city.CountryCode = "USA"; city.Name = "Doesn't matter"; city.Population = 1; city.District = "Doesn't matter"; // Act dao.AddCity(city); return(city); }
public void AddCity_Should_Fail_IfCountryDoesNotExist() { City city = new City() { CountryCode = "XYZ", Name = "Doesn't matter", Population = 1, District = "Doesn't matter" }; CitySqlDAO dao = new CitySqlDAO(ConnectionString); dao.AddCity(city); }
public void AddCityTest() { int countBefore = 0; int countAfter = 0; transaction = new TransactionScope(); //Arrange try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand command = new SqlCommand( "SELECT count(*) FROM city;", conn); countBefore = (int)command.ExecuteScalar(); CitySqlDAO dao = new CitySqlDAO(connectionString); City city = new City(); city.Name = "Johntown"; city.CountryCode = "GBR"; city.Population = 4; city.District = "England"; //Act dao.AddCity(city); command = new SqlCommand( "SELECT count(*) FROM city;", conn); countAfter = (int)command.ExecuteScalar(); //Assert Assert.AreEqual(countBefore + 1, countAfter); } } finally { transaction.Dispose(); } }
public void AddCity_Should_Fail_IfCountryDoesNotExist() { // Arrange City city = new City(); city.CountryCode = "ZZZ"; city.Name = "Test City"; city.Population = 123; city.District = "who cares"; CitySqlDAO dao = new CitySqlDAO(ConnectionString); // Act dao.AddCity(city); // Assert }
public void AddCity_Should_Fail_IfCountryDoesNotExist() { // Arrange City city = new City(); city.CountryCode = "XYZ"; city.Name = "Doesn't matter"; city.Population = 1; city.District = "Doesn't matter"; CitySqlDAO dao = new CitySqlDAO(ConnectionString); // Act dao.AddCity(city); // Assert // SqlException is expected to be thrown }
public void AddCity_Should_IncreaseCountBy1() { // Arrange City city = new City(); city.CountryCode = "USA"; city.Name = "Doesn't matter"; city.Population = 1; city.District = "Doesn't matter"; CitySqlDAO dao = new CitySqlDAO(ConnectionString); int startingRowCount = GetRowCount("city"); dao.AddCity(city); int endingRowCount = GetRowCount("city"); Assert.AreEqual(startingRowCount + 1, endingRowCount); }
private void AddCity() { string name = CLIHelper.GetString("Name of the city:"); string code = CLIHelper.GetString("Country code:"); string district = CLIHelper.GetString($"District {name} is in:"); int population = CLIHelper.GetInteger($"Population of {name}:"); City city = new City { CountryCode = code, Name = name, District = district, Population = population }; cityDAO.AddCity(city); Console.WriteLine("City added."); }
public void AddCity_Should_IncreaseCountBy1() { // Arrange City city = new City(); city.CountryCode = "USA"; city.Name = "Test City"; city.Population = 123; city.District = "who cares"; CitySqlDAO dao = new CitySqlDAO(ConnectionString); int startCount = GetRowCount("city"); // Act dao.AddCity(city); int endCount = GetRowCount("city"); // Assert Assert.AreEqual(startCount + 1, endCount); }
public void AddCity_Should_Fail_IfCountryDoesNotExist() { // Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); IList <City> list = dao.GetCitiesByCountryCode("USA"); int cityCountBefore = list.Count; // Act City city = new City(); city.CountryCode = "YYZ"; city.Name = "East Cleveland"; city.District = "Ohio"; city.Population = 75000; dao.AddCity(city); // Assert - City count goes up by 1 list = dao.GetCitiesByCountryCode("USA"); int cityCountAfter = list.Count; }
public void AddCity_Should_IncreaseCountBy1() { // Arrange CitySqlDAO dao = new CitySqlDAO(ConnectionString); City cincinnati = new City(); cincinnati.Name = "Cincinnati"; cincinnati.District = "OH"; cincinnati.CountryCode = "USA"; cincinnati.Population = 1; int rowsBefore = GetRowCount("city"); // Act dao.AddCity(cincinnati); int rowsAfter = GetRowCount("city"); // Assert int result = rowsAfter - rowsBefore; Assert.AreEqual(1, result); }