public void ConvertFromThrowsWhenRootElementNamespaceIsInvalid() { const string xml = "<san:Properties xmlns:s0='urn' xmlns:san='urn:schemas.stateless.be:biztalk:2012:12:extractors'><s0:PropertyName xpath='*'/></san:Properties>"; var expected = string.Format("Element \"Properties\" in namespace \"{0}\" was not found.", SchemaAnnotations.NAMESPACE); var sut = new XPathExtractorCollectionConverter(); Assert.That( () => sut.ConvertFrom(xml), Throws.TypeOf <ConfigurationErrorsException>() .With.InnerException.TypeOf <XmlException>() .With.InnerException.Message.EqualTo(expected)); }
public void ConvertFromThrowsWhenDuplicatePropertyToExtract() { var xml = string.Format( "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>" + "<s0:PropertyName xpath='*'/><s0:PropertyName xpath='*'/></san:Properties>", SchemaAnnotations.NAMESPACE); var sut = new XPathExtractorCollectionConverter(); Assert.That( () => sut.ConvertFrom(xml), Throws.TypeOf <ConfigurationErrorsException>() .With.InnerException.TypeOf <XmlException>() .With.InnerException.Message.EqualTo("The following properties are declared multiple times: [urn:PropertyName].")); }
public void ConvertFromThrowsWhenPropertyToExtractHasEmptyXPath() { var xml = string.Format( "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>" + "<s0:PropertyName xpath=''/></san:Properties>", SchemaAnnotations.NAMESPACE); var sut = new XPathExtractorCollectionConverter(); Assert.That( () => sut.ConvertFrom(xml), Throws.TypeOf <ConfigurationErrorsException>() .With.InnerException.TypeOf <XmlException>() .With.InnerException.Message.EqualTo( "The following properties are either not associated with the target namespace URI of some property schema " + "or have no XPath expression configured: [{urn}PropertyName].")); }
public void ConvertFrom() { var xml = string.Format( "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>" + "<s0:Property1 xpath='*/some-node'/><s0:Property2 promoted='true' xpath='*/other-node'/></san:Properties>", SchemaAnnotations.NAMESPACE); var sut = new XPathExtractorCollectionConverter(); Assert.That( sut.ConvertFrom(xml), Is.EqualTo( new XPathExtractorCollection { new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node", ExtractionMode.Write), new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote) })); }
public void ConvertTo() { var xml = string.Format( "<s0:Properties xmlns:s0=\"{0}\" xmlns:s1=\"urn\">" + "<s1:Property1 xpath=\"*/some-node\" />" + "<s1:Property2 promoted=\"true\" xpath=\"*/other-node\" />" + "</s0:Properties>", SchemaAnnotations.NAMESPACE); var sut = new XPathExtractorCollectionConverter(); var extractorCollection = sut.ConvertFrom(xml); // ReSharper disable AssignNullToNotNullAttribute Assert.That( sut.ConvertTo(extractorCollection, typeof(string)), Is.EqualTo(xml)); // ReSharper restore AssignNullToNotNullAttribute }