public void StandardValidator_MatchWithOriginalData()
        {
            Match match;
            StandaloneCode code;
            Unit unit;

            Console.WriteLine("Test with valid original data reference.");
            this.DeserializeDocument();
            unit = this._document.Select("#/f=f2/u=u10") as Unit;
            match = new Match(Utilities.MakeIri("s1"));
            match.OriginalData = new OriginalData();
            match.OriginalData.DataElements.Add(new Data("xd1"));
            match.Source = new Source();
            code = new StandaloneCode("c1");
            code.DataReference = "xd1";
            match.Source.Text.Add(code);
            match.Target = new Target();
            unit.Matches.Add(match);
            StandardValidatorTests._validator.Validate(this._document);

            Console.WriteLine("Test with invalid original data reference.");
            this.DeserializeDocument();
            unit = this._document.Select("#/f=f2/u=u10") as Unit;
            match = new Match(Utilities.MakeIri("s1"));
            match.OriginalData = new OriginalData();
            match.OriginalData.DataElements.Add(new Data("xd1"));
            match.Source = new Source();
            code = new StandaloneCode("c1");
            code.DataReference = "zd1";
            match.Source.Text.Add(code);
            match.Target = new Target();
            unit.Matches.Add(match);
            this.VerifyValidationException(ValidationError.StandaloneCodeDataRefInvalid);

            Console.WriteLine("Test with original data reference not on match, but on unit.");
            this.DeserializeDocument();
            unit = this._document.Select("#/f=f2/u=u10") as Unit;
            unit.OriginalData = new OriginalData();
            unit.OriginalData.DataElements.Add(new Data("xd1"));
            match = new Match(Utilities.MakeIri("s1"));
            match.Source = new Source();
            code = new StandaloneCode("c1");
            code.DataReference = "xd1";
            match.Source.Text.Add(code);
            match.Target = new Target();
            unit.Matches.Add(match);
            this.VerifyValidationException(ValidationError.SpanningCodeInvalidDataRefEnd);
        }
        public void StandardValidator_StandaloneCode()
        {
            StandaloneCode span;
            Segment segment;
            Unit unit;

            span = new StandaloneCode();

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

            Console.WriteLine("Test with DataReference matching data.");
            span = new StandaloneCode("spanId");
            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.StandaloneCodeDataRefInvalid);

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

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

            span.DataReference = "dataId";

            Console.WriteLine("Test with SubFlows is null.");
            span = new StandaloneCode("spanId");
            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.StandaloneCodeSubflowsInvalid);

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

            Console.WriteLine("Test with SubType not like prefix:value.");
            span = new StandaloneCode("spanId");
            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);
        }
        /// <summary>
        /// Creates a <see cref="StandaloneCode"/> with every element and attribute.
        /// </summary>
        /// <param name="copyOf">The Id of the element to copy, or null.</param>
        /// <returns>The created <see cref="StandaloneCode"/>.</returns>
        private StandaloneCode CreatePh(string copyOf)
        {
            StandaloneCode result;

            result = new StandaloneCode("ph" + this.GetNextId(typeof(StandaloneCode)));
            result.CanCopy = true;
            result.CanDelete = false;
            result.CanReorder = CanReorderValue.Yes;
            result.CopyOf = copyOf;
            result.DataReference = null;
            result.DisplayText = "display";
            result.EquivalentStorage = "storage";
            result.EquivalentText = "equiv";
            result.FormatStyle = FormatStyleValue.Anchor;
            result.SizeInfo = "size";
            result.SubFlows = "u1";
            result.SubFormatStyle.Add("key1", "value1");
            result.SubFormatStyle.Add("key2", "value2");
            result.Type = CodeType.Image;

            return result;
        }