public void UnionWithSchemaPrecedenceOfSchemaAndPipelineExtractorsHavingSchemaPropertyExtractorsToBeIgnored()
        {
            var schemaExtractors = new PropertyExtractorCollection(
                new PropertyExtractor(new XmlQualifiedName("prop1", "urn"), ExtractionMode.Ignore),
                new PropertyExtractor(new XmlQualifiedName("prop2", "urn"), ExtractionMode.Ignore),
                new ConstantExtractor(new XmlQualifiedName("cso-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("xso-prop", "urn"), "*/other-node", ExtractionMode.Write),
                new ConstantExtractor(new XmlQualifiedName("c-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("x-prop", "urn"), "*/other-node", ExtractionMode.Write));

            var pipelineExtractors = new PropertyExtractorCollection(
                ExtractorPrecedence.Schema,
                new PropertyExtractor(new XmlQualifiedName("prop1", "urn"), ExtractionMode.Clear),
                new PropertyExtractor(new XmlQualifiedName("prop2", "urn"), ExtractionMode.Clear),
                new ConstantExtractor(new XmlQualifiedName("cpo-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("xpo-prop", "urn"), "*/other-node", ExtractionMode.Promote),
                new ConstantExtractor(new XmlQualifiedName("c-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("x-prop", "urn"), "*/other-node", ExtractionMode.Promote));

            var expectedExtractors = schemaExtractors
                                     .Where(pe => pe.ExtractionMode != ExtractionMode.Ignore)
                                     .Concat(
                new PropertyExtractor[] {
                new ConstantExtractor(new XmlQualifiedName("cpo-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("xpo-prop", "urn"), "*/other-node", ExtractionMode.Promote)
            });

            Assert.That(schemaExtractors.Union(pipelineExtractors), Is.EqualTo(expectedExtractors));
        }
        /// <summary>
        /// Merges two sets of <see cref="PropertyExtractor"/>-derived extractors by honoring their <see
        /// cref="Precedence"/> and assuming that this <see cref="PropertyExtractorCollection"/> instance contains the
        /// <see cref="PropertyExtractor"/>s configured by XML schema annotations and that <see
        /// cref="PropertyExtractorCollection"/> being merged into contains the <see cref="PropertyExtractor"/>s
        /// configured by the pipeline.
        /// </summary>
        /// <param name="pipelineExtractors">
        /// The <see cref="PropertyExtractor"/>s configured by the pipeline.
        /// </param>
        /// <returns>
        /// The result of the merge between two sets of <see cref="PropertyExtractor"/>-derived extractors.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The merge algorithm proceeds as follows:
        /// <list type="bullet">
        /// <item>
        /// The <see cref="Precedence"/> of the <see cref="PropertyExtractor"/>s configured by XML schema annotations is
        /// irrelevant and discarded, no matter what its value may be. In other words, only the <see cref="Precedence"/>
        /// of the <see cref="PropertyExtractor"/>s configured by the pipeline is actually relevant. If unspecified, the
        /// <see cref="Precedence"/> of the <see cref="PropertyExtractor"/>s configured by the pipeline will be assumed to
        /// be given to the <see cref="ExtractorPrecedence.Schema"/>.
        /// </item>
        /// <item>
        /// If the <see cref="Precedence"/> of the pipeline <see cref="PropertyExtractor"/>s is given to the <see
        /// cref="ExtractorPrecedence.Schema"/> then any <see cref="PropertyExtractor"/> <b>redefined</b> by the pipeline
        /// will be ignored. In other words, for these particular <see cref="PropertyExtractor"/>s <b>redefined</b> by the
        /// pipeline, only their configuration done by the schema annotations will be retained. The <see
        /// cref="PropertyExtractor"/>s defined either only by the annotations or only by the pipeline will of course be
        /// part of the resulting merge.
        /// </item>
        /// <item>
        /// If the <see cref="Precedence"/> of the pipeline <see cref="PropertyExtractor"/>s is set to <see
        /// cref="ExtractorPrecedence.SchemaOnly"/> then any <see cref="PropertyExtractor"/> defined by the pipeline will
        /// be ignored provided that there are <see cref="PropertyExtractor"/>s configured by XML schema annotations. In
        /// other words, if there are <see cref="PropertyExtractor"/>s configured by annotations then the merge operation
        /// will return only these and discard any <see cref="PropertyExtractor"/>s configured by the pipeline. But if
        /// there are no <see cref="PropertyExtractor"/>s configured by annotations then the merge operation will return
        /// only the <see cref="PropertyExtractor"/>s configured by the the pipeline.
        /// </item>
        /// <item>
        /// If the <see cref="Precedence"/> of the pipeline <see cref="PropertyExtractor"/>s is given to the <see
        /// cref="ExtractorPrecedence.Pipeline"/> then any <see cref="PropertyExtractor"/> <b>redefined</b> by the
        /// pipeline will have precedence over the one defined by the annotations. In other words, for these particular
        /// <see cref="PropertyExtractor"/>s <b>redefined</b> by the pipeline, only their configuration done by the
        /// pipeline will be retained. The <see cref="PropertyExtractor"/>s defined either only by the annotations or only
        /// by the pipeline will of course be part of the resulting merge.
        /// </item>
        /// <item>
        /// If the <see cref="Precedence"/> of the pipeline <see cref="PropertyExtractor"/>s is set to <see
        /// cref="ExtractorPrecedence.PipelineOnly"/> then any <see cref="PropertyExtractor"/> defined by XML schema
        /// annotations will be ignored provided that there are <see cref="PropertyExtractor"/>s configured by the
        /// pipeline. In other words, if there are <see cref="PropertyExtractor"/>s configured by the pipeline then the
        /// merge operation will return only these and discard any <see cref="PropertyExtractor"/>s configured by
        /// annotations. But if there are no <see cref="PropertyExtractor"/>s configured by the pipeline then the merge
        /// operation will return only the <see cref="PropertyExtractor"/>s configured by annotations.
        /// </item>
        /// <item>
        /// Notice that <see cref="PropertyExtractor"/>s whose <see cref="PropertyExtractor.ExtractionMode"/> is set to
        /// <see cref="ExtractionMode.Ignore"/> will be filtered out of the resulting set of <see
        /// cref="PropertyExtractor"/>s only after the merge operation have proceeded. This could therefore lead to
        /// interesting results if the <see cref="Precedence"/> of the pipeline's <see cref="PropertyExtractor"/>s is
        /// either set to <see cref="ExtractorPrecedence.Pipeline"/> or <see cref="ExtractorPrecedence.Schema"/>.
        /// </item>
        /// </list>
        /// </para>
        /// </remarks>
        public IEnumerable <PropertyExtractor> Union(PropertyExtractorCollection pipelineExtractors)
        {
            // notice that Linq.Union enumerates first and second in that order and yields each element that has not
            // already been yielded; see https://msdn.microsoft.com/en-us/library/bb341731
            IEnumerable <PropertyExtractor> mergedExtractors;
            var schemaExtractors = Extractors;

            switch (pipelineExtractors.Precedence)
            {
            case ExtractorPrecedence.Schema:
                mergedExtractors = schemaExtractors.Union(pipelineExtractors, _lambdaComparer);
                break;

            case ExtractorPrecedence.SchemaOnly:
                mergedExtractors = schemaExtractors.Any() ? schemaExtractors : pipelineExtractors;
                break;

            case ExtractorPrecedence.Pipeline:
                mergedExtractors = pipelineExtractors.Union(schemaExtractors, _lambdaComparer);
                break;

            case ExtractorPrecedence.PipelineOnly:
                mergedExtractors = pipelineExtractors.Any() ? pipelineExtractors : schemaExtractors;
                break;

            default:
                throw new InvalidOperationException(string.Format("Unknown ExtractorPrecedence value '{0}'.", pipelineExtractors.Precedence));
            }
            // filter out extractors to be ignored
            return(mergedExtractors.Where(pe => pe.ExtractionMode != ExtractionMode.Ignore).ToArray());
        }
        public void WriteXml()
        {
            var xml = string.Format(
                "<s0:Properties xmlns:s0=\"{0}\" xmlns:s1=\"urn\">"
                + "<s1:Property1 xpath=\"*/some-node\" />"
                + "<s1:Property2 mode=\"promote\" xpath=\"*/other-node\" />"
                + "<s1:Property3 mode=\"promote\" value=\"constant\" />"
                + "<s1:Property4 mode=\"clear\" />"
                + "</s0:Properties>",
                SchemaAnnotations.NAMESPACE);

            var builder = new StringBuilder();

            using (var writer = XmlWriter.Create(builder, new XmlWriterSettings {
                OmitXmlDeclaration = true
            }))
            {
                var sut = new PropertyExtractorCollection(
                    new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node", ExtractionMode.Write),
                    new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote),
                    new ConstantExtractor(new XmlQualifiedName("Property3", "urn"), "constant", ExtractionMode.Promote),
                    new PropertyExtractor(new XmlQualifiedName("Property4", "urn"), ExtractionMode.Clear));
                sut.WriteXml(writer);
            }

            Assert.That(builder.ToString(), Is.EqualTo(xml));
        }
        public void ReadXml()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 xpath='*/some-node'/>"
                + "<s0:Property2 promoted='true' xpath='*/other-node'/>"
                + "<s0:Property3 mode='write' value='constant'/>"
                + "<s0:Property4 mode='clear'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(
                    sut,
                    Is.EqualTo(
                        new[] {
                    new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node", ExtractionMode.Write),
                    new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote),
                    new ConstantExtractor(new XmlQualifiedName("Property3", "urn"), "constant", ExtractionMode.Write),
                    new PropertyExtractor(new XmlQualifiedName("Property4", "urn"), ExtractionMode.Clear)
                }));
            }
        }
        public void ReadXmlWithoutProperties()
        {
            var xml = string.Format("<san:Properties xmlns:s0='urn' xmlns:san='{0}' />", SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(sut, Is.Empty);
            }
        }
        public void UnionWithSchemaPrecedenceOfSchemaAndEmptyPipelineExtractors()
        {
            var schemaExtractors = new PropertyExtractorCollection(
                new ConstantExtractor(new XmlQualifiedName("cso-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("xso-prop", "urn"), "*/other-node", ExtractionMode.Write),
                new ConstantExtractor(new XmlQualifiedName("c-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("x-prop", "urn"), "*/other-node", ExtractionMode.Write));

            var pipelineExtractors = new PropertyExtractorCollection(ExtractorPrecedence.Schema);

            Assert.That(schemaExtractors.Union(pipelineExtractors), Is.EqualTo(schemaExtractors));
        }
        public void UnionWithSchemaOnlyPrecedenceOfEmptySchemaAndPipelineExtractors()
        {
            var schemaExtractors = PropertyExtractorCollection.Empty;

            var pipelineExtractors = new PropertyExtractorCollection(
                ExtractorPrecedence.SchemaOnly,
                new ConstantExtractor(new XmlQualifiedName("cpo-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("xpo-prop", "urn"), "*/other-node", ExtractionMode.Promote),
                new ConstantExtractor(new XmlQualifiedName("c-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("x-prop", "urn"), "*/other-node", ExtractionMode.Promote));

            Assert.That(schemaExtractors.Union(pipelineExtractors), Is.EqualTo(pipelineExtractors));
        }
 /// <summary>
 /// Deserializes a <see cref="PropertyExtractorCollection"/> from its XML serialization <see cref="string"/>.
 /// </summary>
 /// <param name="xml">
 /// A <see cref="string"/> denoting the XML serialization of a <see cref="PropertyExtractorCollection"/>.
 /// </param>
 /// <returns>
 /// The deserialized <see cref="PropertyExtractorCollection"/>.
 /// </returns>
 /// <seealso cref="Serialize"/>
 public static PropertyExtractorCollection Deserialize(string xml)
 {
     if (xml.IsNullOrEmpty())
     {
         return(PropertyExtractorCollection.Empty);
     }
     using (var reader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings {
         IgnoreWhitespace = true, IgnoreComments = true
     }))
     {
         var collection = new PropertyExtractorCollection();
         collection.ReadXml(reader);
         return(collection);
     }
 }
        public void ReadXmlForExtractorPrecedence()
        {
            var xml = string.Format(
                "<san:Properties precedence='schemaOnly' xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 mode='clear'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(sut.Precedence, Is.EqualTo(ExtractorPrecedence.SchemaOnly));
            }
        }
        public void ReadXmlThrowsWhenRootElementNamespaceIsInvalid()
        {
            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' with namespace name '{0}' was not found. Line 1, position 2.", SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.TypeOf <ConfigurationErrorsException>()
                    .With.InnerException.TypeOf <XmlException>()
                    .With.InnerException.Message.EqualTo(expected));
            }
        }
        public void ReadXmlForPropertyExtractorThrowsWhenModeAttributeIsInvalid()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 mode='promote'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.ArgumentException.With.Message.StartsWith("Invalid ExtractionMode, only Clear and Ignore are supported for PropertyExtractor without a Value or an XPath."));
            }
        }
        public void ReadXmlForConstantExtractorThrowsWhenValueIsEmpty()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 value=''/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.ArgumentNullException.With.Message.StartsWith("Value cannot be null."));
            }
        }
        public void ReadXmlForConstantExtractorThrowsWhenModeAttributeIsInvalid()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 mode='demote' value='constant'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.ArgumentException.With.Message.StartsWith("ExtractionMode 'Demote' is not supported by ConstantExtractor."));
            }
        }
 public static string Serialize(PropertyExtractorCollection extractors)
 {
     if (!extractors.Any())
     {
         return(null);
     }
     using (var stringWriter = new StringWriter())
         using (var writer = XmlWriter.Create(stringWriter, new XmlWriterSettings {
             OmitXmlDeclaration = true
         }))
         {
             extractors.WriteXml(writer);
             writer.Flush();
             return(stringWriter.ToString());
         }
 }
        public void ReadXmlForPropertyExtractorThrowsWhenPromotedAttributeIsPresent()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 promoted='true'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.TypeOf <ConfigurationErrorsException>().With.Message.EqualTo("ExtractionMode is missing for PropertyExtractor without a Value or an XPath."));
            }
        }
        public void ReadXmlForPropertyExtractor()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 mode='clear'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(
                    sut,
                    Is.EqualTo(new[] { new PropertyExtractor(new XmlQualifiedName("Property1", "urn"), ExtractionMode.Clear) }));
            }
        }
        public void ReadXmlThrowsWhenDuplicatePropertyToExtract()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:PropertyName xpath='*'/><s0:PropertyName xpath='*'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.TypeOf <ConfigurationErrorsException>()
                    .With.InnerException.TypeOf <XmlException>()
                    .With.InnerException.Message.EqualTo("The following properties are declared multiple times: [urn:PropertyName]."));
            }
        }
        public void ReadXmlThrowsWhenPropertyToExtractHasNoNamespace()
        {
            var xml = string.Format(
                "<san:Properties xmlns:san='{0}'>"
                + "<PropertyName xpath='*'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.TypeOf <ConfigurationErrorsException>()
                    .With.InnerException.TypeOf <XmlException>()
                    .With.InnerException.Message.EqualTo("The following properties are not associated with the target namespace URI of some property schema: [PropertyName]."));
            }
        }
        public void ConvertTo()
        {
            var xml = string.Format(
                "<s0:Properties xmlns:s0=\"{0}\" xmlns:s1=\"urn\">"
                + "<s1:Property1 xpath=\"*/some-node\" />"
                + "<s1:Property2 mode=\"promote\" xpath=\"*/other-node\" />"
                + "</s0:Properties>",
                SchemaAnnotations.NAMESPACE);

            var sut = new PropertyExtractorCollectionConverter();
            var extractorCollection = new PropertyExtractorCollection(
                new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote));

            Assert.That(
                sut.ConvertTo(extractorCollection, typeof(string)),
                Is.EqualTo(xml));
        }
        public void ReadXmlForXPathExtractorThrowsWhenXPathIsEmpty()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:PropertyName xpath=''/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                Assert.That(
                    () => sut.ReadXml(reader),
                    Throws.TypeOf <ConfigurationErrorsException>()
                    .With.InnerException.TypeOf <XPathException>()
                    // ReSharper disable once StringLiteralTypo
                    .With.InnerException.Message.StartsWith("Bad Query string encoundered in XPath:"));
            }
        }
        public void ReadXmlForConstantExtractorWithModeAttribute()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property1 mode='promote' value='constant'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(
                    sut,
                    Is.EqualTo(
                        new PropertyExtractor[] {
                    new ConstantExtractor(new XmlQualifiedName("Property1", "urn"), "constant", ExtractionMode.Promote)
                }));
            }
        }
        public void ReadXmlForQNameValueExtractorFallsBackOnXPathExtractorWhenQNameValueExtractionModeIsDefault()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property3 mode='promote' qnameValue='name' xpath='*/extra-node'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(
                    sut,
                    Is.EqualTo(
                        new PropertyExtractor[] {
                    new XPathExtractor(new XmlQualifiedName("Property3", "urn"), "*/extra-node", ExtractionMode.Promote),
                }));
            }
        }
        public void ReadXmlForXPathExtractorWithPromotedAttribute()
        {
            var xml = string.Format(
                "<san:Properties xmlns:s0='urn' xmlns:san='{0}'>"
                + "<s0:Property2 promoted='true' xpath='*/other-node'/>"
                + "</san:Properties>",
                SchemaAnnotations.NAMESPACE);

            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var sut = new PropertyExtractorCollection();
                sut.ReadXml(reader);
                Assert.That(
                    sut,
                    Is.EqualTo(
                        new PropertyExtractor[] {
                    new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote)
                }));
            }
        }
        public void WriteXmlForExtractorPrecedence()
        {
            var xml = string.Format(
                "<s0:Properties precedence=\"pipelineOnly\" xmlns:s0=\"{0}\" xmlns:s1=\"urn\">"
                + "<s1:Property1 xpath=\"*/some-node\" />"
                + "</s0:Properties>",
                SchemaAnnotations.NAMESPACE);

            var builder = new StringBuilder();

            using (var writer = XmlWriter.Create(builder, new XmlWriterSettings {
                OmitXmlDeclaration = true
            }))
            {
                var sut = new PropertyExtractorCollection(
                    ExtractorPrecedence.PipelineOnly,
                    new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node", ExtractionMode.Write));
                sut.WriteXml(writer);
            }

            Assert.That(builder.ToString(), Is.EqualTo(xml));
        }
        public void UnionWithPipelinePrecedenceOfSchemaAndPipelineExtractors()
        {
            var schemaExtractors = new PropertyExtractorCollection(
                new ConstantExtractor(new XmlQualifiedName("cso-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("xso-prop", "urn"), "*/other-node", ExtractionMode.Write),
                new ConstantExtractor(new XmlQualifiedName("c-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("x-prop", "urn"), "*/other-node", ExtractionMode.Write));

            var pipelineExtractors = new PropertyExtractorCollection(
                ExtractorPrecedence.Pipeline,
                new ConstantExtractor(new XmlQualifiedName("cpo-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("xpo-prop", "urn"), "*/other-node", ExtractionMode.Promote),
                new ConstantExtractor(new XmlQualifiedName("c-prop", "urn"), "constant", ExtractionMode.Promote),
                new XPathExtractor(new XmlQualifiedName("x-prop", "urn"), "*/other-node", ExtractionMode.Promote));

            var expectedExtractors = pipelineExtractors.Concat(
                new PropertyExtractor[] {
                new ConstantExtractor(new XmlQualifiedName("cso-prop", "urn"), "constant", ExtractionMode.Write),
                new XPathExtractor(new XmlQualifiedName("xso-prop", "urn"), "*/other-node", ExtractionMode.Write)
            });

            Assert.That(schemaExtractors.Union(pipelineExtractors), Is.EqualTo(expectedExtractors));
        }
Пример #26
0
 public PropertyExtractorCollectionSerializerSurrogate(PropertyExtractorCollection extractors) : base(extractors.Precedence, extractors)
 {
 }