Ejemplo n.º 1
0
        public void SerializeComplexTypeWithCustomXmlSerialization()
        {
            var component = new DummyContextPropertyExtractorComponent {
                Enabled    = true,
                Extractors = new[] {
                    new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node"),
                    new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote)
                }
            };

            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(
                sut.ConvertTo(new IMicroPipelineComponent[] { component }, typeof(string)),
                Is.EqualTo(
                    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 mode=\"promote\" xpath=\"*/other-node\" />"
                        + "</s0:Properties>"
                        + "</Extractors>"
                        + "</mComponent>"
                        + "</mComponents>",
                        typeof(DummyContextPropertyExtractorComponent).AssemblyQualifiedName)));
        }
Ejemplo n.º 2
0
        public void SerializeComplexTypeWithDefaultXmlSerialization()
        {
            var component = new DummyXmlTranslatorComponent {
                Enabled      = true,
                Translations = new XmlTranslationSet {
                    Override = false,
                    Items    = new[] {
                        new XmlNamespaceTranslation("sourceUrn1", "urn:test1"),
                        new XmlNamespaceTranslation("sourceUrn5", "urn:test5")
                    }
                }
            };

            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(
                sut.ConvertTo(new IMicroPipelineComponent[] { component }, typeof(string)),
                Is.EqualTo(
                    string.Format(
                        "<mComponents>"
                        + "<mComponent name=\"{0}\">"
                        + "<Enabled>true</Enabled>"
                        + "<Translations override=\"false\" xmlns=\"urn:schemas.stateless.be:biztalk:translations:2013:07\">"
                        + "<NamespaceTranslation matchingPattern=\"sourceUrn1\" replacementPattern=\"urn:test1\" />"
                        + "<NamespaceTranslation matchingPattern=\"sourceUrn5\" replacementPattern=\"urn:test5\" />"
                        + "</Translations>"
                        + "</mComponent>"
                        + "</mComponents>",
                        typeof(DummyXmlTranslatorComponent).AssemblyQualifiedName)));
        }
Ejemplo n.º 3
0
        public void ConvertTo()
        {
            var list = new List <IMicroPipelineComponent> {
                new MicroPipelineComponentDummyOne(),
                new MicroPipelineComponentDummyTwo(),
                new MicroPipelineComponentDummyTen()
            };

            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(
                sut.ConvertTo(list, typeof(string)),
                Is.EqualTo(
                    string.Format(
                        "<mComponents>"
                        + "<mComponent name=\"{0}\">"
                        + "<Property-One>one</Property-One><Property-Two>two</Property-Two>"
                        + "</mComponent>"
                        + "<mComponent name=\"{1}\">"
                        + "<Property-Six>six</Property-Six><Property-Ten>ten</Property-Ten>"
                        + "</mComponent>"
                        + "<mComponent name=\"{2}\">"
                        + "<Encoding>utf-8 with signature</Encoding>"
                        + "<Index>10</Index>"
                        + "<Modes>AbsorbXmlDeclaration TranslateAttributeNamespace</Modes>"
                        + "<Name>DummyTen</Name>"
                        + "<Plugin>{3}</Plugin>"
                        + "<Policy>DummyPolicy, Version=1.1</Policy>"
                        + "</mComponent>"
                        + "</mComponents>",
                        typeof(MicroPipelineComponentDummyOne).AssemblyQualifiedName,
                        typeof(MicroPipelineComponentDummyTwo).AssemblyQualifiedName,
                        typeof(MicroPipelineComponentDummyTen).AssemblyQualifiedName,
                        typeof(DummyContextPropertyExtractorComponent).AssemblyQualifiedName)));
        }
Ejemplo n.º 4
0
        public void ConvertToNull()
        {
            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(
                sut.ConvertTo(Enumerable.Empty <IMicroPipelineComponent>(), typeof(string)),
                Is.Null);
        }
Ejemplo n.º 5
0
        public void ConvertFromNull()
        {
            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(
                sut.ConvertFrom(null),
                Is.SameAs(Enumerable.Empty <IMicroPipelineComponent>()));
        }
Ejemplo n.º 6
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)));
        }
Ejemplo n.º 7
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)
            }));
        }
Ejemplo n.º 8
0
        public void SaveConfiguration()
        {
            var microPipelineComponents = new IMicroPipelineComponent[] {
                new MicroPipelineComponentDummyOne(),
                new MicroPipelineComponentDummyTwo()
            };

            var propertyBag = new PropertyBag();

            var sut = new MicroPipelineComponent {
                Components = microPipelineComponents
            };

            sut.Save(propertyBag, true, true);

            Assert.That(propertyBag.Read("Components"), Is.EqualTo(MicroPipelineComponentEnumerableConverter.Serialize(microPipelineComponents)));
        }
Ejemplo n.º 9
0
        public void LoadConfiguration()
        {
            var microPipelineComponents = new IMicroPipelineComponent[] {
                new MicroPipelineComponentDummyOne(),
                new MicroPipelineComponentDummyTwo()
            };

            var propertyBag = new PropertyBag();

            propertyBag.Add("Enabled", true);
            propertyBag.Add("Components", MicroPipelineComponentEnumerableConverter.Serialize(microPipelineComponents));

            var sut = new MicroPipelineComponent();

            sut.Load(propertyBag, 0);

            Assert.That(sut.Components, Is.EqualTo(microPipelineComponents));
        }
Ejemplo n.º 10
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")
                }
            }));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Saves the current component configuration into the property bag
 /// </summary>
 /// <param name="propertyBag">Configuration property bag</param>
 protected override void Save(IPropertyBag propertyBag)
 {
     propertyBag.WriteProperty("Components", MicroPipelineComponentEnumerableConverter.Serialize(Components));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Loads configuration properties for the component
 /// </summary>
 /// <param name="propertyBag">Configuration property bag</param>
 protected override void Load(IPropertyBag propertyBag)
 {
     propertyBag.ReadProperty("Components", value => Components = MicroPipelineComponentEnumerableConverter.Deserialize(value));
 }
Ejemplo n.º 13
0
        public void CanConvertTo()
        {
            var sut = new MicroPipelineComponentEnumerableConverter();

            Assert.That(sut.CanConvertTo(typeof(string)));
        }