public void XlfSampleHasValidData() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); Assert.IsTrue(file.TransUnits.Count() > 0); } }
public void TryGetTransUnit_DoesNotThrow_if_id_is_wrong() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); Assert.IsFalse(file.TryGetTransUnit(null, doc.Dialect, out XlfTransUnit u)); Assert.IsFalse(file.TryGetTransUnit(string.Empty, doc.Dialect, out XlfTransUnit u2)); Assert.IsFalse(file.TryGetTransUnit(Guid.NewGuid().ToString(), doc.Dialect, out XlfTransUnit u3)); } }
public void GetTransUnit_Throws_InvalidOperation_if_id_is_wrong() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); Assert.ThrowsException <InvalidOperationException>(() => file.GetTransUnit(null, doc.Dialect)); Assert.ThrowsException <InvalidOperationException>(() => file.GetTransUnit(string.Empty, doc.Dialect)); Assert.ThrowsException <InvalidOperationException>(() => file.GetTransUnit(Guid.NewGuid().ToString(), doc.Dialect)); } }
public void UpdateTransUnitTest() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); var initialCount = file.TransUnits.Count(); var unit = file.AddOrUpdateTransUnit(System.Guid.NewGuid().ToString(), "New source text", "new translation", XlfDialect.Standard); file.AddOrUpdateTransUnit(unit.Id, unit.Source, "evene newer translation", XlfDialect.Standard); Assert.AreEqual(initialCount + 1, file.TransUnits.Count(), "after adding the same item again, count should still be (initial+1)"); } }
public void ExporterGetsFileName() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); var exporter = new TestXlfExporter(); var fileName = Guid.NewGuid().ToString(); file.Export(fileName, exporter, null, null, XlfDialect.Standard); Assert.AreEqual(exporter.File, fileName); } }
public void ExporterGetsTransUnits() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); var exporter = new TestXlfExporter(); file.Export(null, exporter, null, null, XlfDialect.Standard); Assert.IsTrue(exporter.Units.Count > 0); Assert.AreEqual(exporter.Units.Count, file.TransUnits.Count()); } }
public void RemoveTransUnitTest() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); var initialCount = file.TransUnits.Count(); // first be sure unit is there file.GetTransUnit("c", XlfDialect.Standard); file.RemoveTransUnit("c", XlfDialect.Standard); Assert.AreEqual(initialCount - 1, file.TransUnits.Count(), "after removing an item the count should one less than before"); } }
public void ExporterGetsOnlyFilteredItems() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); var exporter = new TestXlfExporter(); file.Export(null, exporter, new List <string>() { "this-state-does-not-exist" }, null, XlfDialect.Standard); Assert.AreEqual(exporter.Units.Count, 0); file.Export(null, exporter, new List <string>() { "this-state-does-not-exist", "final" }, null, XlfDialect.Standard); Assert.IsTrue(exporter.Units.Count > 0); } }
public void UpdateStaleXlfFromResxWithCustomStateStrings() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var xlfDocument = new XlfDocument(sample.XlfFileName); var updateResult = xlfDocument.Update(sample.ResxFileName, "foo", "bar"); Assert.AreEqual(1, updateResult.AddedItems.Count(), "number of added items must be 1"); Assert.AreEqual(1, updateResult.RemovedItems.Count(), "number of removed items must be 1"); Assert.AreEqual(2, updateResult.UpdatedItems.Count(), "number of updated items must be 2"); var xlfTransUnits = xlfDocument.Files.SelectMany(f => f.TransUnits).ToDictionary(tu => tu.Id, tu => tu); Assert.AreEqual(4, xlfTransUnits.Count); AssertTranslationUnit(xlfTransUnits, "a", "Text for a", "Translation", "Comment for a", null); AssertTranslationUnit(xlfTransUnits, "b", "Text for b", "Translation", "Comment for b", "foo"); AssertTranslationUnit(xlfTransUnits, "c", "Text for c", "Translation", "Comment for c", "foo"); AssertTranslationUnit(xlfTransUnits, "d", "Text for d", "Text for d", "Comment for d", "bar"); } }
public void SaveAsResX() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); string resXFile = System.IO.Path.GetTempFileName(); string resXFile2 = System.IO.Path.GetTempFileName(); try { doc.SaveAsResX(resXFile); Assert.IsFalse(File.ReadAllText(resXFile).Contains("<comment>Comment for a</comment>"), "SaveAsResX does not write comments per default"); doc.SaveAsResX(resXFile2, XlfDocument.ResXSaveOption.IncludeComments); Assert.IsTrue(File.ReadAllText(resXFile2).Contains("<comment>Comment for a</comment>"), "SaveAsResX must include comments when specified so"); } finally { System.IO.File.Delete(resXFile); System.IO.File.Delete(resXFile2); } } }
public void AddTransUnitTest() { using (var sample = new ResxWithStaleCorrespondingXlf()) { var doc = new XlfDocument(sample.XlfFileName); var file = doc.Files.First(); var initialCount = file.TransUnits.Count(); var unit = file.AddOrUpdateTransUnit(System.Guid.NewGuid().ToString(), "New source text", "new translation", XlfDialect.Standard); Assert.AreEqual(initialCount + 1, file.TransUnits.Count(), "after adding one item, count should be (initial+1)"); try { file.AddTransUnit(unit.Id, string.Empty, string.Empty, XlfFile.AddMode.FailIfExists, XlfDialect.Standard); Assert.Fail("Adding the same unit must result in exception"); } catch (System.InvalidOperationException) { } var sameUnit = file.AddTransUnit(unit.Id, string.Empty, string.Empty, XlfFile.AddMode.SkipExisting, XlfDialect.Standard); Assert.AreEqual(unit.ToString(), sameUnit.ToString(), "unit must not be modified but returned"); } }