Example #1
0
        public void IgnoresMissingMetadataColumns()
        {
            string document = "value,[Metadata]\n123";
            Func<TextReader> documentReaderProvider = delegate { return new StringReader(document); };
            CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false)
            {
                HasHeader = true
            };

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

            Assert.AreEqual("123", items[0].GetValue(binding));
            PropertyBag map = DataItemUtils.GetMetadata(items[0]);
            Assert.IsFalse(map.ContainsKey("Metadata"));
        }
Example #2
0
        public void CanGetDescriptiveDataBindingsFromItem()
        {
            CsvDataSet dataSet = new CsvDataSet(delegate { return new StringReader("Fruit,[Metadata]\nApples, x, 2\n"); }, false);
            dataSet.HasHeader = true;

            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(EmptyArray<DataBinding>.Instance, false));

            Assert.AreElementsEqual(new[]
            {
                new DataBinding(0, "Fruit"),
                new DataBinding(1, "[Metadata]"),
                new DataBinding(2, null)
            }, items[0].GetBindingsForInformalDescription());
        }
Example #3
0
        public void ProducesMetadata()
        {
            string document = "value,[Metadata]\n123,abc\n456,def";
            Func<TextReader> documentReaderProvider = delegate { return new StringReader(document); };
            CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false);

            dataSet.HasHeader = true;
            dataSet.DataLocationName = "<inline>";
            Assert.AreEqual("<inline>", dataSet.DataLocationName);

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

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

            Assert.AreEqual("456", items[1].GetValue(binding));
            map = new PropertyBag();
            items[1].PopulateMetadata(map);
            Assert.AreEqual("<inline>(3)", map.GetValue(MetadataKeys.DataLocation));
            Assert.AreEqual("def", map.GetValue("Metadata"));
        }
Example #4
0
 public void GetItemsReturnsNothingIfIsDynamicAndNotIncludingDynamicRows()
 {
     CsvDataSet dataSet = new CsvDataSet(delegate { return new StringReader(""); }, true);
     List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(EmptyArray<DataBinding>.Instance, false));
     Assert.Count(0, items);
 }
Example #5
0
        public void BindValues(string document, char fieldDelimiter, char commentPrefix, bool hasHeader,
            int? bindingIndex, string bindingPath, string[] expectedValues)
        {
            Func<TextReader> documentReaderProvider = delegate { return new StringReader(document); };
            CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false);

            dataSet.FieldDelimiter = fieldDelimiter;
            Assert.AreEqual(fieldDelimiter, dataSet.FieldDelimiter);

            dataSet.CommentPrefix = commentPrefix;
            Assert.AreEqual(commentPrefix, dataSet.CommentPrefix);

            dataSet.HasHeader = hasHeader;
            Assert.AreEqual(hasHeader, dataSet.HasHeader);

            DataBinding binding = new DataBinding(bindingIndex, bindingPath);
            List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(new DataBinding[] { binding }, true));

            string[] actualValues = GenericCollectionUtils.ConvertAllToArray<IDataItem, string>(items, delegate(IDataItem item)
            {
                return (string) item.GetValue(binding);
            });

            Assert.AreEqual(expectedValues, actualValues);
        }