public void UpdateCityTests() { //Arrange CitySqlDAO dao = new CitySqlDAO(ConnectionString); IList <City> cities = dao.GetCitiesByCountryCode("USA"); City cityToUpdate = cities[0]; //Act cityToUpdate.Population = 5; dao.UpdateCity(cityToUpdate); //Assert Assert.AreEqual(5, cityToUpdate.Population); //THIS TEST IS ONLY TESTING MEMORY NOT THE DB IList <City> updatedCities = dao.GetCitiesByCountryCode("USA"); City fromDB = null; foreach (City c in updatedCities) { if (c.CityId == cityToUpdate.CityId) { fromDB = c; break; } } Assert.AreEqual(5, fromDB.Population); }
public void GetCitiesByCountryCode_Should_ReturnRightNumberOfCities(string countryCode, int expectedCityCount) { CitySqlDAO dao = new CitySqlDAO(ConnectionString); IList <City> cities = dao.GetCitiesByCountryCode(countryCode); Assert.AreEqual(expectedCityCount, cities.Count); }
//public IActionResult GetCities(string countryCode) //{ // CitySqlDAO dao = new CitySqlDAO(connectionString); // IList<City> cities = dao.GetCities(countryCode); // return View(cities); //} //public IActionResult GetCities(string countryCode, string district) //{ // CitySqlDAO dao = new CitySqlDAO(connectionString); // IList<City> cities = dao.GetCities(countryCode, district); // return View(cities); //} public IActionResult GetCities(CityView city) { CitySqlDAO dao = new CitySqlDAO(connectionString); IList <City> cities = dao.GetCities(city.CountryCode, city.district); return(View(cities)); }
static void Main(string[] args) { // Select all countries //GetAllCountries(); // Get a count of all countries //GetCountryCount(); // Select cities that belong to a country code //GetCitiesForCountryCode("USA"); //Console.ReadKey(); //return; // TODO: Un-comment the Configuration builder and place the connection string in appsettings.json //IConfigurationBuilder builder = new ConfigurationBuilder() // .SetBasePath(Directory.GetCurrentDirectory()) // .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); //IConfigurationRoot configuration = builder.Build(); //string connectionString = configuration.GetConnectionString("World"); ICityDAO cityDAO = new CitySqlDAO(connectionString); ICountryDAO countryDAO = new CountrySqlDAO(connectionString); ILanguageDAO languageDAO = new LanguageSqlDAO(connectionString); WorldGeographyCLI cli = new WorldGeographyCLI(cityDAO, countryDAO, languageDAO); cli.RunCLI(); }
static void Main(string[] args) { // This code reads the connection string from appsettings.json // Add the connection string to appsettings.json and un-comment the following lines to read the configuration IConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); string connectionString = configuration.GetConnectionString("World"); // TEMPORARY: DB EXAMPLE (vanilla, no DAO) //ReadCities(); //return; ICountryDAO countryDAO = new CountrySqlDAO(connectionString); ICityDAO cityDAO = new CitySqlDAO(connectionString); // TODO 14a: Create a Model for CountryLanguage // TODO 14b: Create a CountryLanguageSqlDAO class (GetLanguages(string countryCode)) // TODO 14c: Create an ICountryLanguageDAO interface ICountryLanguageDAO countryLanguageDAO = new CountryLanguageSqlDAO(connectionString); // Create a WorldDBMenu, passing in the country dao, and Run it WorldDBMenu menu = new WorldDBMenu(countryDAO, cityDAO, countryLanguageDAO); menu.Show(); // Say goodbye to the user... Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("Goodbye..."); Thread.Sleep(1500); }
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); }
static void Main(string[] args) { // This code reads the connection string from appsettings.json IConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); // Get the connection string for the World database string connectionString = configuration.GetConnectionString("World"); CitySqlDAO cityDAO = new CitySqlDAO(connectionString); List <City> cities = cityDAO.GetAllCities(); foreach (City city in cities) { Console.WriteLine($"{city.Id,5} {city.Name,-40} {city.Population,12:N0} "); } Console.ReadLine(); cities = cityDAO.GetCitiesForCountryCode("GBR"); foreach (City city in cities) { Console.WriteLine($"{city.Id,5} {city.Name,-40} {city.Population,12:N0} "); } // GetAllCities(connectionString) // GetCitiesForCountry(connectionString, "USA"); Console.ReadLine(); return; // TODO: Create a City Model class // TODO: Create a City SQL DAO Class (GetCities, GetCitiesByCountryCode) // TODO: List the cities of the world // TODO: List the cities in a Country (code) // TODO: Add a City to the US // TODO: Create instances of DAOs to pass into the menus // TODO: Create a WorldDBMenu and Run it WorldDBMenu menu = new WorldDBMenu(); menu.Run(); // Say goodbye to the user... Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("Goodbye..."); Thread.Sleep(1500); }
public void GetCitiesByCountryCodeTest() { // Arrange CitySqlDAO citySqlDAO = new CitySqlDAO(connectionString); // Act IList <City> cities = citySqlDAO.GetCitiesByCountryCode("USA"); // Assert Assert.IsTrue(cities.Count > 0); }
static void Main(string[] args) { ICityDAO cityDAO = new CitySqlDAO(@"Server=.\SQLEXPRESS;Database=World;Trusted_Connection=True;"); ICountryDAO countryDAO = new CountrySqlDAO(@"Server=.\SQLExpress;Database=World;Trusted_Connection=True;"); ILanguageDAO languageDAO = new LanguageSqlDAO(@"Server=.\SQLEXPRESS;Database=World;Trusted_Connection=True;"); WorldGeographyCLI cli = new WorldGeographyCLI(cityDAO, countryDAO, languageDAO); cli.RunCLI(); }
public void GetVenueCityShouldReturnVenueCity(int cityNum, string expectedCityName) { //Arrange CitySqlDAO dao = new CitySqlDAO(ConnectionString); //Act City cityPlace = dao.GetVenueCity(cityNum); //Assert Assert.AreEqual(expectedCityName, cityPlace.Name); }
public void GetCitiesByCountryCode_Should_ReturnRightNumberOfCities(string countryCode, int expectedCityCount) { // Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); // Act IList <City> cities = dao.GetCitiesByCountryCode(countryCode); // Assert Assert.IsTrue(cities.Count >= expectedCityCount); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { CitySqlDAO citySqlDAO = new CitySqlDAO(@"Data Source=.\SQLEXPRESS;Initial Catalog=World;Integrated Security=True"); List <string> countryCodes = citySqlDAO.GetCountryCodes().ToList(); City city = (City)validationContext.ObjectInstance; if (!countryCodes.Contains(city.CountryCode)) { return(new ValidationResult("Country Code does not exist. Please try again.")); } return(ValidationResult.Success); }
public void GetCitiesByCountryCodeTest(string code, int expectedCount) { // Perform our test // Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); // Act IList <City> cities = dao.GetCitiesByCountryCode(code); // Assert Assert.AreEqual(expectedCount, cities.Count); }
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 GetCitiesByCountryCode_Should_ReturnRightNumberOfCities(string countryCode, int expectedValue) { // Arrange CitySqlDAO dao = new CitySqlDAO(ConnectionString); // Act IList <City> cities = dao.GetCitiesByCountryCode(countryCode); // Assert Assert.AreEqual(expectedValue, cities.Count); }
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_IncreaseCountBy1() { CitySqlDAO dao = new CitySqlDAO(ConnectionString); // Arrange int startingRowCount = GetRowCount("city"); AddNewCity(dao); // Assert int endingRowCount = GetRowCount("city"); Assert.AreNotEqual(startingRowCount, endingRowCount); }
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); }
public void GetCityById_ShouldFindCity() { // Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); // Act - Call GetCity..passing the id that was added during our test setup. City city; city = dao.GetCityById(this.newCityId); // Assert - We found Smallville Assert.IsNotNull(city); Assert.AreEqual("Smallville", city.Name); }
static void Main(string[] args) { // This code reads the connection string from appsettings.json // TODO 03: Add the connection string to appsettings.json and un-comment the following lines to read the configuration IConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); string connectionString = configuration.GetConnectionString("World"); // TEMPORARY: DB EXAMPLE (vanilla, no DAO) //ReadCities(); //return; /* CREATED JUST TO TEST MENU * CountrySqlDAO dao = new CountrySqlDAO(connectionString); * List<Country> list = dao.GetCountries("Asia"); * * Country country = dao.GetCountry("ZZZ"); * * country = dao.GetCountry("USA"); */ // TODO 04a: Create a Model for Country to go with the City model we already have // TODO 04b: Create a CountrySqlDAO class (GetCountries, GetCountries(continent), GetCountry(code)) // TODO 04c: Create an ICountryDAO interface // TODO 10: Create a CitySqlDAO class (GetCitiesByCountryCode) // TODO 10a: Create an ICityDAO interface // TODO 14a: Create a Model for CountryLanguage // TODO 14b: Create a CountryLanguageSqlDAO class (GetLanguages(string countryCode)) // TODO 14c: Create an ICountryLanguageDAO interface ICountryDAO countryDAO = new CountrySqlDAO(connectionString); ICityDAO cityDAO = new CitySqlDAO(connectionString); // TODO 05b: Create a WorldDBMenu, passing in the country dao, and Run it WorldDBMenu menu = new WorldDBMenu(countryDAO, cityDAO); menu.Show(); // Say goodbye to the user... Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("Goodbye..."); Thread.Sleep(1500); }
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 }
static void Main(string[] args) { IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); string connectionString = configuration.GetConnectionString("World"); ICityDAO cityDAO = new CitySqlDAO(connectionString); ICountryDAO countryDAO = new CountrySqlDAO(connectionString); ILanguageDAO languageDAO = new LanguageSqlDAO(connectionString); WorldGeographyCLI cli = new WorldGeographyCLI(cityDAO, countryDAO, languageDAO); cli.RunCLI(); }
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 }
static void Main(string[] args) { //IConfigurationBuilder builder = new ConfigurationBuilder() // .SetBasePath(Directory.GetCurrentDirectory()) // .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); //IConfigurationRoot configuration = builder.Build(); //string connectionString = configuration.GetConnectionString("World"); ICityDAO cityDAO = new CitySqlDAO(@"Data Source=.\SQLEXPRESS;Initial Catalog=World;Integrated Security=True"); ICountryDAO countryDAO = new CountrySqlDAO(@"Data Source=.\SQLEXPRESS;Initial Catalog=World;Integrated Security=True"); ILanguageDAO languageDAO = null; WorldGeographyCLI cli = new WorldGeographyCLI(cityDAO, countryDAO, languageDAO); cli.RunCLI(); }
public void GetCitiesByCountryCodeTest() { // Initialize data in the DB // SetupDatabase(); // Perform our test // ------ Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); // ------ Act IList <City> cities = dao.GetCitiesByCountryCode("USA"); // ------ Assert Assert.AreEqual(2, cities.Count); // Go back to the original DB values // CleanupDatabase(); }
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); }
public void GetCityById_ShouldFindCity() { // Arrange CitySqlDAO dao = new CitySqlDAO(connectionString); // Act // TODO: We need to get a valid city Id from our script // Uh-oh...how do I know what city ids exist in the db? City city; city = dao.GetCityById(0); // Assert - We found Smallville Assert.IsNotNull(city); Assert.AreEqual("Smallville", city.Name); }
static void Main(string[] args) { //IConfigurationBuilder builder = new ConfigurationBuilder() // .SetBasePath(Directory.GetCurrentDirectory()) // .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); //IConfigurationRoot configuration = builder.Build(); //string connectionString = configuration.GetConnectionString("World"); ICityDAO cityDAO = new CitySqlDAO(@"Server=.\SQLEXPRESS;Database=World;Trusted_Connection=True;"); ICountryDAO countryDAO = new CountrySqlDAO(@"Server=.\SQLEXPRESS;Database=World;Trusted_Connection=True;"); ILanguageDAO languageDAO = new LanguageSqlDAO(@"Server=.\SQLEXPRESS;Database=World;Trusted_Connection=True;"); WorldGeographyCLI cli = new WorldGeographyCLI(cityDAO, countryDAO, languageDAO); cli.RunCLI(); }
static void Main(string[] args) { IConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); string connectionString = configuration.GetConnectionString("World"); ICityDAO cityDAO = new CitySqlDAO(connectionString); ICountryDAO countryDAO = new CountrySqlDAO(connectionString); ILanguageDAO languageDAO = new LanguageSqlDAO(connectionString); WorldDBMenu menu = new WorldDBMenu(cityDAO, countryDAO, languageDAO); menu.Run(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("Goodbye..."); Thread.Sleep(1500); }