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 DefaultMerger(); 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); }
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); }