public void DeserializeComplexTypeWithDefaultXmlSerialization()
        {
            var xml = $@"<mComponents>
  <mComponent name='{typeof(DummyXmlTranslator).AssemblyQualifiedName}'>
    <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>";

            var sut = new MicroComponentEnumerableConverter();

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

            deserialized.Should().BeEquivalentTo(
                new object[] {
                new DummyXmlTranslator {
                    Enabled      = true,
                    Translations = new() {
                        Override = false,
                        Items    = new[] {
                            new XmlNamespaceTranslation("sourceUrn1", "urn:test1"),
                            new XmlNamespaceTranslation("sourceUrn5", "urn:test5")
                        }
                    }
                }
            });
        public void ConvertTo()
        {
            var list = new List <IMicroComponent> {
                new DummyMicroComponentOne(),
                new DummyMicroComponentTwo(),
                new DummyMicroComponentTen()
            };

            var sut = new MicroComponentEnumerableConverter();

            sut.ConvertTo(list, typeof(string)).Should().Be(
                "<mComponents>"
                + $"<mComponent name='{typeof(DummyMicroComponentOne).AssemblyQualifiedName}'>"
                + "<Property-One>one</Property-One>"
                + "<Property-Two>two</Property-Two>"
                + "</mComponent>"
                + $"<mComponent name='{typeof(DummyMicroComponentTwo).AssemblyQualifiedName}'>"
                + "<Property-Six>six</Property-Six>"
                + "<Property-Ten>ten</Property-Ten>"
                + "</mComponent>"
                + $"<mComponent name='{typeof(DummyMicroComponentTen).AssemblyQualifiedName}'>"
                + "<Encoding>utf-8 with signature</Encoding>"
                + "<Index>10</Index>"
                + "<Name>DummyTen</Name>"
                + $"<Plugin>{typeof(DummyContextPropertyExtractor).AssemblyQualifiedName}</Plugin>"
                + "<Requirements>AbsorbXmlDeclaration TranslateAttributeNamespace</Requirements>"
                + "</mComponent>"
                + "</mComponents>");
        }
        public void SaveConfiguration()
        {
            var specimenContext = new SpecimenContext(CreateAutoFixture());
            var microComponents = new[] {
                specimenContext.Create <IMicroComponent>(),
                specimenContext.Create <IMicroComponent>(),
                specimenContext.Create <IMicroComponent>()
            };

            var sut = new MicroPipeline {
                Components = microComponents
            };
            var configuration = sut.SaveConfiguration();

            configuration.Should().Be(MicroComponentEnumerableConverter.Serialize(microComponents));
        }
        public void LoadConfiguration()
        {
            var specimenContext = new SpecimenContext(CreateAutoFixture());
            var microComponents = new[] {
                specimenContext.Create <IMicroComponent>(),
                specimenContext.Create <IMicroComponent>(),
                specimenContext.Create <IMicroComponent>()
            };
            var configuration = MicroComponentEnumerableConverter.Serialize(microComponents);

            var sut = new MicroPipeline();

            sut.LoadConfiguration(configuration);

            sut.Components.Should().BeEquivalentTo(microComponents.Cast <object>(), o => o.IncludingProperties());
        }
        public void ConvertFrom()
        {
            var xml = $@"<mComponents>
  <mComponent name='{typeof(DummyMicroComponentOne).AssemblyQualifiedName}'>
    <Property-One>1</Property-One>
    <Property-Two>2</Property-Two>
  </mComponent>
  <mComponent name='{typeof(DummyMicroComponentTwo).AssemblyQualifiedName}' >
    <Property-Six>6</Property-Six>
    <Property-Ten>9</Property-Ten>
  </mComponent>
  <mComponent name='{typeof(DummyMicroComponentTen).AssemblyQualifiedName}'>
    <Encoding>utf-8</Encoding>
    <Index>10</Index>
    <Requirements>Default</Requirements>
    <Name>DummyTen</Name>
    <Plugin>{typeof(DummyXmlTranslator).AssemblyQualifiedName}</Plugin>
  </mComponent>
</mComponents>";

            var sut = new MicroComponentEnumerableConverter();

            var result = sut.ConvertFrom(xml) as IEnumerable <IMicroComponent>;

            result.Should().NotBeNull().And.BeEquivalentTo(
                new object[] {
                new DummyMicroComponentOne {
                    One = "1", Two = "2"
                },
                new DummyMicroComponentTwo {
                    Six = "6", Ten = "9"
                },
                new DummyMicroComponentTen {
                    Encoding     = new UTF8Encoding(false),
                    Index        = 10,
                    Requirements = XmlTranslationRequirements.Default,
                    Name         = "DummyTen",
                    Plugin       = typeof(DummyXmlTranslator)
                }
            });
        }
        public void DeserializeComplexTypeWithCustomXmlSerialization()
        {
            var xml = $@"<mComponents>
  <mComponent name='{typeof(DummyContextPropertyExtractor).AssemblyQualifiedName}'>
    <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='{typeof(DummyMicroComponentOne).AssemblyQualifiedName}'>
    <Property-One>1</Property-One>
    <Property-Two>2</Property-Two>
  </mComponent>
</mComponents>";

            var sut = new MicroComponentEnumerableConverter();

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

            deserialized.Should().BeEquivalentTo(
                new object[] {
                new DummyContextPropertyExtractor {
                    Enabled    = true,
                    Extractors = new[] {
                        new XPathExtractor(new XmlQualifiedName("Property1", "urn"), "*/some-node"),
                        new XPathExtractor(new XmlQualifiedName("Property2", "urn"), "*/other-node", ExtractionMode.Promote)
                    }
                },
                new DummyMicroComponentOne {
                    One = "1", Two = "2"
                }
            });
        }
Example #7
0
 public string SaveConfiguration()
 {
     return(MicroComponentEnumerableConverter.Serialize(Components));
 }
Example #8
0
 public void LoadConfiguration(string configuration)
 {
     Components = MicroComponentEnumerableConverter.Deserialize(configuration);
 }
        public void ConvertFromEmpty()
        {
            var sut = new MicroComponentEnumerableConverter();

            sut.ConvertFrom(string.Empty).Should().BeSameAs(Enumerable.Empty <IMicroComponent>());
        }
        public void CanConvertTo()
        {
            var sut = new MicroComponentEnumerableConverter();

            sut.CanConvertTo(typeof(string)).Should().BeTrue();
        }
        public void ConvertToNull()
        {
            var sut = new MicroComponentEnumerableConverter();

            sut.ConvertTo(Enumerable.Empty <IMicroComponent>(), typeof(string)).Should().BeNull();
        }