예제 #1
0
        public void ConvertFromNull()
        {
            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(
                sut.ConvertFrom(null),
                Is.SameAs(Enumerable.Empty <IMicroPipelineComponent>()));
        }
예제 #2
0
        public void ConvertFrom()
        {
            var xml = string.Format(
                @"<mComponents>
  <mComponent name='{0}'>
    <Property-One>1</Property-One>
    <Property-Two>2</Property-Two>
  </mComponent>
  <mComponent name='{1}' >
    <Property-Six>6</Property-Six>
    <Property-Ten>9</Property-Ten>
  </mComponent>
  <mComponent name='{2}'>
    <Encoding>utf-8</Encoding>
    <Index>10</Index>
    <Modes>Default</Modes>
    <Name>DummyTen</Name>
    <Plugin>{3}</Plugin>
    <Policy>SamplePolicy, Version=6.1</Policy>
  </mComponent>
</mComponents>",
                typeof(MicroPipelineComponentDummyOne).AssemblyQualifiedName,
                typeof(MicroPipelineComponentDummyTwo).AssemblyQualifiedName,
                typeof(MicroPipelineComponentDummyTen).AssemblyQualifiedName,
                typeof(DummyXmlTranslatorComponent).AssemblyQualifiedName);

            var sut    = new MicroPipelineComponentEnumerableConverter();
            var result = sut.ConvertFrom(xml);

            Assert.That(result, Is.Not.Null.And.InstanceOf <IEnumerable <IMicroPipelineComponent> >());

            Assert.That(
                result,
                Is.EquivalentTo(
                    new IMicroPipelineComponent[] {
                new MicroPipelineComponentDummyOne(),
                new MicroPipelineComponentDummyTwo(),
                new MicroPipelineComponentDummyTen()
            })
                .Using(new LambdaComparer <IMicroPipelineComponent>((lmc, rmc) => lmc.GetType() == rmc.GetType())));

            // ReSharper disable once PossibleNullReferenceException
            var microPipelineComponentDummyTen = (MicroPipelineComponentDummyTen)((IMicroPipelineComponent[])result)[2];

            Assert.That(microPipelineComponentDummyTen.Encoding, Is.EqualTo(new UTF8Encoding(false)));
            Assert.That(microPipelineComponentDummyTen.Modes, Is.EqualTo(XmlTranslationModes.Default));
            Assert.That(microPipelineComponentDummyTen.Plugin, Is.EqualTo(typeof(DummyXmlTranslatorComponent)));
            Assert.That(microPipelineComponentDummyTen.Policy, Is.EqualTo(new PolicyName("SamplePolicy", 6, 1)));
        }
예제 #3
0
        public void DeserializeComplexTypeWithCustomXmlSerialization()
        {
            var xml = string.Format(
                @"<mComponents>
  <mComponent name='{0}'>
    <Enabled>true</Enabled>
    <Extractors>
      <s0:Properties xmlns:s0='urn:schemas.stateless.be:biztalk:annotations:2013:01' xmlns:s1='urn'>
        <s1:Property1 xpath='*/some-node' />
        <s1:Property2 promoted='true' xpath='*/other-node' />
      </s0:Properties>
    </Extractors>
  </mComponent>
  <mComponent name='{1}'>
    <Property-One>1</Property-One>
    <Property-Two>2</Property-Two>
  </mComponent>
</mComponents>",
                typeof(DummyContextPropertyExtractorComponent).AssemblyQualifiedName,
                typeof(MicroPipelineComponentDummyOne).AssemblyQualifiedName
                );

            var sut = new MicroPipelineComponentEnumerableConverter();

            var deserialized = sut.ConvertFrom(xml) as IMicroPipelineComponent[];

            Assert.That(
                deserialized,
                Is.EquivalentTo(
                    new IMicroPipelineComponent[] {
                new DummyContextPropertyExtractorComponent(),
                new MicroPipelineComponentDummyOne()
            })
                .Using(new LambdaComparer <IMicroPipelineComponent>((lmc, rmc) => lmc.GetType() == rmc.GetType())));

            // ReSharper disable once PossibleNullReferenceException
            var extractorComponent = deserialized[0] as DummyContextPropertyExtractorComponent;

            // ReSharper disable once PossibleNullReferenceException
            Assert.That(extractorComponent.Enabled);
            Assert.That(
                extractorComponent.Extractors,
                Is.EqualTo(
                    new[] {
                new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node"),
                new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote)
            }));
        }
예제 #4
0
        public void DeserializeComplexTypeWithDefaultXmlSerialization()
        {
            var xml = string.Format(
                @"<mComponents>
  <mComponent name='{0}'>
    <Enabled>true</Enabled>
    <xt:Translations override='false' xmlns:xt='urn:schemas.stateless.be:biztalk:translations:2013:07'>
      <xt:NamespaceTranslation matchingPattern='sourceUrn1' replacementPattern='urn:test1' />
      <xt:NamespaceTranslation matchingPattern='sourceUrn5' replacementPattern='urn:test5' />
    </xt:Translations>
  </mComponent>
</mComponents>",
                typeof(DummyXmlTranslatorComponent).AssemblyQualifiedName);

            var sut = new MicroPipelineComponentEnumerableConverter();

            var deserialized = sut.ConvertFrom(xml) as IMicroPipelineComponent[];

            Assert.That(
                deserialized,
                Is.EquivalentTo(
                    new IMicroPipelineComponent[] { new DummyXmlTranslatorComponent() })
                .Using(new LambdaComparer <IMicroPipelineComponent>((lmc, rmc) => lmc.GetType() == rmc.GetType())));

            // ReSharper disable once PossibleNullReferenceException
            var extractorComponent = deserialized[0] as DummyXmlTranslatorComponent;

            // ReSharper disable once PossibleNullReferenceException
            Assert.That(extractorComponent.Enabled);
            Assert.That(
                extractorComponent.Translations,
                Is.EqualTo(
                    new XmlTranslationSet {
                Override = false,
                Items    = new[] {
                    new XmlNamespaceTranslation("sourceUrn1", "urn:test1"),
                    new XmlNamespaceTranslation("sourceUrn5", "urn:test5")
                }
            }));
        }