public void ShouldValidateXsdSchemaSuccessfully()
        {
            // Arrange
            string xmlContent = XmlTestData.GetValidXmlContent();
            string xsdContent = XmlTestData.GetXsdMarkup();

            IXsdValidator xsdValidator = XsdValidator.Instance;

            // Act
            var validationResult = xsdValidator.Validate(xmlContent, xsdContent);

            // Assert
            Assert.That(validationResult.IsValid, Is.True);
        }
Пример #2
0
        public void ShouldValidateXsdSchemaSuccessfully()
        {
            // Arrange
            string xmlContent = XmlTestData.GetValidXmlContent();
            string xsdContent = XmlTestData.GetXsdMarkup();

            IXsdValidator xsdValidator = new XsdValidator();

            // Act
            var validationResult = xsdValidator.Validate(xmlContent, xsdContent);

            // Assert
            validationResult.IsValid.Should().BeTrue();
        }
Пример #3
0
        static void Main(string[] args)
        {
            IXsdValidator xsdValidator = new XsdValidator();
            var           xsdContent   = XmlTestData.GetXsdMarkup();

            {
                Console.WriteLine("// Demo: Validate a valid XML file against an XSD schema");
                string validXmlContent  = XmlTestData.GetValidXmlContent();
                var    validationResult = xsdValidator.Validate(validXmlContent, xsdContent);
                Console.WriteLine($"validationResult.IsValid: {validationResult.IsValid}");
                Console.WriteLine($"validationResult.Errors ({validationResult.Errors.Count()}):\n{FormatValidationErrors(validationResult)}");
                Console.WriteLine();
            }

            {
                Console.WriteLine("// Demo: Validate an invalid XML file against an XSD schema");
                string invalidXmlContent = XmlTestData.GetInvalidXmlContent();
                var    validationResult  = xsdValidator.Validate(invalidXmlContent, xsdContent);
                Console.WriteLine($"validationResult.IsValid: {validationResult.IsValid}");
                Console.WriteLine($"validationResult.Errors ({validationResult.Errors.Count()}):\n{FormatValidationErrors(validationResult)}");
                Console.WriteLine();
            }

            Console.WriteLine("// Demo: Serialize/deserialize string to XML");
            const string inputString = "This is a test string";

            Console.WriteLine($"inputString:\n{inputString}");
            Console.WriteLine();

            var serialized = XmlSerializerHelper.Current.SerializeToXml(inputString);

            Console.WriteLine($"SerializeToXml:\n{serialized}");
            Console.WriteLine();

            var deserialized = XmlSerializerHelper.Current.DeserializeFromXml <string>(serialized);

            Console.WriteLine($"DeserializeFromXml:\n{deserialized}");
            Console.WriteLine();

            Console.ReadKey();
        }