public void DefaultCommentPrefixIsPound() { Gallio.Common.Func <TextReader> documentReaderProvider = delegate { return(new StringReader("")); }; CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false); Assert.AreEqual('#', dataSet.CommentPrefix); }
public void DefaultHasHeaderIsFalse() { Gallio.Common.Func <TextReader> documentReaderProvider = delegate { return(new StringReader("")); }; CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false); Assert.IsFalse(dataSet.HasHeader); }
public void DefaultFieldDelimiterIsComma() { Gallio.Common.Func <TextReader> documentReaderProvider = delegate { return(new StringReader("")); }; CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false); Assert.AreEqual(',', dataSet.FieldDelimiter); }
public void ProducesMetadata() { string document = "value,[Metadata]\n123,abc\n456,def"; Gallio.Common.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")); }
public void BindValues(string document, char fieldDelimiter, char commentPrefix, bool hasHeader, int?bindingIndex, string bindingPath, string[] expectedValues) { Gallio.Common.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); }
public void IgnoresMissingMetadataColumns() { string document = "value,[Metadata]\n123"; Gallio.Common.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")); }
protected static void VerifyEqualityAndHashcodeContracts <TTarget, TWrapper>( TTarget target1, TTarget target2, Gallio.Common.Func <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 })); } } }