public void RoundtripExample4() { var u1 = new Unit("u1"); var te1 = new TextElement("Press the "); var te2 = new SmElement("m1"); var te3 = new TextElement("TAB key"); var te4 = new EmElement(); var te5 = new TextElement("."); var te6 = new TextElement("Drücken Sie die "); var te7 = new SmElement("m2"); var te8 = new TextElement("TAB-TASTE"); var te9 = new EcElement(); var te10 = new TextElement("."); var s1 = new Segment(); s1.Source.Add(te1); s1.Source.Add(te2); s1.Source.Add(te3); s1.Source.Add(te4); s1.Source.Add(te5); s1.Target.Add(te6); s1.Target.Add(te7); s1.Target.Add(te8); s1.Target.Add(te9); s1.Target.Add(te10); var unit1 = new Unit("u1"); unit1.Subunits.Add(s1); var gloss = new GlossaryEntry(); var def = new Definition(); def.Source = "publicTermbase"; def.Text = "A keyboard key that is traditionally used to insert tab characters into a document."; gloss.Definition = def; var t1 = new Translation("1", "myTermbase", "Tabstopptaste"); var t2 = new Translation("2", "myTermbase", "TAB-TASTE"); gloss.Translations.Add(t1); gloss.Translations.Add(t2); unit1.Glossary.Add(gloss); var model = new JliffDocument("en", "de"); model.Files.Add(new Localization.Jliff.Graph.File("f1")); model.Files[0].Subfiles = new List <ISubfile> { unit1 }; var dllPath = Assembly.GetAssembly(typeof(ModelTests)).Location; var dllName = Assembly.GetAssembly(typeof(ModelTests)).GetName().Name; var outputPath = dllPath.Replace(dllName + ".dll", ""); Converter.Serialize(Path.Combine(outputPath, "example4.json"), model); Converter.Deserialize(new FileInfo(Path.Combine(outputPath, "example4.json"))); JsonSchema schema = JsonSchema.Parse(schemaDef); var obGraph = JObject.FromObject(model); Assert.IsTrue(obGraph.IsValid(schema)); }
public void RoundtripExample1() { JliffDocument model = new JliffDocument("en", "fr", new Localization.Jliff.Graph.File("f1")); var u1 = new Unit("u1"); u1.OriginalData.Add("d1", "[C1/]"); u1.OriginalData.Add("d2", "[C2]"); u1.OriginalData.Add("d3", "[/C2]"); var seg = new Segment(); seg.State = Enumerations.State.translated.ToString(); seg.CanResegment = "yes"; var ph1 = new PhElement("c1"); ph1.DataRef = "d1"; var tph1 = new PhElement("c1"); tph1.DataRef = "d1"; var sc1 = new ScElement("c2"); sc1.DataRef = "d2"; var tsc1 = new ScElement("c2"); tsc1.DataRef = "d2"; var te3 = new TextElement("text"); var tte3 = new TextElement("AAA"); var ec1 = new EcElement(); ec1.DataRef = "d3"; ec1.StartRef = new Nmtoken("c2"); var tec1 = new EcElement(); tec1.DataRef = "d3"; tec1.StartRef = new Nmtoken("c2"); var te1 = new TextElement("aaa"); var tte1 = new TextElement("AAA"); var te2 = new TextElement(". "); var i1 = new Ignorable(); i1.Source.Add(te2); seg.Source.Add(ph1); seg.Source.Add(te1); seg.Source.Add(sc1); seg.Source.Add(te3); seg.Source.Add(ec1); seg.Target.Add(tph1); seg.Target.Add(tte1); seg.Target.Add(tsc1); seg.Target.Add(tte3); seg.Target.Add(tec1); u1.Subunits.Add(seg); u1.Subunits.Add(i1); model.Files[0].Subfiles.Add(u1); var g = new Group("g1"); var u2 = new Unit("u2"); var g2 = new Group("g2"); model.Files[0].Subfiles.Add(g); g.Subgroups.Add(u2); g.Subgroups.Add(g2); model.Context = new Context21(); var dllPath = Assembly.GetAssembly(typeof(ModelTests)).Location; var dllName = Assembly.GetAssembly(typeof(ModelTests)).GetName().Name; var outputPath = dllPath.Replace(dllName + ".dll", ""); Converter.Serialize(Path.Combine(outputPath, "example1.json"), model); Converter.Deserialize(new FileInfo(Path.Combine(outputPath, "example1.json"))); JsonSchema schema = JsonSchema.Parse(schemaDef); var obGraph = JObject.FromObject(model); Assert.IsTrue(obGraph.IsValid(schema)); }