Beispiel #1
0
        public void SelectEnumerableValueUsingPathSeperator_Expected_ScalarValue()
        {
            IPath namePath = new XmlPath(".", ".");

            var xmlNavigator = new XmlNavigator(testData);

            var actual   = xmlNavigator.SelectEnumerable(namePath);
            var expected = new List <object> {
                @"<Company Name=""Dev2"">
  <Motto>Eat lots of cake</Motto>
  <PreviousMotto />
  <Departments TestAttrib=""testing"">
    <Department Name=""Dev"">
      <Employees>
        <Person Name=""Brendon"" Surename=""Page"" />
        <Person Name=""Jayd"" Surename=""Page"" />
      </Employees>
    </Department>
    <Department Name=""Accounts"">
      <Employees>
        <Person Name=""Bob"" Surename=""Soap"" />
        <Person Name=""Joe"" Surename=""Pants"" />
      </Employees>
    </Department>
  </Departments>
  <InlineRecordSet>
        RandomData
    </InlineRecordSet>
  <InlineRecordSet>
        RandomData1
    </InlineRecordSet>
  <OuterNestedRecordSet>
    <InnerNestedRecordSet ItemValue=""val1"" />
    <InnerNestedRecordSet ItemValue=""val2"" />
  </OuterNestedRecordSet>
  <OuterNestedRecordSet>
    <InnerNestedRecordSet ItemValue=""val3"" />
    <InnerNestedRecordSet ItemValue=""val4"" />
  </OuterNestedRecordSet>
</Company>"
            };

            Assert.AreEqual(expected.FirstOrDefault().ToString(), actual.FirstOrDefault().ToString());
        }
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainAScalarPath_Expected_FlattenedDataWithValueFromScalarPathRepeatingForEachEnumeration()
        {
            string testData = Given();

            IPath        path  = new XmlPath("Company:Name", "Company:Name");
            IPath        path1 = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet");
            List <IPath> paths = new List <IPath> {
                path, path1
            };

            XmlNavigator xmlNavigator = new XmlNavigator(testData);

            Dictionary <IPath, IList <object> > data = xmlNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "Dev2|Dev2^RandomData|RandomData1";
            string       actual   = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void XmlNavigator_SelectScalarValue_WithPathSeperator_Expected_ScalarValue()
        {
            IPath namePath = new XmlPath(".", ".");

            using (var xmlNavigator = new XmlNavigator(TestData))
            {
                var          actual   = xmlNavigator.SelectScalar(namePath).ToString();
                const string expected = @"<Company Name=""Dev2"">
  <Motto>Eat lots of cake</Motto>
  <PreviousMotto />
  <Departments TestAttrib=""testing"">
    <Department Name=""Dev"">
      <Employees>
        <Person Name=""Brendon"" Surename=""Page"" />
        <Person Name=""Jayd"" Surename=""Page"" />
      </Employees>
    </Department>
    <Department Name=""Accounts"">
      <Employees>
        <Person Name=""Bob"" Surename=""Soap"" />
        <Person Name=""Joe"" Surename=""Pants"" />
      </Employees>
    </Department>
  </Departments>
  <InlineRecordSet>
        RandomData
    </InlineRecordSet>
  <InlineRecordSet>
        RandomData1
    </InlineRecordSet>
  <OuterNestedRecordSet>
    <InnerNestedRecordSet ItemValue=""val1"" />
    <InnerNestedRecordSet ItemValue=""val2"" />
  </OuterNestedRecordSet>
  <OuterNestedRecordSet>
    <InnerNestedRecordSet ItemValue=""val3"" />
    <InnerNestedRecordSet ItemValue=""val4"" />
  </OuterNestedRecordSet>
</Company>";

                Assert.AreEqual(expected, actual);
            }
        }
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes()
        {
            string testData = Given();

            IPath        path  = new XmlPath("Company().OuterNestedRecordSet().InnerNestedRecordSet:ItemValue", "Company.OuterNestedRecordSet.InnerNestedRecordSet:ItemValue");
            IPath        path1 = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet");
            List <IPath> paths = new List <IPath> {
                path, path1
            };

            XmlNavigator xmlNavigator = new XmlNavigator(testData);

            Dictionary <IPath, IList <object> > data = xmlNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "val1|val2|val3|val4^RandomData|RandomData1||";
            string       actual   = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            string testData = Given();

            IPath        path  = new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name");
            IPath        path1 = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name");
            List <IPath> paths = new List <IPath> {
                path, path1
            };

            XmlNavigator xmlNavigator = new XmlNavigator(testData);

            Dictionary <IPath, IList <object> > data = xmlNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "Dev|Dev|Accounts|Accounts^Brendon|Jayd|Bob|Joe";
            string       actual   = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
        public void SelectEnumerableValuesAsRelatedUsingPocoEnumerablePathsFromXml_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            string testData = GivenXml();

            XmlPath      enumerableNamePath       = new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name");
            XmlPath      nestedEnumerableNamePath = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name");
            List <IPath> paths = new List <IPath> {
                enumerableNamePath, nestedEnumerableNamePath
            };

            IDataBrowser dataBrowser = DataBrowserFactory.CreateDataBrowser();
            Dictionary <IPath, IList <object> > data = dataBrowser.SelectEnumerablesAsRelated(paths, testData);

            string expected = "Dev|Dev|Accounts|Accounts^Brendon|Jayd|Bob|Joe";
            string actual   = string.Join("|", data[enumerableNamePath]);

            actual += "^" + string.Join("|", data[nestedEnumerableNamePath]);

            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        /// <summary>
        /// Load Method
        /// </summary>
        public void Load()
        {
            try
            {
                xml = XmlReader.Create(XmlPath);

                string dbPath = XmlPath.Substring(0, XmlPath.LastIndexOf('.')) + ".db";
                dbConnection = new SQLiteConnection($"Data Source={dbPath};FailIfMissing=True");
                dbConnection.Open();
                loadDatabase();

                buildMapGraph();

                XmlReader xml2 = XmlReader.Create(xml, new XmlReaderSettings());
                _xaml = (FrameworkElement)XamlReader.Load(xml2);
                addEllipseClick();

                setDefaultStyle();

                styleChanged = new Dictionary <Shape, bool>();

                _isLoad = true;
            }
            catch (FileNotFoundException e)
            {
                throw e;
            }
            catch (SQLiteException e)
            {
                throw e;
            }
            catch (InvalidCastException e)
            {
                throw e;
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #8
0
        public void GetXPathTest8()
        {
            var p    = new Paragraph(new Run(), new BookmarkEnd(), new Run());
            var body = new Body(p);

            body.PrependChild(new Paragraph());
            var r        = p.LastChild;
            var unknown1 = p.PrependChild(new OpenXmlUnknownElement("my:test", "http://my"));
            var unknown2 = p.AppendChild(new OpenXmlUnknownElement("my:test", "http://my"));

            AssertNamespace(XmlPath.GetXPath(r), @"/w:body[1]/w:p[2]/w:r[2]",
                            new NS("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"));

            using (var stream = new MemoryStream())
                using (var doc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document))
                {
                    doc.AddMainDocumentPart();
                    doc.MainDocumentPart.Document = new Document(body);
                    AssertNamespace(XmlPath.GetXPath(r), doc.MainDocumentPart.Uri, @"/w:document[1]/w:body[1]/w:p[2]/w:r[2]",
                                    new NS("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
                }
        }
Beispiel #9
0
 private static void AssertNamespace(XmlPath xmlPath, string uri, params NS[] namespaces) => AssertNamespace(xmlPath, null, uri, namespaces);
Beispiel #10
0
 public bool UpdateNode(object Item, XmlPath path)
 {
     return(UpdateWebNodeValue(path.Key, Item as Dictionary <string, string>));
 }
Beispiel #11
0
 public bool DeleteNode(XmlPath path)
 {
     return(true);
 }
Beispiel #12
0
 public AbstractController(IXmlConfigReader configReader, IXmlConfigWriter configWriter)
 {
     ConfigReader = configReader;
     ConfigWriter = configWriter;
     XmlPaths     = ConfigReader.LoadConfigs(typeof(XmlPath), XmlPath, "xmlPath", new XmlPath());
 }
 public void Assert_Exists_with_null_xml_should_throw_exception()
 {
     Assert.Xml.Exists((string)null, XmlPath.Element("Root"), XmlOptions.Default);
 }
 public void Assert_Exists_with_null_reader_should_throw_exception()
 {
     Assert.Xml.Exists((TextReader)null, XmlPath.Element("Root"), XmlOptions.Default);
 }
Beispiel #15
0
        public static void Throw(XmlPath path, string message)
        {
            var effectiveMessage = WrapMessage(path.ToString(), message);

            throw new XmlAssertionException(effectiveMessage);
        }
Beispiel #16
0
        public void GetXPathTest()
        {
            XmlPath actual;

            Paragraph p    = new Paragraph(new Run(), new BookmarkEnd(), new Run());
            Body      body = new Body(p);

            actual = XmlPath.GetXPath(p);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[1]", actual.XPath);
            Assert.Equal(1, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);

            actual = XmlPath.GetXPath(p.FirstChild);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[1]/w:r[1]", actual.XPath);
            Assert.Equal(1, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);

            body.PrependChild(new Paragraph());

            actual = XmlPath.GetXPath(p.FirstChild.NextSibling());
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[2]/w:bookmarkEnd[1]", actual.XPath);
            Assert.Equal(1, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);

            var r = p.LastChild;

            actual = XmlPath.GetXPath(r);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[2]/w:r[2]", actual.XPath);
            Assert.Equal(1, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);

            var unknown1 = p.PrependChild(new OpenXmlUnknownElement("my:test", "http://my"));

            actual = XmlPath.GetXPath(unknown1);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[2]/my:test[1]", actual.XPath);
            Assert.Equal(2, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);
            Assert.Equal(@"xmlns:my=""http://my""", actual.NamespacesDefinitions[1]);

            var unknown2 = p.AppendChild(new OpenXmlUnknownElement("my:test", "http://my"));

            actual = XmlPath.GetXPath(unknown2);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[2]/my:test[2]", actual.XPath);
            Assert.Equal(2, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);
            Assert.Equal(@"xmlns:my=""http://my""", actual.NamespacesDefinitions[1]);

            var miscNode = p.AppendChild(new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- comment -->"));

            actual = XmlPath.GetXPath(miscNode);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[2]/<!-- comment -->", actual.XPath);
            Assert.Equal(1, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);

            actual = XmlPath.GetXPath(r);
            Assert.Null(actual.PartUri);
            Assert.Equal(@"/w:body[1]/w:p[2]/w:r[2]", actual.XPath);
            Assert.Equal(1, actual.NamespacesDefinitions.Count);
            Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);

            using (var stream = new MemoryStream())
                using (var doc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document))
                {
                    doc.AddMainDocumentPart();
                    doc.MainDocumentPart.Document = new Document(body);

                    actual = XmlPath.GetXPath(r);
                    Assert.Equal(doc.MainDocumentPart.Uri, actual.PartUri);
                    Assert.Equal(new Uri("/word/document.xml", UriKind.Relative), actual.PartUri);
                    Assert.Equal(@"/w:document[1]/w:body[1]/w:p[2]/w:r[2]", actual.XPath);
                    Assert.Equal(1, actual.NamespacesDefinitions.Count);
                    Assert.Equal(@"xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""", actual.NamespacesDefinitions[0]);
                }
        }
        public void Assert_IsUnique_passes()
        {
            var xml = GetTextResource("MbUnit.Tests.Framework.SolarSystem.xml");

            Assert.Xml.IsUnique(xml, XmlPath.Element("SolarSystem").Element("Planets"), XmlOptions.Default);
        }