public void StandardValidator_MarkedStart() { MarkedSpanStart span; Segment segment; Unit unit; span = new MarkedSpanStart(); 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.MarkedSpanStartIdNull); Console.WriteLine("Test with empty Id."); span.Id = String.Empty; this.VerifyValidationException(ValidationError.MarkedSpanStartIdNull); 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 MarkedSpanStart("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.MarkedSpanStartInvalidType); 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); }
public void XliffWriter_MarkedSpanStart() { MarkedSpanStart span; 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(); span = new MarkedSpanStart("mrk1"); segment.Source.Text.Add(span); actualValue = this.Serialize(); // Translate value will be automatically written because type is generic (default). Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanStartWithValidValues), actualValue); span.Type = MarkedSpanTypes.Term; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanStartWithTerm), actualValue); span.Type = "my:type"; actualValue = this.Serialize(); Assert.AreEqual(TestUtilities.GetFileContents(TestData.MarkedSpanStartWithCustomType), actualValue); }
public void StandardValidator_MarkedSpanEnd() { MarkedSpanEnd span; MarkedSpanStart startSpan; Segment segment; Unit unit; span = new MarkedSpanEnd(); Console.WriteLine("Test with StartReference matching sm."); span = new MarkedSpanEnd("spanId"); this.DeserializeDocument(); unit = (Unit)this._document.Files[0].Containers.First(c => c is Unit); unit.OriginalData = new OriginalData(); unit.OriginalData.AddData("dataId", "text"); segment = (Segment)unit.Resources.First(r => r is Segment); startSpan = new MarkedSpanStart("smId"); startSpan.Type = "term"; segment.Source.Text.Add(startSpan); segment.Source.Text.Add(span); span.StartReference = "smId"; StandardValidatorTests._validator.Validate(this._document); Console.WriteLine("Test with StartReference not matching sm."); span.StartReference = "bogus"; this.VerifyValidationException(ValidationError.TagStartRefInvalid); Console.WriteLine("Test with StartReference is null."); span.StartReference = null; this.VerifyValidationException(ValidationError.MarkedSpanEndStartRefNull); Console.WriteLine("Test with StartReference is empty."); span.StartReference = String.Empty; this.VerifyValidationException(ValidationError.MarkedSpanEndStartRefNull); }
/// <summary> /// Creates a <see cref="MaredSpanStart"/> with every element and attribute. /// </summary> /// <param name="noteId">The Id of a note to reference.</param> /// <returns>The created <see cref="MaredSpanStart"/>.</returns> private MarkedSpanStart CreateSm(string noteId) { MarkedSpanStart result; result = new MarkedSpanStart("sm" + this.GetNextId(typeof(MarkedSpanStart))); 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; }