Exemplo n.º 1
0
        internal static void StoreDatFile(string filePath, IEnumerable <Translation> translations)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException($"The argument {nameof(filePath)} must not be null.");
            }

            if (translations == null)
            {
                throw new ArgumentNullException($"The argument {nameof(translations)} must not be null.");
            }

            List <Translation> enumerable = translations.ToList();

            if (!enumerable.Any())
            {
                throw new ArgumentException($"{nameof(translations)} must not be empty.");
            }

            UnsortedDatFileBinaryFileBuilder builder = new UnsortedDatFileBinaryFileBuilder();
            DatFile datFile = builder.Build(new DatFileAttribute()
            {
                Translations = enumerable
            });

            using (BinaryWriter writer = new BinaryWriter(File.Open(filePath, FileMode.CreateNew)))
            {
                writer.Write(datFile.GetBytes());
            }
        }
Exemplo n.º 2
0
        public void BuildUnsortedDatFile_Test()
        {
            byte[] b = File.ReadAllBytes(TEST_DATA_PATH_IN);
            UnsortedDatFileBinaryFileBuilder builder = new UnsortedDatFileBinaryFileBuilder();
            DatFile datFile = builder.Build(b);

            Assert.IsNotNull(datFile);
        }
Exemplo n.º 3
0
        public void BuildUnsortedDatFileFromTranslationList_Test()
        {
            byte[] b = File.ReadAllBytes(TEST_DATA_PATH_IN);
            CreditsTranslationListBuilder    translationListBuilder           = new CreditsTranslationListBuilder(new CultureInfo("en-GB"));
            List <Translation>               translations                     = translationListBuilder.Build(b);
            UnsortedDatFileBinaryFileBuilder unsortedDatFileBinaryFileBuilder = new UnsortedDatFileBinaryFileBuilder();
            DatFile datFile = unsortedDatFileBinaryFileBuilder.Build(new DatFileAttribute()
            {
                Translations = translations
            });

            Assert.IsNotNull(datFile);
        }
Exemplo n.º 4
0
        public void Export_TestUnsorted()
        {
            DatFileUtility.Export(TEST_DATA_UNSORTED_PATH_OUT, TRANSLATIONS, FileType.UnsortedCreditsStringFile);
            Assert.IsTrue(File.Exists(TEST_DATA_UNSORTED_PATH_OUT));
            byte[] b = File.ReadAllBytes(TEST_DATA_UNSORTED_PATH_OUT);
            UnsortedDatFileBinaryFileBuilder builder = new UnsortedDatFileBinaryFileBuilder();
            DatFile datFile = builder.Build(b);

            Assert.IsNotNull(datFile);
            Assert.IsTrue(datFile.GetTextItemCount() == TRANSLATIONS.Count);
            for (int i = 0; i < TRANSLATIONS.Count; i++)
            {
                Assert.IsTrue(datFile.GetKeys()[i].CompareTo(new KeyTableRecord(TRANSLATIONS[i].Key)) == 0);
                Assert.IsTrue(datFile.GetValues()[i].CompareTo(new ValueTableRecord(TRANSLATIONS[i].Value)) == 0);
            }
        }
Exemplo n.º 5
0
        public void StoreDatFile_Test()
        {
            List <Translation> translations = new List <Translation>
            {
                new Translation("TEST_KEY_01", "Test value 1.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_02", "Test value 2.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_03", "Test value 3.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_04", "Test value 4.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_05", "Test value 5.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_06", "Test value 6.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_07", "Test value 7.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_08", "Test value 8.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_09", "Test value 9.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_10", "Test value 10.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_11", "Test value 11.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_12", "Test value 12.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_13", "Test value 13.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_14", "Test value 14.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_15", "Test value 15.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_16", "Test value 16.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_17", "Test value 17.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_18", "Test value 18.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_19", "Test value 19.", new CultureInfo("en-GB")),
                new Translation("TEST_KEY_20", "Test value 20.", new CultureInfo("en-GB"))
            };

            UnsortedDatFileService.StoreDatFile(TEST_DATA_PATH_OUT, translations);
            Assert.IsTrue(File.Exists(TEST_DATA_PATH_OUT));
            byte[] b = File.ReadAllBytes(TEST_DATA_PATH_OUT);
            UnsortedDatFileBinaryFileBuilder builder = new UnsortedDatFileBinaryFileBuilder();
            DatFile datFile = builder.Build(b);

            Assert.IsNotNull(datFile);
            Assert.IsTrue(datFile.GetTextItemCount() == translations.Count);
            for (int i = 0; i < translations.Count; i++)
            {
                Assert.IsTrue(datFile.GetKeys()[i].CompareTo(new KeyTableRecord(translations[i].Key)) == 0);
                Assert.IsTrue(datFile.GetValues()[i].CompareTo(new ValueTableRecord(translations[i].Value)) == 0);
            }
        }