public void StandardValidator_MarkedSpan()
        {
            MarkedSpan span;
            Segment segment;
            Unit unit;

            span = new MarkedSpan();

            Console.WriteLine("Test with null Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            segment.Source.Text.Add(span);
            this.VerifyValidationException(ValidationError.MarkedSpanIdNull);

            Console.WriteLine("Test with empty Id.");
            span.Id = String.Empty;
            this.VerifyValidationException(ValidationError.MarkedSpanIdNull);

            Console.WriteLine("Test with duplicate Id.");
            segment.Id = "duplicateId";
            span.Id = segment.Id;
            this.VerifyValidationException(ValidationError.ElementIdDuplicate);

            Console.WriteLine("Test with item on target not matching source.");
            span.Id = "newSpanId";
            segment.Target.Text.Add(new MarkedSpan("bogus"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with type not like prefix:value.");
            span = new MarkedSpan("spanId");
            span.Value = "comment";
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            segment.Source.Text.Add(span);
            span.Type = "a";
            this.VerifyValidationException(ValidationError.MarkedSpanInvalidType);

            Console.WriteLine("Test with type using comment.");
            span.Type = MarkedSpanTypes.Comment;
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with type using generic.");
            span.Type = MarkedSpanTypes.Generic;
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with type using term.");
            span.Type = MarkedSpanTypes.Term;
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with null type.");
            span.Type = null;
            StandardValidatorTests._validator.Validate(this._document);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Demonstrates how to store <see cref="Glossary"/> data in a <see cref="Unit"/> element.
        /// </summary>
        public static void StoreGlossary()
        {
            GlossaryEntry entry;
            MarkedSpan span;
            Segment segment;
            Translation translation;
            Unit unit;

            // Create a unit to hold the glossary.
            unit = new Unit("id");
            unit.Glossary = new Glossary();
            entry = new GlossaryEntry();
            entry.Reference = "#m1";
            unit.Glossary.Entries.Add(entry);

            // Create a term that looks like: <gls:term source="publicTermbase">TAB key</gls:term>
            entry.Term.Source = "publicTermbase";
            entry.Term.Text = "TAB key";

            // Create a translation that looks like: <gls:translation id="1" source="myTermbase">Tabstopptaste</gls:translation>
            translation = new Translation("1");
            translation.Source = "myTermbase";
            translation.Text = "Tabstopptaste";
            entry.Translations.Add(translation);

            // Create a translation that looks like: <gls:translation ref="#m2" source="myTermbase">TAB-TASTE</gls:translation>
            translation = new Translation();
            translation.Reference = "#m1";
            translation.Source = "myTermbase";
            translation.Text = "TAB-TASTE";
            entry.Translations.Add(translation);

            // Create a definition that looks like:
            //  <gls:definition source="publicTermbase">A keyboard key that is traditionally used to insert tab"
            //      characters into a document.</gls:definition>
            entry.Definition = new Definition();
            entry.Definition.Source = "publicTermbase";
            entry.Definition.Text = "A keyboard key that is traditionally used to insert tab characters into a document.";

            // Create a segment to which the glossary refers.
            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(new PlainText("Press the "));
            span = new MarkedSpan("m1");
            span.Type = "term";
            span.Text.Add(new PlainText("TAB key"));
            segment.Source.Text.Add(span);

            segment.Target = new Target();
            segment.Target.Text.Add(new PlainText("Drücken Sie die "));
            span = new MarkedSpan("m1");
            span.Type = "term";
            span.Text.Add(new PlainText("TAB-TASTE"));
            segment.Target.Text.Add(span);

            unit.Resources.Add(segment);
        }
        public void StandardValidator_EditingHintsCanDelete()
        {
            MarkedSpan mrk;
            Segment segment;
            SpanningCode sourceCode;
            SpanningCodeStart startCode;
            Unit unit;

            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();

            sourceCode = new SpanningCode("pc1");
            sourceCode.CanDelete = false;
            segment.Source.Text.Add(sourceCode);

            mrk = new MarkedSpan("mrk1");
            segment.Target.Text.Add(mrk);

            this.VerifyValidationException(ValidationError.CodeBaseTagDeleted);

            // Add a start tag to the target. Since the Id doesn't match the pc, validation still fails.
            startCode = new SpanningCodeStart("sc1");
            segment.Target.Text.Add(startCode);
            this.VerifyValidationException(ValidationError.CodeBaseTagDeleted);

            // Name the sc tag the same as the pc tag. Validation fails because the sc tag is isolated.
            startCode.Id = "pc1";
            startCode.Isolated = true;
            this.VerifyValidationException(ValidationError.ContainerResourceTypesWithSameIdMismatch);

            // Add the ec and make the sc not isolated. Now validation should pass because sc and pc are equivalent.
            startCode.Isolated = false;
            segment.Target.Text.Add(new SpanningCodeEnd() { StartReference = startCode.Id });
            StandardValidatorTests._validator.Validate(this._document);
        }
        public void StandardValidator_EditingHintsCanReorder()
        {
            MarkedSpan mrk;
            Segment segment;
            SpanningCode span;
            Unit unit;

            Console.WriteLine("Test with no at start in source.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes });
            this.VerifyValidationException(ValidationError.CodeBaseSequenceStartsWithCanReorderNo);

            Console.WriteLine("Test with no at start in target.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseSequenceStartsWithCanReorderNo);

            Console.WriteLine("Test with 1 element in sequence.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes });
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with missing element in sequence.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            this.VerifyValidationException(ValidationError.CodeBaseTagDeleted);

            Console.WriteLine("Test with reordered sequence.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseSequenceNotFound);

            Console.WriteLine("Test with added element in sequence.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCodeStart("sc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseSequenceMismatch);

            Console.WriteLine("Test with missing sequence.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseTagDeleted);

            Console.WriteLine("Test with CanCopy = true.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = true, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new StandaloneCode("ph1") { CanCopy = true, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseMismatchedCanReorderCopyDelete);

            Console.WriteLine("Test with CanDelete = true.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = true, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = true, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseMismatchedCanReorderCopyDelete);

            Console.WriteLine("Test with multiple sequence where sequences are reordered.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            segment.Source.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk1");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Source.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk = new MarkedSpan("mrk2");
            segment.Source.Text.Add(mrk);
            mrk.Text.Add(new StandaloneCode("ph2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            mrk.Text.Add(new StandaloneCode("ph3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Source.Text.Add(new SpanningCodeStart("sc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No, Isolated = true });
            segment.Source.Text.Add(new SpanningCodeEnd("ec1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No, Isolated = true });
            segment.Source.Text.Add(new SpanningCodeEnd("ec2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes, Isolated = true });
            segment.Target.Text.Add(new StandaloneCode("ph2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new StandaloneCode("ph3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCodeStart("sc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No, Isolated = true });
            segment.Target.Text.Add(new SpanningCodeEnd("ec1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No, Isolated = true });
            segment.Target.Text.Add(new SpanningCodeEnd("ec2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes, Isolated = true });
            segment.Target.Text.Add(new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(new StandaloneCode("ph1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with invalid source hierarchy.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            span = new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes };
            span.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Source.Text.Add(span);
            segment.Source.Text.Add(new SpanningCode("pc3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target = null;
            this.VerifyValidationException(ValidationError.CodeBaseInvalidSourceSequenceHierarchy);

            Console.WriteLine("Test with invalid target hierarchy.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            span = new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes };
            span.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            span.Text.Add(new SpanningCode("pc3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Source.Text.Add(span);
            span = new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.Yes };
            span.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo });
            segment.Target.Text.Add(span);
            segment.Target.Text.Add(new SpanningCode("pc3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseInvalidTargetSequenceHierarchy);

            Console.WriteLine("Test with mismatched hierarchy.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();
            span = new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo };
            span.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            span.Text.Add(new SpanningCode("pc3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Source.Text.Add(span);
            span = new SpanningCode("pc1") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.FirstNo };
            span.Text.Add(new SpanningCode("pc2") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            segment.Target.Text.Add(span);
            segment.Target.Text.Add(new SpanningCode("pc3") { CanCopy = false, CanDelete = false, CanReorder = CanReorderValue.No });
            this.VerifyValidationException(ValidationError.CodeBaseSequenceHierarchyMismatch);
        }
        public void StandardValidator_EditingHintsCanCopy()
        {
            MarkedSpan mrk;
            Segment segment;
            SpanningCode sourceCode;
            SpanningCode targetCode;
            Unit unit;

            Console.WriteLine("Test with copy from source.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();

            sourceCode = new SpanningCode("pc1");
            sourceCode.CanCopy = false;
            segment.Source.Text.Add(sourceCode);

            mrk = new MarkedSpan("mrk1");
            segment.Target.Text.Add(mrk);

            targetCode = new SpanningCode("pc2");
            targetCode.CopyOf = "pc1";
            targetCode.DataReferenceEnd = null;
            targetCode.DataReferenceStart = null;
            mrk.Text.Add(targetCode);

            this.VerifyValidationException(ValidationError.CodeBaseTargetCopyOfTypeMismatchOrNotCanCopy);

            Console.WriteLine("Test with copy from target.");
            this.DeserializeDocument();
            unit = this._document.Files[0].Containers.Where(c => c is Unit).First() as Unit;
            segment = unit.Resources.Where(c => c is Segment).Cast<Segment>().First();

            sourceCode = new SpanningCode("pc1");
            sourceCode.CanCopy = false;
            segment.Target.Text.Add(sourceCode);

            mrk = new MarkedSpan("mrk1");
            segment.Target.Text.Add(mrk);

            targetCode = new SpanningCode("pc2");
            targetCode.CopyOf = "pc1";
            mrk.Text.Add(targetCode);

            this.VerifyValidationException(ValidationError.CodeBaseTargetCopyOfTypeMismatchOrNotCanCopy);
        }
        public void StandardValidator_TargetAndSoureTypesMatch()
        {
            MarkedSpan host;
            Segment segment;
            Unit unit;

            Console.WriteLine("Test with MarkedSpan types with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new MarkedSpan("testId"));
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new MarkedSpan("testId"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with MarkedSpanStart types with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new MarkedSpanStart("testId"));
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new MarkedSpan("testId"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SpanningCode types with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new SpanningCode("testId"));
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new SpanningCode("testId"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SpanningCodeStart types with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new SpanningCodeStart("testId") { Isolated = false });
            host.Text.Add(new SpanningCodeEnd() { StartReference = "testId" });
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new SpanningCode("testId"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with StandaloneCode types with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new StandaloneCode("testId"));
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new StandaloneCode("testId"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with different types (MarkedSpan, SpanningCode) with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new MarkedSpan("testId"));
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new SpanningCode("testId"));
            this.VerifyValidationException(ValidationError.ContainerResourceTypesWithSameIdMismatch);

            Console.WriteLine("Test with different types (SpanningCode, StandaloneCode) with same Id.");
            this.DeserializeDocument();
            unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit);
            segment = (Segment)unit.Resources.First(r => r is Segment);
            host = new MarkedSpan("hostSource");
            segment.Source.Text.Add(host);
            host.Text.Add(new SpanningCode("testId"));
            host = new MarkedSpan("hostTarget");
            segment.Target.Text.Add(host);
            host.Text.Add(new StandaloneCode("testId"));
            this.VerifyValidationException(ValidationError.ContainerResourceTypesWithSameIdMismatch);
        }
Ejemplo n.º 7
0
        public void XliffWriter_MarkedSpan()
        {
            MarkedSpan span1;
            MarkedSpan span2;
            Segment segment;
            Unit unit;
            string actualValue;

            unit = new Unit("u1");
            this._document.SourceLanguage = "en-us";
            this._document.Files.Add(new File("f1"));
            this._document.Files[0].Containers.Add(unit);

            segment = new Segment("s1");
            unit.Resources.Add(segment);
            segment.Source = new Source();
            span1 = new MarkedSpan("mrk1");
            segment.Source.Text.Add(span1);

            Console.WriteLine("Test with valid values.");
            actualValue = this.Serialize();
            // Translate value will be automatically written because type is generic (default).
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithValidValues), actualValue);

            Console.WriteLine("Test with term.");
            span1.Type = MarkedSpanTypes.Term;
            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithTerm), actualValue);

            Console.WriteLine("Test with custom type.");
            span1.Type = "my:type";
            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithCustomType), actualValue);

            Console.WriteLine("Test with nested spans.");
            span1.Type = MarkedSpanTypes.Comment;
            span1.Value = "this is a comment";
            span2 = new MarkedSpan("mrk2");
            span2.Translate = true;
            span1.Text.Add(span2);
            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanWithNestedMarkedSpan), actualValue);
        }
Ejemplo n.º 8
0
        public void XliffWriter_Glossary()
        {
            MarkedSpan span;
            Segment segment;
            Unit unit;

            unit = new Unit("u1");
            unit.Glossary = new Glossary();
            unit.Glossary.Entries.Add(new GlossaryEntry());
            unit.Glossary.Entries[0].Id = "entry1";
            unit.Glossary.Entries[0].Reference = Utilities.MakeIri("m1");
            unit.Glossary.Entries[0].Definition = new Definition();
            unit.Glossary.Entries[0].Definition.Source = "definitionSource";
            unit.Glossary.Entries[0].Definition.Text = "definition text";
            unit.Glossary.Entries[0].Term.Source = "termSource";
            unit.Glossary.Entries[0].Term.Text = "term text";
            unit.Glossary.Entries[0].Translations.Add(new Translation());
            unit.Glossary.Entries[0].Translations[0].Id = "trans1";
            unit.Glossary.Entries[0].Translations[0].Reference = Utilities.MakeIri("m1");
            unit.Glossary.Entries[0].Translations[0].Source = "transSource";
            unit.Glossary.Entries[0].Translations[0].Text = "translation text";

            span = new MarkedSpan("m1");
            span.Type = "term";
            span.Text.Add(new PlainText("text"));

            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(span);
            segment.State = TranslationState.Initial;

            this._document.SourceLanguage = "en-us";
            this._document.Files.Add(new File("f1"));
            this._document.Files[0].Containers.Add(unit);
            unit.Resources.Add(segment);

            Assert.AreEqual(
                            TestUtilities.GetFileContents(TestData.GlossaryWithValidValues),
                            this.Serialize(),
                            "Serialized document is incorrect.");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a <see cref="MarkedSpan"/> with every element and attribute.
        /// </summary>
        /// <param name="noteId">The Id of a note to reference.</param>
        /// <returns>The created <see cref="MarkedSpan"/>.</returns>
        private MarkedSpan CreateMrk(string noteId)
        {
            MarkedSpan result;

            result = new MarkedSpan("mrk" + this.GetNextId(typeof(MarkedSpan)));
            result.FormatStyle = FormatStyleValue.Anchor;
            result.Reference = "#n=" + noteId;
            result.SizeRestriction = "restriction";
            result.StorageRestriction = "restriction";
            result.SubFormatStyle.Add("key1", "value1");
            result.SubFormatStyle.Add("key2", "value2");
            result.Translate = true;
            result.Type = "pre:type";
            result.Value = "value";

            return result;
        }