private void AddNewLanguage() { string countryCode = CLIHelper.GetString("Enter the country code the language is for:"); bool officialOnly = CLIHelper.GetBool("Is it official only? True/False "); int percentage = CLIHelper.GetInteger("What percentage is it spoken by?"); string name = CLIHelper.GetString("What is the name of the lanaguage?"); Language lang = new Language { CountryCode = countryCode, IsOfficial = officialOnly, Percentage = percentage, Name = name }; LanguageSqlDAL languageDal = new LanguageSqlDAL(DatabaseConnectionString); bool result = languageDal.AddNewLanguage(lang); if (result) { Console.WriteLine("Success!"); } else { Console.WriteLine("The new language was not inserted"); } }
public void GetLanguagesTest() { //Arrange LanguageSqlDAL languageDal = new LanguageSqlDAL(connectionString); //Act List <Language> languages = languageDal.GetLanguages("ABC", true); //Assert Assert.AreEqual(1, languages.Count); Assert.AreEqual("OfficialLanguage", languages[0].Name); }
private void GetLanguagesForCountry() { string countryCode = CLIHelper.GetString("Enter the country code you want to retrieve:"); bool officialOnly = CLIHelper.GetBool("Retrieve official languages only? True/False "); LanguageSqlDAL languageDal = new LanguageSqlDAL(DatabaseConnectionString); List <Language> languages = languageDal.GetLanguages(countryCode, officialOnly); Console.WriteLine(); Console.WriteLine($"Printing {languages.Count} languages for {countryCode}"); foreach (var language in languages) { Console.WriteLine(language); } }
public void RemoveLanguageTest_ReturnsFalseIfNotExists() { //Arrange LanguageSqlDAL dal = new LanguageSqlDAL(connectionString); Language deadLanguage = new Language() { CountryCode = "ABC", Name = "Nonexistent-Language" }; //Act bool didRemove = dal.RemoveLanguage(deadLanguage); //Assert Assert.IsFalse(didRemove); }
public void RemoveLanguageTest_ReturnsTrueIfExists() { //Arrange LanguageSqlDAL dal = new LanguageSqlDAL(connectionString); Language deadLanguage = new Language() { CountryCode = "ABC", Name = "OfficialLanguage" }; //Act bool didRemove = dal.RemoveLanguage(deadLanguage); //Assert Assert.IsTrue(didRemove); }
private void GetLanguagesForCountry() { string countryCode = CLIHelper.GetString("Enter the country code you want to retrieve:"); LanguageSqlDAL languageDal = new LanguageSqlDAL(DatabaseConnectionString); List <Language> languages = languageDal.GetLanguages(countryCode); Console.WriteLine(); Console.WriteLine($"Printing {languages.Count} languages for {countryCode}"); foreach (Language l in languages) { Console.WriteLine(l.Name.PadRight(30) + l.CountryCode.PadRight(5) + (l.IsOfficial ? "Official" : "Unofficial").PadRight(15) + (l.Percentage / 100.00).ToString("P").PadRight(5)); } }
public void AddNewLanguageTest() { //Arrange LanguageSqlDAL languageDal = new LanguageSqlDAL(connectionString); Language language = new Language { CountryCode = "ABC", IsOfficial = true, Name = "Test Language", Percentage = 100 }; //Act bool didWork = languageDal.AddNewLanguage(language); //Assert Assert.AreEqual(true, didWork); }
public void AddLanguage_ThrowsExceptionIfRowExists() { using (TransactionScope transaction = new TransactionScope()) { //Arrange CountrySqlDALTests.InsertFakeCountry("JRT", "Fake Country", "North America"); LanguageSqlDALTests.InsertFakeLanguage("JRT", "TEST LANGUAGE", true); LanguageSqlDAL testClass = new LanguageSqlDAL(connectionString); Language newLanguage = new Language(); newLanguage.CountryCode = "JRT"; newLanguage.Name = "TEST LANGUAGE"; newLanguage.IsOfficial = true; newLanguage.Percentage = 100; //Act bool output = testClass.AddNewLanguage(newLanguage); } }
public void LanguagesByCountry_OfficialLanguages() { using (TransactionScope transaction = new TransactionScope()) { // Arrange CountrySqlDALTests.InsertFakeCountry("JRT", "Joshtopia", "North America"); LanguageSqlDALTests.InsertFakeLanguage("JRT", "Official Language", true); LanguageSqlDALTests.InsertFakeLanguage("JRT", "Unofficial Languauge", false); LanguageSqlDAL testClass = new LanguageSqlDAL(connectionString); // Act List <Language> languages = testClass.GetLanguages("JRT", true); // Assert Assert.AreEqual(1, languages.Count); Assert.AreEqual("Official Language", languages[0].Name); } }