public void StandardValidator_FormatStyle_Attributes()
        {
            Core.File file;
            Segment segment;
            SpanningCodeEnd end;
            SpanningCodeStart start;
            Unit unit;

            segment = new Segment("sx");
            segment.Source = new Source();
            unit = new Unit("ux");
            unit.Resources.Add(segment);

            file = new Core.File("fx");
            file.Containers.Add(unit);

            this.DeserializeDocument();
            this._document.Files.Add(file);

            start = new SpanningCodeStart();
            start.Id = "sc1";
            segment.Source.Text.Add(start);

            end = new SpanningCodeEnd();
            end.Isolated = false;
            end.FormatStyle = FormatStyleValue.Anchor;
            end.StartReference = start.Id;
            segment.Source.Text.Add(end);

            Console.WriteLine("Test fs with ec not isolated.");
            this.VerifyValidationException(ValidationError.FormatStyleWithSpanEndNotIsolated);
            end.Isolated = true;
            end.StartReference = null;
            start.Isolated = true;

            Console.WriteLine("Test subfs without fs.");
            end.FormatStyle = null;
            end.SubFormatStyle.Add("key", "value");
            this.VerifyValidationException(ValidationError.FormatStyleSubFormatWithoutFormat);

            Console.WriteLine("Test with valid data.");
            end.FormatStyle = FormatStyleValue.Anchor;
            StandardValidatorTests._validator.Validate(this._document);
        }
        public void StandardValidator_SpanningCodeStart()
        {
            // canOverlap defaults to yes

            SpanningCodeStart span;
            Segment segment;
            Unit unit;

            span = new SpanningCodeStart();

            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.CodeBaseIdNull);

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

            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";
            span.Isolated = true;
            segment.Target.Text.Add(new MarkedSpan("bogus"));
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with DataReference matching data.");
            span = new SpanningCodeStart("spanId");
            span.Isolated = true;
            span.Type = CodeType.Formatting;
            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);
            segment.Source.Text.Add(span);
            span.DataReference = "dataId";
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with DataReference not matching data.");
            span.DataReference = "bogus";
            this.VerifyValidationException(ValidationError.SpanningCodeStartDataRefInvalid);

            Console.WriteLine("Test with DataReference is null.");
            span.DataReference = null;
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with DataReferenceEnd is empty.");
            span.DataReference = String.Empty;
            this.VerifyValidationException(ValidationError.SpanningCodeStartDataRefInvalid);

            span.DataReference = "dataId";

            Console.WriteLine("Test with SubFlows is null.");
            span = new SpanningCodeStart("spanId");
            span.Isolated = true;
            span.Type = CodeType.Formatting;
            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);
            segment.Source.Text.Add(span);
            span.DataReference = "dataId";
            span.SubFlows = null;
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SubFlows is empty.");
            span.SubFlows = String.Empty;
            this.VerifyValidationException(ValidationError.SpanningCodeStartSubflowsInvalid);

            Console.WriteLine("Test with SubFlows matching a unit.");
            span.SubFlows = "u1";
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SubFlows matching multiple units.");
            span.SubFlows = "u1 u2 u3";
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SubFlows multiple units with one not matching.");
            span.SubFlows = "u1 u200 u3";
            this.VerifyValidationException(ValidationError.SpanningCodeStartSubflowsInvalid);

            Console.WriteLine("Test with SubType not like prefix:value.");
            span = new SpanningCodeStart("spanId");
            span.Isolated = true;
            span.Type = CodeType.Formatting;
            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);
            segment.Source.Text.Add(span);
            span.DataReference = "dataId";
            span.SubType = "a";
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SubType using xlf:value.");
            span.SubType = "Xlf:value";
            this.VerifyValidationException(ValidationError.CodeBaseSubTypeInvalid);

            Console.WriteLine("Test with SubType using prefix:value:value is ok.");
            span.SubType = "prefix:value:value";
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SubType set and Type not.");
            span.SubType = "prefix:value";
            span.Type = null;
            this.VerifyValidationException(ValidationError.CodeBaseTypeNotSpecified);

            Console.WriteLine("Test with SubType is null.");
            span.SubType = null;
            span.Type = CodeType.Formatting;
            StandardValidatorTests._validator.Validate(this._document);

            foreach (string name in new string[] { "lb", "pb", "b", "i", "u" })
            {
                Console.WriteLine("Test with SubType set to {0} and Type set to fmt.", name);
                span.SubType = "xlf:" + name;
                span.Type = CodeType.Formatting;
                StandardValidatorTests._validator.Validate(this._document);

                Console.WriteLine("Test with SubType set to {0} and Type not set to fmt.", name);
                span.Type = CodeType.Image;
                this.VerifyValidationException(ValidationError.CodeBaseSubTypeMismatchFormatting);
            }

            Console.WriteLine("Test with SubType set to var and Type set to var.");
            span.SubType = "xlf:var";
            span.Type = CodeType.UserInterface;
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with SubType set to var and Type not set to var.");
            span.Type = CodeType.Image;
            this.VerifyValidationException(ValidationError.CodeBaseSubTypeMismatchUserInterface);

            Console.WriteLine("Test with Type is null.");
            span.SubType = null;
            span.SubType = null;
            StandardValidatorTests._validator.Validate(this._document);
        }
        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);
        }
        /// <summary>
        /// Creates a <see cref="SpanningCodeStart"/> with every element and attribute.
        /// </summary>
        /// <param name="copyOf">The Id of the element to copy, or null.</param>
        /// <returns>The created <see cref="SpanningCodeStart"/>.</returns>
        private SpanningCodeStart CreateSc(string copyOf)
        {
            SpanningCodeStart result;

            result = new SpanningCodeStart("sc" + this.GetNextId(typeof(SpanningCodeStart)));
            result.CanCopy = true;
            result.CanDelete = true;
            result.CanOverlap = true;
            result.CanReorder = CanReorderValue.Yes;
            result.CopyOf = copyOf;
            result.DataReference = null;
            result.Directionality = ContentDirectionality.Auto;
            result.DisplayText = "display";
            result.EquivalentStorage = "storage";
            result.EquivalentText = "equiv";
            result.FormatStyle = FormatStyleValue.Anchor;
            result.Isolated = false;
            result.SizeInfoReference = "sizeref";
            result.SizeRestriction = "restriction";
            result.StorageRestriction = "restriction";
            result.SubFlows = "u1";
            result.SubFormatStyle.Add("key1", "value1");
            result.SubFormatStyle.Add("key2", "value2");
            result.SubType = "pre:subtype";
            result.Type = CodeType.Formatting;

            return result;
        }