Ejemplo n.º 1
0
        public void FileWithOnePropertyWritesToXliffFileWithOneUnit()
        {
            var bundle = EmbeddedFilesReader.ReadString("XliffLib.Test.TestFiles.OnePropertyInRoot.json").ToBundle();

            ISourceExtractor extractor = new SourceExtractorFromBundle(bundle);
            var xliffModel             = extractor.Extract("en-US", "it-IT");

            var actual = xliffModel.Files[0].Containers.Count;

            Assert.AreEqual(1, actual);
            Assert.IsAssignableFrom <Unit>(xliffModel.Files[0].Containers[0]);
        }
Ejemplo n.º 2
0
        public void CanExtractSimpleFile(string filename)
        {
            var bundle = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".json").ToBundle();
            var xliff  = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".xlf");

            var extractor  = new SimpleExtractor();
            var xliffModel = extractor.Extract(bundle, "en-US", "it-IT");

            var xliffString = extractor.Write(xliffModel, true);

            var cleanedExpected = System.Text.RegularExpressions.Regex.Replace(xliff, @"\s+", " ");
            var cleanedResult   = System.Text.RegularExpressions.Regex.Replace(xliffString, @"\s+", " ");

            Assert.AreEqual(cleanedExpected, cleanedResult);
        }
Ejemplo n.º 3
0
        public void CanMergeSimpleFile(string filename)
        {
            var bundle = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".json");
            var xliff  = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".target.xlf");

            var merger     = new SimpleMerger();
            var xliffModel = merger.Read(xliff);

            var resultingBundle = merger.Merge(xliffModel);

            var jsonResult = resultingBundle.ToJson();

            JObject expected = JObject.Parse(bundle);
            JObject result   = JObject.Parse(jsonResult);

            Assert.IsTrue(JToken.DeepEquals(expected, result), "The two bundles are different:\r\nExpected {0}\r\nResult {1}", bundle, jsonResult);
        }
Ejemplo n.º 4
0
        public void CanExtractAndMerge(string filename)
        {
            var bundleString = EmbeddedFilesReader.ReadString("XliffLib.Integration.TestFiles." + filename + ".json");
            var bundle       = bundleString.ToBundle();

            var extractor  = new DefaultExtractor();
            var xliffModel = extractor.Extract(bundle, "en-US", "it-IT");

            var xliffString = extractor.Write(xliffModel, true);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xliffString);

            var allSources = doc.GetElementsByTagName("source");

            foreach (XmlNode source in allSources)
            {
                var newTarget = doc.CreateElement("target", "urn:oasis:names:tc:xliff:document:2.0");
                newTarget.InnerXml = source.InnerXml;
                source.ParentNode.AppendChild(newTarget);
            }

            var newXliff = doc.OuterXml;

            var merger = new DefaultMerger();

            xliffModel = merger.Read(newXliff);

            var resultingBundle = merger.Merge(xliffModel);
            var jsonResult      = resultingBundle.ToJson();

            JObject expected = JObject.Parse(bundleString);
            JObject result   = JObject.Parse(jsonResult);


            Assert.IsTrue(JToken.DeepEquals(expected, result), "The two bundles are different:\r\nExpected {0}\r\nResult {1}", bundleString, jsonResult);
        }