private static void ITabularValue_Basics(string value, String8 value8, ITabularValue itv) { Assert.AreEqual(String.IsNullOrEmpty(value), itv.IsNullOrEmpty()); Assert.AreEqual(value8, itv.ToString8()); Assert.AreEqual(value, itv.ToString()); bool asBoolean; if (bool.TryParse(value, out asBoolean)) { Assert.AreEqual(asBoolean, itv.ToBoolean()); } else { Verify.Exception <FormatException>(() => { var result = itv.ToBoolean(); }); } int asInteger; if (int.TryParse(value, out asInteger)) { Assert.AreEqual(asInteger, itv.ToInteger()); } else { Verify.Exception <FormatException>(() => { var result = itv.ToInteger(); }); } DateTime asDateTime; if (DateTime.TryParse(value, CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out asDateTime)) { Assert.AreEqual(asDateTime, itv.ToDateTime()); } else { Verify.Exception <FormatException>(() => { var result = itv.ToDateTime(); }); } }
private static TableMetadata Build(IStreamProvider streamProvider, string tableRootPath) { TableMetadata metadata = new TableMetadata(); string schemaFilePath = Path.Combine(tableRootPath, SchemaFileName); using (ITabularReader sr = TabularFactory.BuildReader(streamProvider.OpenRead(schemaFilePath), SchemaFileName)) { int nameIndex = sr.ColumnIndex("Name"); int typeIndex = sr.ColumnIndex("Type"); while (sr.NextRow()) { metadata.Schema.Add(new ColumnDetails(sr.Current(nameIndex).ToString(), TypeProviderFactory.Get(sr.Current(typeIndex).ToString()).Type)); } } using (ITabularReader mr = TabularFactory.BuildReader(streamProvider.OpenRead(Path.Combine(tableRootPath, MetadataFileName)), MetadataFileName)) { int nameIndex = mr.ColumnIndex("Name"); int contextIndex = mr.ColumnIndex("Context"); int valueIndex = mr.ColumnIndex("Value"); while (mr.NextRow()) { String8 name = mr.Current(nameIndex).ToString8(); String8 context = mr.Current(contextIndex).ToString8(); ITabularValue value = mr.Current(valueIndex); if (name.Equals("RowCount")) { metadata.RowCount = value.ToInteger(); } else { throw new NotImplementedException($"TableMetadataSerializer.Read doesn't know how to read Metadata '{name}'"); } } } metadata.Query = streamProvider.ReadAllText(Path.Combine(tableRootPath, ConfigQueryPath)); return(metadata); }