Exemplo n.º 1
0
        public void DefaultHasHeaderIsFalse()
        {
            Gallio.Common.GallioFunc <TextReader> documentReaderProvider = delegate { return(new StringReader("")); };
            CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false);

            Assert.IsFalse(dataSet.HasHeader);
        }
Exemplo n.º 2
0
        public void DefaultCommentPrefixIsPound()
        {
            Gallio.Common.GallioFunc <TextReader> documentReaderProvider = delegate { return(new StringReader("")); };
            CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false);

            Assert.AreEqual('#', dataSet.CommentPrefix);
        }
Exemplo n.º 3
0
        public void DefaultFieldDelimiterIsComma()
        {
            Gallio.Common.GallioFunc <TextReader> documentReaderProvider = delegate { return(new StringReader("")); };
            CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false);

            Assert.AreEqual(',', dataSet.FieldDelimiter);
        }
Exemplo n.º 4
0
        public void ProducesMetadata()
        {
            string document = "value,[Metadata]\n123,abc\n456,def";

            Gallio.Common.GallioFunc <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"));
        }
Exemplo n.º 5
0
        public void BindValues(string document, char fieldDelimiter, char commentPrefix, bool hasHeader,
                               int?bindingIndex, string bindingPath, string[] expectedValues)
        {
            Gallio.Common.GallioFunc <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);
        }
Exemplo n.º 6
0
        public void IgnoresMissingMetadataColumns()
        {
            string document = "value,[Metadata]\n123";

            Gallio.Common.GallioFunc <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"));
        }
Exemplo n.º 7
0
        protected static void VerifyEqualityAndHashcodeContracts <TTarget, TWrapper>(
            TTarget target1, TTarget target2, Gallio.Common.GallioFunc <TTarget, TWrapper> wrapperFactory)
        {
            Assert.AreNotEqual(target1, target2, "Precondition for this method is that targets are different.");

            Assert.IsTrue(wrapperFactory(target1).Equals((object)wrapperFactory(target1)));
            Assert.IsFalse(wrapperFactory(target1).Equals((object)wrapperFactory(target2)));
            Assert.IsFalse(wrapperFactory(target1).Equals((object)null));

            Assert.AreEqual(wrapperFactory(target1).GetHashCode(), wrapperFactory(target1).GetHashCode());

            foreach (Type @interface in typeof(TWrapper).GetInterfaces())
            {
                if (@interface.IsGenericType && @interface.GetGenericTypeDefinition() == typeof(IEquatable <>))
                {
                    MethodInfo equals = @interface.GetMethod("Equals");

                    Assert.IsTrue((bool)equals.Invoke(wrapperFactory(target1), new object[] { wrapperFactory(target1) }));
                    Assert.IsFalse((bool)equals.Invoke(wrapperFactory(target1), new object[] { wrapperFactory(target2) }));
                    Assert.IsFalse((bool)equals.Invoke(wrapperFactory(target1), new object[] { null }));
                }
            }
        }