public void StandardValidator_Validation_Validation()
        {
            Rule rule;
            Validation validation;

            validation = new Validation();

            this.DeserializeDocument();
            this._document.Files[0].ValidationRules = validation;

            Console.WriteLine("Test with no rules.");
            validation.Rules.Clear();
            this.VerifyValidationException(ValidationError.ValidationMissingRules);

            Console.WriteLine("Test with valid data.");
            rule = new Rule();
            rule.IsNotPresent = "text";
            validation.Rules.Add(rule);
            StandardValidatorTests._validator.Validate(this._document);
        }
        public void StandardValidator_Validation_Rule()
        {
            Rule rule;
            Validation validation;

            rule = new Rule();
            validation = new Validation();
            validation.Rules.Add(rule);

            this.DeserializeDocument();
            this._document.Files[0].ValidationRules = validation;

            Console.WriteLine("Test with occurs < 1.");
            rule.Occurs = 0;
            this.VerifyValidationException(ValidationError.RuleInvalidOccurs);
            rule.Occurs = 1;

            Console.WriteLine("Test with no isPresent, isNotPresent, startsWtih, endsWith, or custom rule.");
            rule.ExistsInSource = false;
            rule.IsPresent = null;
            rule.IsNotPresent = null;
            rule.StartsWith = null;
            rule.EndsWith = null;
            this.VerifyValidationException(ValidationError.RuleInvalidDefinition);
            rule.IsNotPresent = "text";

            Console.WriteLine("Test with existsInSource and no isPresent, startsWtih, or endsWith.");
            rule.ExistsInSource = true;
            this.VerifyValidationException(ValidationError.RuleInvalidExistsInSource);
        }
        /// <summary>
        /// Creates a <see cref="Rule"/> with every element and attribute.
        /// </summary>
        /// <returns>The created <see cref="Rule"/>.</returns>
        private Rule CreateValidationModule_Rule()
        {
            Rule result;

            result = new Rule();
            result.IsPresent = "ispresent";
            result.ExistsInSource = true;
            result.CaseSensitive = true;
            result.Normalization = Modules.NormalizationValue.NFC;
            result.Disabled = false;
            result.Occurs = 1;

            return result;
        }
        public void XliffWriter_Validation()
        {
            Validation validation;
            Rule rule;
            string actualValue;

            validation = new Validation();

            rule = new Rule();
            rule.CaseSensitive = true;
            rule.Disabled = false;
            rule.EndsWith = "endswith";
            rule.ExistsInSource = true;
            rule.IsNotPresent = null;
            rule.IsPresent = null;
            rule.Normalization = NormalizationValue.NFC;
            rule.Occurs = 2;
            rule.StartsWith = null;
            validation.Rules.Add(rule);

            rule = new Rule();
            rule.CaseSensitive = true;
            rule.Disabled = false;
            rule.EndsWith = null;
            rule.ExistsInSource = true;
            rule.IsNotPresent = "isnotpresent";
            rule.IsPresent = null;
            rule.Normalization = NormalizationValue.NFC;
            rule.Occurs = 2;
            rule.StartsWith = null;
            validation.Rules.Add(rule);

            rule = new Rule();
            rule.CaseSensitive = true;
            rule.Disabled = false;
            rule.EndsWith = null;
            rule.ExistsInSource = true;
            rule.IsNotPresent = null;
            rule.IsPresent = "ispresent";
            rule.Normalization = NormalizationValue.NFC;
            rule.Occurs = 2;
            rule.StartsWith = null;
            validation.Rules.Add(rule);

            rule = new Rule();
            rule.CaseSensitive = true;
            rule.Disabled = false;
            rule.EndsWith = null;
            rule.ExistsInSource = true;
            rule.IsNotPresent = null;
            rule.IsPresent = null;
            rule.Normalization = NormalizationValue.NFC;
            rule.Occurs = 2;
            rule.StartsWith = "startswith";
            validation.Rules.Add(rule);

            this._document.Files.Add(new File("f1"));
            this._document.Files[0].ValidationRules = validation;

            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.FileWithValidation), actualValue);
        }
 public void TestInitialize()
 {
     this.element = new Rule();
     this.provider = this.element;
 }