public void ShouldWorkWithASingleInputSchemaComponent()
        {
            var mapForceMapping = new MapForceMapping(new List <SchemaComponent>
            {
                new SchemaComponent("Schema1.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry1", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry1", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry2", InputOutputKey.Output(null, "2"), XsdObjectType.Element,
                              new[]
                    {
                        new Entry("Entry3", InputOutputKey.Output(null, "3"), XsdObjectType.Element),
                    }),
                })),
            },
                                                      new List <ConstantComponent>(),
                                                      new List <FunctionComponent>(),
                                                      new Graph(new Vertex[0]));
            var expectedRoot   = new SourceItem("Entry1", null, XsdObjectType.Element, null);
            var expectedChild1 = new SourceItem("Entry2", null, XsdObjectType.Element, null);
            var expectedChild2 = new SourceItem("Entry3", null, XsdObjectType.Element, null);

            expectedRoot.AddChild(expectedChild1);
            expectedChild1.AddChild(expectedChild2);

            var          xsdFileName  = TestUtils.PathToTestResource(@"XSDImporterTest\mapping\mapForceSourceElementTreeTests\Schema1.xsd");
            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();

            xmlSchemaSet.Add(XmlSchema.Read(XmlReader.Create(xsdFileName), null));

            var sourceElementTree = new MapForceSourceItemTree(mapForceMapping, xmlSchemaSet);

            AssertTreesAreEqual(expectedRoot, sourceElementTree.RootSourceItem, string.Empty);
        }
        public void ShouldThrowExceptionIfNoRootIsDefinedForMultipleInputSchemaComponents()
        {
            var mapForceMapping = new MapForceMapping(new List <SchemaComponent>
            {
                new SchemaComponent("Schema1.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry1", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry1", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry2", InputOutputKey.Output(null, "2"), XsdObjectType.Element,
                              new[]
                    {
                        new Entry("Entry3", InputOutputKey.Output(null, "3"), XsdObjectType.Element),
                    }),
                })),
                new SchemaComponent("Schema2.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry4", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry4", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry5", InputOutputKey.Output(null, "5"), XsdObjectType.Element),
                })),
            },
                                                      new List <ConstantComponent>(),
                                                      new List <FunctionComponent>(),
                                                      new Graph(new Vertex[0]));

            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();

            xmlSchemaSet.Add(XmlSchema.Read(XmlReader.Create(TestUtils.PathToTestResource(@"XSDImporterTest\mapping\mapForceSourceElementTreeTests\Schema1.xsd")), null));
            xmlSchemaSet.Add(XmlSchema.Read(XmlReader.Create(TestUtils.PathToTestResource(@"XSDImporterTest\mapping\mapForceSourceElementTreeTests\Schema2.xsd")), null));

            new MapForceSourceItemTree(mapForceMapping, xmlSchemaSet);
        }
        public void ShouldAttachConnectedSchemaComponentsToRootSchemaComponent()
        {
            var mapForceMapping = new MapForceMapping(new List <SchemaComponent>
            {
                new SchemaComponent("Schema3.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry1", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry1", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry2", InputOutputKey.Output(null, "2"), XsdObjectType.Element,
                              new[]
                    {
                        new Entry("Entry3", InputOutputKey.Output(null, "3"), XsdObjectType.Element),
                    }),
                    new Entry("Entry4", InputOutputKey.None, XsdObjectType.Element),
                })),
                new SchemaComponent("Schema2.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry4", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry4", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry5", InputOutputKey.Output(null, "5"), XsdObjectType.Element),
                })),
            },
                                                      new List <ConstantComponent>
            {
                new ConstantComponent("Root:Entry1", InputOutputKey.Output(null, "6")),
            },
                                                      new List <FunctionComponent>(),
                                                      new Graph(new Vertex[0]));
            var entry1 = new SourceItem("Entry1", null, XsdObjectType.Element, null);
            var entry2 = new SourceItem("Entry2", null, XsdObjectType.Element, null);
            var entry3 = new SourceItem("Entry3", null, XsdObjectType.Element, null);
            var entry4 = new SourceItem("Entry4", null, XsdObjectType.Element, null);
            var entry5 = new SourceItem("Entry5", null, XsdObjectType.Element, null);

            entry1.AddChild(entry2);
            entry2.AddChild(entry3);
            entry1.AddChild(entry4);
            entry4.AddChild(entry5);

            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();

            xmlSchemaSet.Add(XmlSchema.Read(XmlReader.Create(TestUtils.PathToTestResource(@"XSDImporterTest\mapping\mapForceSourceElementTreeTests\Schema3.xsd")), null));

            var sourceElementTree = new MapForceSourceItemTree(mapForceMapping, xmlSchemaSet);

            AssertTreesAreEqual(entry1, sourceElementTree.RootSourceItem, string.Empty);
        }
        public void TestImportSchemaComponents()
        {
            string mappingFile = TestUtils.PathToTestResource(@"XSDImporterTest\mapping\MapForceMappingImporterTests\MapForceMappingImporter_ImportSchemaComponents_Test.mfd");

            MapForceMapping expectedMapping = new MapForceMapping(new List <SchemaComponent>
            {
                new SchemaComponent("CoreComponent_1.xsd", "{}Address", new Namespace[0],
                                    new Entry("Address", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry((string)"CityName", InputOutputKey.Input(null, CCCityNameKey), XsdObjectType.Element),
                })
                                    ),
                new SchemaComponent("Invoice.xsd", "{http://www.ebinterface.at/schema/3p0/}Address", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Address", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry((string)"Town", InputOutputKey.Output(null, EbInterfaceTownKey), XsdObjectType.Element),
                })),
            },
                                                                  new List <ConstantComponent>(),
                                                                  new List <FunctionComponent>(),
                                                                  new Graph(new[]
            {
                new Vertex(EbInterfaceTownKey, new[]
                {
                    new Edge("72603008", CCCityNameKey, null),
                }, null),
            }));

            MapForceMapping mapping = LinqToXmlMapForceMappingImporter.ImportFromFiles(mappingFile);

            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Expected mapping: ");
            expectedMapping.PrettyPrint(Console.Out, "  ");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Imported mapping: ");
            mapping.PrettyPrint(Console.Out, "  ");
            Console.WriteLine("----------------------------------------------------");

            Assert.AreEqual(expectedMapping, mapping);
        }
        public void ShouldAttachXsdChoiceInformationToSourceElements()
        {
            var mapForceMapping = new MapForceMapping(new List <SchemaComponent>
            {
                new SchemaComponent("Schema4.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry1", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry1", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry2", InputOutputKey.Output(null, "2"), XsdObjectType.Element,
                              new[]
                    {
                        new Entry("Entry3", InputOutputKey.Output(null, "3"), XsdObjectType.Element),
                    }),
                    new Entry("Entry4", InputOutputKey.None, XsdObjectType.Element),
                })),
                new SchemaComponent("Schema2.xsd", "{http://www.ebinterface.at/schema/3p0/}Entry4", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Entry4", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry("Entry5", InputOutputKey.Output(null, "5"), XsdObjectType.Element),
                })),
            },
                                                      new List <ConstantComponent>
            {
                new ConstantComponent("Root:Entry1", InputOutputKey.Output(null, "6")),
            },
                                                      new List <FunctionComponent>(),
                                                      new Graph(new Vertex[0]));

            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();

            xmlSchemaSet.Add(XmlSchema.Read(XmlReader.Create(TestUtils.PathToTestResource(@"XSDImporterTest\mapping\mapForceSourceElementTreeTests\Schema4.xsd")), null));

            var sourceElementTree = new MapForceSourceItemTree(mapForceMapping, xmlSchemaSet);

            Assert.That(sourceElementTree.RootSourceItem.XsdTypeName, Is.EqualTo("Entry1Type"));
            Assert.That(sourceElementTree.RootSourceItem.Children[0].XsdTypeName, Is.EqualTo("Entry2Type"));
            Assert.That(sourceElementTree.RootSourceItem.Children[0].Children[0].XsdTypeName, Is.EqualTo("String"));
            Assert.That(sourceElementTree.RootSourceItem.Children[1].XsdTypeName, Is.EqualTo("Entry4Type"));
            Assert.That(sourceElementTree.RootSourceItem.Children[1].Children[0].XsdTypeName, Is.EqualTo("String"));
        }
        public void TestImportSchemaComponentsWithMappingFunctionSplit()
        {
            string mappingFile = TestUtils.PathToTestResource(@"XSDImporterTest\mapping\MapForceMappingImporterTests\mapping_simple_element_and_attributes_to_acc_with_mapping_function_split\mapping.mfd");

            const string ebInterfaceStreetKey = "72359800";
            const string ebInterfaceTownKey   = "72359696";

            const string cclBuildingNumberKey = "72345456";
            const string cclCityNameKey       = "72355472";
            const string cclStreetNameKey     = "72345296";

            const string splitFunctionNameConstantKey = "69602728";

            const string splitFunctionNameKey    = "72342768";
            const string splitFunctionInputKey   = "72455912";
            const string splitFunctionOutputKey1 = "72357424";
            const string splitFunctionOutputKey2 = "72357888";

            MapForceMapping expectedMapping = new MapForceMapping(new List <SchemaComponent>
            {
                new SchemaComponent("source.xsd", "{http://www.ebinterface.at/schema/3p0/}Address", new[] { new Namespace("http://www.ebinterface.at/schema/3p0/"), },
                                    new Entry("Address", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry((string)"Street", InputOutputKey.Output(null, ebInterfaceStreetKey), XsdObjectType.Element),
                    new Entry((string)"Town", InputOutputKey.Output(null, ebInterfaceTownKey), XsdObjectType.Element),
                })
                                    ),
                new SchemaComponent("target.xsd", "{ccts.org}Address", new[] { new Namespace("ccts.org"), },
                                    new Entry("Address", InputOutputKey.None, XsdObjectType.Element,
                                              new[]
                {
                    new Entry((string)"BuildingNumber", InputOutputKey.Input(null, cclBuildingNumberKey), XsdObjectType.Element),
                    new Entry((string)"CityName", InputOutputKey.Input(null, cclCityNameKey), XsdObjectType.Element),
                    new Entry((string)"StreetName", InputOutputKey.Input(null, cclStreetNameKey), XsdObjectType.Element),
                })),
            },
                                                                  new List <ConstantComponent>
            {
                new ConstantComponent("split1", InputOutputKey.Output(null, splitFunctionNameConstantKey))
            },
                                                                  new List <FunctionComponent>
            {
                new FunctionComponent("split", InputOutputKey.Input(null, splitFunctionNameKey), new [] { InputOutputKey.Input(null, splitFunctionInputKey) }, new [] { InputOutputKey.Output(null, splitFunctionOutputKey1), InputOutputKey.Output(null, splitFunctionOutputKey2) }),
            },
                                                                  new Graph(new[]
            {
                new Vertex(splitFunctionNameConstantKey, new[]
                {
                    new Edge("72352528", splitFunctionNameKey, null),
                }, null),
                new Vertex(splitFunctionOutputKey1, new[]
                {
                    new Edge("72363680", cclStreetNameKey, null),
                }, null),
                new Vertex(splitFunctionOutputKey2, new[]
                {
                    new Edge("72363864", cclBuildingNumberKey, null),
                }, null),
                new Vertex(ebInterfaceTownKey, new[]
                {
                    new Edge("72363312", cclCityNameKey, null),
                }, null),
                new Vertex(ebInterfaceStreetKey, new[]
                {
                    new Edge("72363496", splitFunctionInputKey, null),
                }, null),
            }));

            MapForceMapping mapping = LinqToXmlMapForceMappingImporter.ImportFromFiles(mappingFile);

            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Expected mapping: ");
            expectedMapping.PrettyPrint(Console.Out, "  ");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Imported mapping: ");
            mapping.PrettyPrint(Console.Out, "  ");
            Console.WriteLine("----------------------------------------------------");

            Assert.AreEqual(expectedMapping, mapping);
        }