public void XmlSchema() { string testSchema = AssemblyResources.GetTextFile(xsdResourcePath); XmlSchemaValidator<TestProject> validator = new XmlSchemaValidator<TestProject>(testSchema); validator.GetXmlSchema(); Assert.That(validator, Is.Not.Null); }
public void WrongElements() { string testSchema = AssemblyResources.GetTextFile(xsdResourcePath); string xml = AssemblyResources.GetTextFile(testProjectResourcePath); string replaced = xml.Replace("TestProject", "ProjectMaster"); XmlSchemaValidator<TestProject> validator = new XmlSchemaValidator<TestProject>(testSchema); Assert.That(() => { validator.Deserialize(replaced); }, Throws.TypeOf<InvalidOperationException>()); }
public void InvalidXml() { string testSchema = AssemblyResources.GetTextFile(xsdResourcePath); string xml = AssemblyResources.GetTextFile(testProjectResourcePath); Assert.That(xml, Is.StringContaining("<Hierarchy")); string invalidXml = xml.Replace("<Hierarchy", "<InvalidHierarchy"); Assert.That(invalidXml, Is.StringContaining("<InvalidHierarchy")); XmlSchemaValidator<TestProject> validator = new XmlSchemaValidator<TestProject>(testSchema); Assert.That(() => { validator.Deserialize(invalidXml); }, Throws.TypeOf<InvalidOperationException>()); }
public void ValidXml() { string testSchema = AssemblyResources.GetTextFile(xsdResourcePath); string xml = AssemblyResources.GetTextFile(testProjectResourcePath); XmlSchemaValidator<TestProject> validator = new XmlSchemaValidator<TestProject>(testSchema); TestProject record = validator.Deserialize(xml); Assert.That(record, Is.Not.Null); Assert.That(record.Hierarchy, Is.Not.Null); Assert.That(record.Hierarchy.href, Is.Not.Null); }
public void ValidateWhitespace() { if (context.NeedValidateChildren) { XmlSchemaContentType contentType = context.ElementDecl.ContentValidator.ContentType; if (context.IsNill) { SendValidationEvent(ResXml.Sch_ContentInNill, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } if (contentType == XmlSchemaContentType.Empty) { SendValidationEvent(ResXml.Sch_InvalidWhitespaceInEmpty, string.Empty); } if (checkDatatype) { SaveTextValue(reader.Value); } } }
private void ProcessElement() { SchemaElementDecl elementDecl = schemaInfo.GetElementDecl(elementName); Push(elementName); if (elementDecl != null) { context.ElementDecl = elementDecl; ValidateStartElement(); ValidateEndStartElement(); context.NeedValidateChildren = true; elementDecl.ContentValidator.InitValidation(context); } else { SendValidationEvent(Res.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); context.ElementDecl = null; } }
public void Call_Before_After_GetUnspecifiedDefaultAttributeWhenJust_Required_Optional_Fixed_FixedRequired_AttributesAreLeft(String attrType, String callOrder) { XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_ATTRIBUTES); XmlSchemaInfo info = new XmlSchemaInfo(); ArrayList def = new ArrayList(); val.Initialize(); val.ValidateElement(attrType + "AttributesElement", "", info); val.ValidateAttribute("a1", "", StringGetter("hgd"), info); if (callOrder == "after") { val.GetUnspecifiedDefaultAttributes(def); } CheckExpectedAttributes(val.GetExpectedAttributes(), new XmlQualifiedName[] { new XmlQualifiedName("a2") }); return; }
public void Typed_NullTypedValue() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("NumberElement", "", info); val.ValidateEndOfAttributes(null); try { val.ValidateEndElement(info, null); } catch (ArgumentNullException) { return; } Assert.True(false); }
static void ProcessDictionary(string name, string input, string output, Files files, string specificationVersion) { var resourcePath = "Opc.Ua.ModelCompiler.Design"; if (!String.IsNullOrEmpty(specificationVersion)) { resourcePath = $"Opc.Ua.ModelCompiler.Design.{specificationVersion}"; } TypeDictionaryValidator validator = new TypeDictionaryValidator(resourcePath); validator.Validate(input); string basePath = String.Format(@"{0}\{1}", output, name); string fileName = String.Format("Opc.Ua{0}", name); XmlSchemaGenerator generator1 = new XmlSchemaGenerator(input, output, files.TypeDictionaries, resourcePath); generator1.TypesNamespace = "http://opcfoundation.org/UA/2008/02/Types.xsd"; generator1.ServicesNamespace = "http://opcfoundation.org/UA/2008/02/Services.wsdl"; generator1.EndpointsNamespace = "http://opcfoundation.org/UA/2008/02/Endpoints.wsdl"; generator1.Generate(fileName, "Opc.Ua", name, true); string filePath = String.Format(@"{0}\Opc.Ua.Types.xsd", output); XmlSchemaValidator validator1 = new XmlSchemaValidator(files.XmlSchemas); validator1.Validate(filePath); files.XmlSchemas[validator1.TargetSchema.TargetNamespace] = filePath; System.IO.File.Delete(filePath); fileName = "Opc.Ua.Types"; BinarySchemaGenerator generator2 = new BinarySchemaGenerator(input, output, files.TypeDictionaries, resourcePath); generator2.Generate(fileName, true, "http://opcfoundation.org/UA/"); filePath = String.Format(@"{0}\{1}.bsd", output, fileName); BinarySchemaValidator validator2 = new BinarySchemaValidator(files.BinarySchemas); validator2.Validate(filePath); files.BinarySchemas[validator2.Dictionary.TargetNamespace] = filePath; System.IO.File.Delete(filePath); }
private void ValidateEndElement() { if (base.context.ElementDecl != null) { if (base.context.NeedValidateChildren && !base.context.ElementDecl.ContentValidator.CompleteValidation(base.context)) { XmlSchemaValidator.CompleteValidationError(base.context, base.EventHandler, base.reader, base.reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition, null); } if (base.checkDatatype) { string str = !base.hasSibling ? base.textString : base.textValue.ToString(); this.CheckValue(str, null); base.checkDatatype = false; base.textValue.Length = 0; base.textString = string.Empty; } } this.Pop(); }
private void ProcessElement() { SchemaElementDecl elementDecl = base.schemaInfo.GetElementDecl(base.elementName); this.Push(base.elementName); if (elementDecl != null) { base.context.ElementDecl = elementDecl; this.ValidateStartElement(); this.ValidateEndStartElement(); base.context.NeedValidateChildren = true; elementDecl.ContentValidator.InitValidation(base.context); } else { base.SendValidationEvent("Sch_UndeclaredElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace)); base.context.ElementDecl = null; } }
public void CheckSchemaInfoAfterCallingValidateEndElementWithTypedValue() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("NumberElement", "", info); val.ValidateEndOfAttributes(null); val.ValidateEndElement(info, "123"); val.EndValidation(); Assert.Equal(XmlSchemaValidity.Valid, info.Validity); Assert.Equal(XmlSchemaContentType.TextOnly, info.ContentType); Assert.False(info.IsDefault); Assert.False(info.IsNil); Assert.Equal(XmlTypeCode.Int, info.SchemaType.TypeCode); return; }
public void LineInfoProviderChangesDuringValidation() { string xmlSrc = "<root><foo>FooText</foo></root>"; XmlSchemaInfo info = new XmlSchemaInfo(); CValidationEventHolder holder = new CValidationEventHolder(); int lineNum = -1; int linePos = -1; XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml(xmlSrc)); val.ValidationEventHandler += holder.CallbackA; val.Initialize(); foreach (int i in new int[] { 1111, 1333, 0 }) { lineNum = i; linePos = i * 2; if (i == 0) { val.LineInfoProvider = null; } else { val.LineInfoProvider = new CDummyLineInfo(lineNum, linePos); } val.ValidateElement("root", "", info); val.ValidateEndOfAttributes(null); val.ValidateElement("bar", "", info); Assert.True(holder.IsCalledA); Assert.Equal(holder.lastException.LineNumber, lineNum); Assert.Equal(holder.lastException.LinePosition, linePos); val.SkipToEndElement(info); val.SkipToEndElement(info); holder.IsCalledA = false; } return; }
public void CallWithoutValidationOfRequiredAttribute() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE); ArrayList atts = new ArrayList(); val.Initialize(); val.ValidateElement("RequiredAttributeElement", "", null); try { val.ValidateEndOfAttributes(null); } catch (XmlSchemaValidationException e) { _exVerifier.IsExceptionOk(e, "Sch_MissRequiredAttribute", new string[] { "RequiredAttribute" }); return; } Assert.True(false); }
public void CallForChoiceAfterValidating_1_2_ChoiceElement(String elemAfter) { XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_PARTICLES); XmlSchemaInfo info = new XmlSchemaInfo(); string elem = elemAfter; val.Initialize(); val.ValidateElement("ChoiceElement", "", info); val.ValidateAttribute("attr1", "", StringGetter("foo"), info); val.ValidateAttribute("attr2", "", StringGetter("foo"), info); val.ValidateEndOfAttributes(null); val.ValidateElement(elem, "", info); val.SkipToEndElement(info); CheckExpectedElements(val.GetExpectedParticles(), new XmlQualifiedName[] { }); return; }
public void AddSameXmlSchemaWithTargetNamespaceTwice() { XmlSchemaValidator val = CreateValidator(new XmlSchemaSet()); XmlSchemaInfo info = new XmlSchemaInfo(); XmlSchema s; s = XmlSchema.Read(XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + " xmlns:n1=\"uri:tempuri\"\n" + " targetNamespace=\"uri:tempuri\">\n" + " <xs:element name=\"root\" />\n" + "</xs:schema>")), null); val.AddSchema(s); val.AddSchema(s); val.Initialize(); val.ValidateElement("root", "uri:tempuri", info); return; }
public void PassNonWhitespaceContent__ShouldNotWork() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT); val.Initialize(); val.ValidateElement("ElementOnlyElement", "", null); val.ValidateEndOfAttributes(null); try { val.ValidateWhitespace("this is not whitespace"); } catch (Exception) // Replace with concrete exception type { // Verify exception Assert.True(false); } return; }
private void ProcessElement(object particle) { XmlQualifiedName xsiType; string xsiNil; SchemaElementDecl elementDecl = FastGetElementDecl(particle); Push(elementName); if (bManageNamespaces) { nsManager.PushScope(); } ProcessXsiAttributes(out xsiType, out xsiNil); if (processContents != XmlSchemaContentProcessing.Skip) { if (elementDecl == null || !xsiType.IsEmpty || xsiNil != null) { elementDecl = ThoroughGetElementDecl(elementDecl, xsiType, xsiNil); } if (elementDecl == null) { if (HasSchema && processContents == XmlSchemaContentProcessing.Strict) { SendValidationEvent(Res.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } else { SendValidationEvent(Res.Sch_NoElementSchemaFound, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace), XmlSeverityType.Warning); } } } context.ElementDecl = elementDecl; ValidateStartElementIdentityConstraints(); ValidateStartElement(); if (context.ElementDecl != null) { ValidateEndStartElement(); context.NeedValidateChildren = processContents != XmlSchemaContentProcessing.Skip; context.ElementDecl.ContentValidator.InitValidation(context); } }
// SxS: This method processes resource names read from the source document and does not expose // any resources to the caller. It is fine to suppress the SxS warning. private SchemaElementDecl ThoroughGetElementDecl() { if (reader.Depth == 0) { LoadSchema(string.Empty); } if (reader.MoveToFirstAttribute()) { do { string objectNs = reader.NamespaceURI; string objectName = reader.LocalName; if (Ref.Equal(objectNs, SchemaNames.NsXmlNs)) { LoadSchema(reader.Value); if (_isProcessContents) { _nsManager.AddNamespace(reader.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value); } } if ( Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) && Ref.Equal(objectName, SchemaNames.QnDtDt.Name) ) { reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value); } } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } SchemaElementDecl elementDecl = schemaInfo.GetElementDecl(elementName); if (elementDecl == null) { if (schemaInfo.TargetNamespaces.ContainsKey(context.Namespace)) { SendValidationEvent(SR.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } } return(elementDecl); }
public void CallAfterValidatingSomeDefaultAttributes() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE); ArrayList atts = new ArrayList(); val.Initialize(); val.ValidateElement("MixedAttributesElement", "", null); val.ValidateAttribute("def1", "", StringGetter("foo"), null); val.GetUnspecifiedDefaultAttributes(atts); CheckDefaultAttributes(atts, new string[] { "def2" }); val.ValidateAttribute("def2", "", StringGetter("foo"), null); atts.Clear(); val.GetUnspecifiedDefaultAttributes(atts); CheckDefaultAttributes(atts, new string[] { }); return; }
public void WhitespaceInEmptyContent__Invalid() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("EmptyElement", "", info); val.ValidateEndOfAttributes(null); try { val.ValidateWhitespace(" " + Environment.NewLine + "\t"); } catch (XmlSchemaValidationException e) { _exVerifier.IsExceptionOk(e, "Sch_InvalidWhitespaceInEmpty"); return; } Assert.True(false); }
public void AllXmlSchemaInfoArgsCanBeNull() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT); val.Initialize(); val.ValidateElement("WithAttributesElement", "", null); val.ValidateAttribute("attr1", "", StringGetter("foo"), null); val.ValidateAttribute("attr2", "", StringGetter("foo"), null); val.ValidateEndOfAttributes(null); val.ValidateEndElement(null); val.ValidateElement("foo", "", null, "EmptyType", null, null, null); val.SkipToEndElement(null); val.ValidateElement("NumberElement", "", null); val.ValidateEndOfAttributes(null); val.ValidateEndElement(null, "123"); return; }
public void EmptyContent() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("EmptyElement", "", info); val.ValidateEndOfAttributes(null); try { val.ValidateText(StringGetter("some text")); } catch (XmlSchemaValidationException e) { _exVerifier.IsExceptionOk(e, "Sch_InvalidTextInEmpty"); return; } Assert.True(false); }
public void CallForAllAfterValidatingBothElements() { XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_PARTICLES); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("AllElement", "", info); val.ValidateAttribute("attr1", "", StringGetter("foo"), info); val.ValidateAttribute("attr2", "", StringGetter("foo"), info); val.ValidateEndOfAttributes(null); foreach (string elem in new string[] { "elem1", "elem2" }) { val.ValidateElement(elem, "", info); val.SkipToEndElement(info); } CheckExpectedElements(val.GetExpectedParticles(), new XmlQualifiedName[] { }); return; }
public void InitializeShouldNotResetInternalSchemaSet() { XmlSchemaValidator val = CreateValidator(new XmlSchemaSet()); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.AddSchema(XmlSchema.Read(XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + " <xs:element name=\"root\" type=\"xs:string\" />\n" + "</xs:schema>")), null)); val.EndValidation(); val.Initialize(); val.ValidateElement("root", "", info); Assert.True(info.SchemaElement != null); return; }
public void WhitespaceInEmptyContent__Invalid() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("EmptyElement", "", info); val.ValidateEndOfAttributes(null); try { val.ValidateWhitespace(StringGetter(" \r\n\t")); } catch (XmlSchemaValidationException) { //XmlExceptionVerifier.IsExceptionOk(e, "Sch_InvalidWhitespaceInEmpty"); return; } Assert.True(false); }
public void ValidateSameAttributeTwice() { XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE); XmlSchemaInfo info = new XmlSchemaInfo(); val.Initialize(); val.ValidateElement("RequiredAttributeElement", "", null); val.ValidateAttribute("RequiredAttribute", "", StringGetter("foo"), info); try { val.ValidateAttribute("RequiredAttribute", "", StringGetter("foo"), info); } catch (XmlSchemaValidationException e) { _exVerifier.IsExceptionOk(e, "Sch_DuplicateAttribute", new string[] { "RequiredAttribute" }); return; } Assert.True(false); }
private void ProcessElement(object particle) { XmlQualifiedName name; string str; SchemaElementDecl elementDecl = this.FastGetElementDecl(particle); this.Push(base.elementName); if (this.bManageNamespaces) { this.nsManager.PushScope(); } this.ProcessXsiAttributes(out name, out str); if (this.processContents != XmlSchemaContentProcessing.Skip) { if (((elementDecl == null) || !name.IsEmpty) || (str != null)) { elementDecl = this.ThoroughGetElementDecl(elementDecl, name, str); } if (elementDecl == null) { if (this.HasSchema && (this.processContents == XmlSchemaContentProcessing.Strict)) { base.SendValidationEvent("Sch_UndeclaredElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace)); } else { base.SendValidationEvent("Sch_NoElementSchemaFound", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace), XmlSeverityType.Warning); } } } base.context.ElementDecl = elementDecl; this.ValidateStartElementIdentityConstraints(); this.ValidateStartElement(); if (base.context.ElementDecl != null) { this.ValidateEndStartElement(); base.context.NeedValidateChildren = this.processContents != XmlSchemaContentProcessing.Skip; base.context.ElementDecl.ContentValidator.InitValidation(base.context); } }
public void SetResolverToCustomValidateSomethingSetResolverToNullThenVerify() { CXmlTestResolver res = new CXmlTestResolver(); CResolverHolder holder = new CResolverHolder(); res.CalledResolveUri += new XmlTestResolverEventHandler(holder.CallBackResolveUri); res.CalledGetEntity += new XmlTestResolverEventHandler(holder.CallBackGetEntity); XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); XmlSchemaInfo info = new XmlSchemaInfo(); XmlSchemaValidator val = new XmlSchemaValidator(new NameTable(), new XmlSchemaSet(), manager, AllFlags); val.XmlResolver = res; val.Initialize(); val.ValidateElement("foo", "", null, "type1", null, null, Path.Combine(TestData, XSDFILE_NO_TARGET_NAMESPACE)); val.SkipToEndElement(null); Assert.True(holder.IsCalledResolveUri); Assert.True(holder.IsCalledGetEntity); manager.AddNamespace("t", "uri:tempuri"); val.XmlResolver = null; try { val.ValidateElement("bar", "", null, "t:type1", null, "uri:tempuri " + Path.Combine(TestData, XSDFILE_TARGET_NAMESPACE), null); Assert.True(false); } catch (XmlSchemaValidationException e) { _exVerifier.IsExceptionOk(e, "Sch_XsiTypeNotFound", new string[] { "uri:tempuri:type1" }); return; } Assert.True(false); }
static int Main () { XmlSchema schema = XmlSchema.Read (new XmlTextReader ("schema.xsd"), null); #if NET_2_0 XmlReaderSettings settings = new XmlReaderSettings (); settings.ValidationType = ValidationType.None; XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); XmlReader reader = XmlReader.Create (new StringReader (xml), settings); XmlNamespaceManager manager = new XmlNamespaceManager (reader.NameTable); XmlSchemaValidator validator = new XmlSchemaValidator (reader.NameTable, schemaSet, manager, XmlSchemaValidationFlags.None); validator.Initialize (); validator.ValidateElement ("test", string.Empty, null); try { validator.ValidateAttribute ("mode", string.Empty, "NOT A ENUMERATION VALUE", null); return 1; } catch (XmlSchemaValidationException) { } finally { reader.Close (); } #else XmlValidatingReader validator = new XmlValidatingReader (xml, XmlNodeType.Document, null); validator.ValidationType = ValidationType.Schema; validator.Schemas.Add (schema); try { while (validator.Read ()) ; return 1; } catch (XmlSchemaException) { } finally { validator.Close (); } #endif return 0; }
public void CallAfter_Constructor_Initialize_EndValidation(String after) { XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_PARTICLES); if (after == "init") { val.Initialize(); Assert.Equal(val.GetExpectedParticles().Length, 18); } else if (after == "end") { val.Initialize(); val.EndValidation(); CheckExpectedElements(val.GetExpectedParticles(), new XmlQualifiedName[] { }); } else { CheckExpectedElements(val.GetExpectedParticles(), new XmlQualifiedName[] { }); } return; }
public IEnumerable <IController> Create() { string currentAssemblyFilePath = new Uri(typeof(XmlConfigReader).Assembly.CodeBase).LocalPath; string currentAssemblyDirectoryPath = Path.GetDirectoryName(currentAssemblyFilePath); string schemaFilePath = currentAssemblyDirectoryPath + "\\config.xsd"; string configFilePath = currentAssemblyDirectoryPath + "\\config.xml"; var validator = new XmlSchemaValidator(schemaFilePath, configFilePath); bool isValid = validator.Validate(); if (!isValid) { throw new ConfigurationErrorsException("Serial controller configuration is not valid."); } else { var xmlConfigReader = new XmlConfigReader(configFilePath); var devices = xmlConfigReader.Read(); return(devices.Select(x => new SerialController(x)).ToList()); } }
public void Call_Before_After_GetUnspecifiedDefaultAttributesWhenJustDefaultAttributesAreLeft(string callOrder) { XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_ATTRIBUTES); XmlSchemaInfo info = new XmlSchemaInfo(); ArrayList def = new ArrayList(); XmlQualifiedName[] names; val.Initialize(); val.ValidateElement("DefaultAttributesElement", "", info); val.ValidateAttribute("a1", "", StringGetter("hgd"), info); if (callOrder == "after") { val.GetUnspecifiedDefaultAttributes(def); } names = new XmlQualifiedName[] { new XmlQualifiedName("a2") }; CheckExpectedAttributes(val.GetExpectedAttributes(), names); return; }
public void InitializeShouldResetIDConstraints() { XmlSchemaValidator val = CreateValidator(XSDFILE_IDENTITY_CONSTRAINS); XmlSchemaInfo info = new XmlSchemaInfo(); for (int i = 0; i < 2; i++) { val.Initialize(); val.ValidateElement("rootIDs", "", info); val.ValidateEndOfAttributes(null); val.ValidateElement("foo", "", info); val.ValidateAttribute("attr", "", StringGetter("a1"), info); val.ValidateEndOfAttributes(null); val.ValidateEndElement(info); val.ValidateEndElement(info); val.EndValidation(); } return; }
public void AskForDefaultAttributesAndValidateThem() { XmlSchemaValidator val = CreateValidator(XSDFILE_200_DEF_ATTRIBUTES); XmlSchemaInfo info = new XmlSchemaInfo(); ArrayList atts = new ArrayList(); val.Initialize(); val.ValidateElement("StressElement", "", null); val.GetUnspecifiedDefaultAttributes(atts); foreach (XmlSchemaAttribute a in atts) { val.ValidateAttribute(a.QualifiedName.Name, a.QualifiedName.Namespace, StringGetter(a.DefaultValue), info); Assert.Equal(info.SchemaAttribute, a); } atts.Clear(); val.GetUnspecifiedDefaultAttributes(atts); Assert.Equal(0, atts.Count); return; }
public void LoadFromString() { string xml = AssemblyResources.GetTextFile(GetType().Assembly, exampleResourcePath); Assert.That(xml, Is.Not.Empty); string schema = AssemblyResources.GetSchema<Equipment>(); XmlSchemaValidator<Project> validator = new XmlSchemaValidator<Project>(schema); Project projectResource = validator.Deserialize(xml); Assert.That(projectResource.GetCount(), Is.EqualTo(5)); Project project = SerializationHelper.DeserializeFromString<Project>(xml); Assert.That(project, Is.Not.Null); Assert.That(project.Items, Is.Not.Empty); Assert.That(project.Items[0].Name, Is.EqualTo("Mining Company")); Assert.That(project.Items[0].Items, Is.Not.Empty); Assert.That(project.Items[0].Items[0].Name, Is.EqualTo("Remote Site")); Assert.That(project.Items[0].Items[0].Items, Is.Not.Empty); Assert.That(project.Items[0].Items[0].Items[0].Name, Is.EqualTo("Mining")); Assert.That(project.Items[0].Items[0].Items[1].Name, Is.EqualTo("Processing")); Assert.That(project.Items[0].Items[0].Items[1].Items, Is.Not.Empty); Assert.That(project.Items[0].Items[0].Items[1].Items[0].Name, Is.EqualTo("ROM")); }