Exemplo n.º 1
0
        public void NLTCanAutomaticallyCreateTheTranslationsFileIfInstructed()
        {
            string fileName = RandomFileName();

            try
            {
                NLT nlt = new NLT(fileName);
                Assert.AreEqual(1, nlt.AvailableLanguages.Length);
                Assert.AreEqual(CultureInfo.CurrentCulture, nlt.CurrentCulture);

                string[] words = new string[] { "Hello", "Hi", "Table", "Window" };
                foreach (string word in words)
                {
                    nlt.Translate(word);
                }
                nlt.UpdateTranslationsFile();
                Assert.IsTrue(File.Exists(fileName), "Translation file doesn't exists");
                string[][] csv = CSV.ReadFile(fileName).ToJaggedArray();
                Assert.AreEqual(CultureInfo.CurrentCulture.Name, csv[0][0]);
                Assert.IsTrue(words
                              .OrderBy(each => each)
                              .SequenceEqual(csv
                                             .Where((each, index) => index > 0)
                                             .Select(each => each[0])
                                             .OrderBy(each => each)),
                              "Translations file doesn't contain all the attempted translations");
            }
            finally
            {
                File.Delete(fileName);
            }
        }
Exemplo n.º 2
0
        public void NLTCanUpdateTheTranslationsFileKeepingTheOldData()
        {
            string fileName = RandomFileName();

            try
            {
                File.Copy(TRANSLATIONS, fileName);
                NLT nlt = new NLT(fileName);

                string[] words = new string[] { "Hello", "Hi", "Table", "Window" };
                foreach (string word in words)
                {
                    nlt.Translate(word);
                }
                nlt.UpdateTranslationsFile();
                string[][] csv = CSV.ReadFile(fileName).ToJaggedArray();

                Assert.IsTrue(csv.All(row => row.Length == 3));
                Assert.IsTrue(csv.Any(row => "English".Equals(row[0]) && "Inglés".Equals(row[1])));
                Assert.IsTrue(words.All(word => csv.Select(row => row[0]).Contains(word)));
                Assert.AreEqual(1, csv.Select(row => row[0]).Count(word => "Hello".Equals(word)));
            }
            finally
            {
                File.Delete(fileName);
            }
        }