public void GetItemsReturnsNothingIfIsDynamicAndNotIncludingDynamicRows()
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml("<root><rows><row a=\"42\"/></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return document; }, "//row", true);
            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(EmptyArray<DataBinding>.Instance, false));
            Assert.Count(0, items);
        }
        public void IsDynamicPropertyIsSameAsWasSpecifiedInTheConstructor(bool isDynamic)
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml("<root><rows><row a=\"42\"/></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return document; }, "//row", isDynamic);
            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(EmptyArray<DataBinding>.Instance, true));
            Assert.Count(1, items);
            Assert.AreEqual(isDynamic, items[0].IsDynamic);
        }
        public void GetItemsReturnsXPathNavigatorsForAllSelectedValues()
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml("<root><rows><row a=\"42\" b=\"x\"/><row a=\"53\" b=\"y\"/></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return document; }, "//row", false);

            DataBinding[] bindings = new DataBinding[]
            {
                new DataBinding(null, "@a"),
                new DataBinding(null, "@b")
            };

            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(bindings, true));

            Assert.AreEqual("42", ((XPathNavigator)items[0].GetValue(bindings[0])).Value);
            Assert.AreEqual("x", ((XPathNavigator)items[0].GetValue(bindings[1])).Value);
            Assert.AreEqual("53", ((XPathNavigator)items[1].GetValue(bindings[0])).Value);
            Assert.AreEqual("y", ((XPathNavigator)items[1].GetValue(bindings[1])).Value);

            Assert.Throws<DataBindingException>(delegate { items[0].GetValue(new DataBinding(0, null)); });
            Assert.Throws<DataBindingException>(delegate { items[0].GetValue(new DataBinding(null, "not valid xpath")); });
        }
        public void ProducesMetadata()
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml("<root><rows><row a=\"42\" b=\"x\"><metadata xmlns=\"http://www.gallio.org/\"><entry key=\"Metadata\" value=\"abc\"/></metadata></row><row a=\"53\" b=\"y\"><metadata xmlns=\"http://www.gallio.org/\"><entry key=\"Metadata\" value=\"def\"/></metadata></row></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return document; }, "//row", false);
            dataSet.DataLocationName = "<inline>";
            Assert.AreEqual("<inline>", dataSet.DataLocationName);

            DataBinding binding = new DataBinding(null, "@a");
            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(new DataBinding[] { binding }, true));

            Assert.AreEqual("42", ((XPathNavigator)items[0].GetValue(binding)).Value);
            PropertyBag map = DataItemUtils.GetMetadata(items[0]);
            Assert.AreEqual("<inline>", map.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual("abc", map.GetValue("Metadata"));

            Assert.AreEqual("53", ((XPathNavigator)items[1].GetValue(binding)).Value);
            map = DataItemUtils.GetMetadata(items[1]);
            Assert.AreEqual("<inline>", map.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual("def", map.GetValue("Metadata"));
        }
        public void CanGetDescriptiveDataBindingsFromItem()
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml("<root><rows><row a=\"42\" b=\"x\"/><row a=\"53\" b=\"y\"/></rows></root>");

            XmlDataSet dataSet = new XmlDataSet(delegate { return document; }, "//row", false);
            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(EmptyArray<DataBinding>.Instance, true));

            Assert.AreElementsEqual(new[]
            {
                new DataBinding(null, ".")
            }, items[0].GetBindingsForInformalDescription());
        }