예제 #1
0
        public void TestMethod1()
        {
            // Arrange
            LanguageSqlDAO dao = new LanguageSqlDAO(connectionString);

            // Act
            IList <Language> list  = dao.GetLanguages("ZZZ");
            IList <Language> list2 = dao.GetLanguages("AAA");

            // Assert
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(0, list2.Count);
        }
예제 #2
0
        public void AddLanguage()
        {
            // Arrange
            Language lang = new Language();

            lang.CountryCode = "USA";
            lang.IsOfficial  = false;
            lang.Name        = "Wakandian";
            lang.Percentage  = 5;

            ILanguageDAO dao = new LanguageSqlDAO(ConnectionString);

            // Act
            int  beforeRowCount = GetRowCount("countrylanguage");
            bool result         = dao.AddNewLanguage(lang);

            // Assert
            Assert.IsTrue(result);

            ICollection <Language> allUSLanguages = dao.GetLanguages("USA");

            CollectionAssert.Contains((ICollection)allUSLanguages, lang);

            Assert.AreEqual(beforeRowCount + 1, GetRowCount("countrylanguage"));
        }
예제 #3
0
        public void GetLanguageByCountryCode()
        {
            // Arrange
            LanguageSqlDAO languageSqlDAO = new LanguageSqlDAO(connectionString);
            // Act
            IList <Language> languages = languageSqlDAO.GetLanguages(countryCodeToTest);

            // Assert
            Assert.IsTrue(languages.Count > 0);
        }
예제 #4
0
        public void GetLanguageBySpecificCountryCode(string countryCode, int expectedCount)
        {
            // Arrange
            LanguageSqlDAO languageSqlDAO = new LanguageSqlDAO(ConnectionString);

            // Act
            IList <Language> languages = languageSqlDAO.GetLanguages(countryCode);

            // Assert
            Assert.AreEqual(expectedCount, languages.Count);
        }
예제 #5
0
        public void TestUpdateLanguage()
        {
            //Arrange
            ILanguageDAO           dao            = new LanguageSqlDAO(ConnectionString);
            ICollection <Language> allUSLanguages = dao.GetLanguages("USA");
            Language lang = allUSLanguages.ToArray()[0];

            lang.Percentage = 50;

            //Act
            bool result = dao.UpdateLanguage(lang);

            //Assert
            Assert.IsTrue(result);
            Assert.AreEqual(50, lang.Percentage);//this is NOT checkign the DAO

            ICollection <Language> updatedLanguages = dao.GetLanguages("USA");

            CollectionAssert.Contains((ICollection)updatedLanguages, lang);
        }
예제 #6
0
        public void AddLanguage_FailsBecauseLanguageExists()
        {
            //ARRANGE
            ILanguageDAO           dao            = new LanguageSqlDAO(ConnectionString);
            ICollection <Language> allUSLanguages = dao.GetLanguages("USA");

            //ACT
            Language dup = allUSLanguages.ToArray()[0];

            dao.AddNewLanguage(dup);
        }
예제 #7
0
        public void GetLanguagesTest(string countryCode, int expectedCount)
        {
            // Arrange
            LanguageSqlDAO dal = new LanguageSqlDAO(ConnectionString);

            // Act
            IList <Language> languages = dal.GetLanguages(countryCode);

            // Assert
            Assert.AreEqual(expectedCount, languages.Count);
        }
예제 #8
0
        public void GetLanguagesTest(string continent, int expectedNumberOfRows)
        {
            // Arrange
            LanguageSqlDAO dao = new LanguageSqlDAO(ConnectionString);

            // Act
            IList <Language> languages = dao.GetLanguages(continent);

            // Assert
            Assert.AreEqual(expectedNumberOfRows, languages.Count);
        }
        private void GetLanguagesForCountry()
        {
            string countryCode = CLIHelper.GetString("Enter the country code you want to retrieve:");

            IList <Language> languages = languageDAO.GetLanguages(countryCode);

            Console.WriteLine();
            Console.WriteLine($"Printing {languages.Count} languages for {countryCode}");

            foreach (var language in languages)
            {
                Console.WriteLine(language);
            }
        }
예제 #10
0
        public void RemoveLanguage()
        {
            // Arrange
            ILanguageDAO           dao            = new LanguageSqlDAO(ConnectionString);
            ICollection <Language> allUSLanguages = dao.GetLanguages("USA");
            Language lang = allUSLanguages.ToArray()[0];

            // Act
            int  beforeRowCount = GetRowCount("countrylanguage");
            bool result         = dao.RemoveLanguage(lang);

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual(beforeRowCount - 1, GetRowCount("countrylanguage"));
        }
예제 #11
0
        public void AddLanguage_FailsBecauseLanguageExists()
        {
            // Arrange
            ILanguageDAO           dao            = new LanguageSqlDAO(ConnectionString);
            ICollection <Language> allUSLanguages = dao.GetLanguages("USA");
            Language dup = allUSLanguages.ToArray()[0];

            //dup.Name = "something else"; the PK is the language and the countrycode so if we change the name, then it doesn't have a pk dup

            // Act
            dao.AddNewLanguage(dup);

            // Assert
            // SqlException is expected to be thrown
        }
예제 #12
0
        public void GetLanguagesTest(string countryCode, int expectedCount)
        {
            // Arrange
            ILanguageDAO dao = new LanguageSqlDAO(ConnectionString);

            //Act
            IList <Language> list = dao.GetLanguages(countryCode);

            //Assert
            Assert.AreEqual(expectedCount, list.Count);


            /* Not using DataRow attributes
             * // Act
             * IList<Language> list = dao.GetLanguages("USA");
             * // Assert
             * Assert.AreEqual(1, list.Count);
             * list = dao.GetLanguages("XYZ");
             * // Assert
             * Assert.AreEqual(0, list.Count);
             */
        }
예제 #13
0
        public void AddLanguageHappyTest()
        {
            // Arrange
            LanguageSqlDAO   languageSqlDAO = new LanguageSqlDAO(ConnectionString);
            IList <Language> allLanguages   = languageSqlDAO.GetLanguages(newCountryCode);

            foreach (Language foo in allLanguages)
            {
                if (foo.Name.Equals("Klingon"))
                {
                    Assert.IsTrue(false);
                }
            }
            Language language = new Language
            {
                CountryCode = newCountryCode,
                Name        = "Klingon",
                IsOfficial  = true,
                Percentage  = 5
            };

            // Assert
            Assert.IsTrue(languageSqlDAO.AddNewLanguage(language));
        }