public void DeserializeShouldThrowErrorSomethingWithInvalidFormat() { const string input = @"Count ""This is the description"""; Assert.Throws <FormatException>(() => CsvConvert.Deserialize <SimpleExample>(input)); }
public void Deserialize_InvalidArgs_Exception() { Assert.Throws <ArgumentNullException>(() => CsvConvert.Deserialize(null, null)); Assert.Throws <ArgumentNullException>(() => CsvConvert.Deserialize(_table, null)); Assert.Throws <ArgumentException>(() => CsvConvert.Deserialize(_table, typeof(TestType))); Assert.Throws <ArgumentException>(() => CsvConvert.Deserialize(_table, typeof(CsvData))); }
public void DeserializeNoEntriesOnlyHeader() { const string input = @"Count,Flag,Description"; var result = CsvConvert.Deserialize <SimpleExample>(input); Assert.That(result, Is.SameAs(default(SimpleExample))); }
public void FileWithHeaderDateAndSemi() { var text = File.ReadAllText(Path.Combine("Files", "FileWithHeaderDateAndSemi.csv")); var result = CsvConvert.Deserialize <FileWithHeaderDateAndSemi>(text).ToList(); result.First().Name.Should().Be("Gabs"); result.First().DateOfBirth.Should().Be(new DateTime(1980, 10, 11)); }
public void DeserializeShouldHonorEnums() { const string input = @"Status Done"; var result = CsvConvert.Deserialize <EnumExample>(input); Assert.That(result.Status, Is.EqualTo(ExampleStatuses.Done)); }
public void DeserializeShouldHonorEnumDescriptions() { const string input = @"Status ""In Progress"""; var result = CsvConvert.Deserialize <EnumExample>(input); Assert.That(result.Status, Is.EqualTo(ExampleStatuses.InProgress)); }
public void FileHeaderContainsQuotes() { var text = File.ReadAllText(Path.Combine("Files", "FileWithQuotes.csv")); var result = CsvConvert.Deserialize <FileWithQuotes>(text).ToList(); result.First().Title.Should().Be("Greetings"); result.First(r => r.Title.Contains("New York")).Title.Should().Be("New York, New York"); }
public void FileAttributeIsDefined() { var text = File.ReadAllText(Path.Combine("Files", "FileWithHeader.csv")); var result = CsvConvert.Deserialize <FileWithHeader>(text).ToList(); result.Count().Should().Be(3); result.First().Name.Should().Be("Gabs"); }
public void DeserializeShouldNotCareAboutInputOrder() { const string input = @"Description,Count,Flag ""This is the description"",5,true"; var result = CsvConvert.Deserialize <SimpleExample>(input); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void Deserialize_ShouldHonorPropertyAttribute() { const string input = @"count,flag,desc 5,true,""This is the description"""; var result = CsvConvert.Deserialize <PropertyAttributeExample>(input); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void Deserialize_ShouldHandleEscapedPropertyNamesAttribute() { const string input = @"""The Count"",""A Flag"",""A Description"" 5,True,""This is the description"""; var result = CsvConvert.Deserialize <EscapedPropertyAttributeExample>(input); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void DeserializeShouldIgnoreHeadersThatDoNotCorrespondWithAccessors() { const string input = @"Description,ID ""This is the description"",5"; var result = CsvConvert.Deserialize <SimpleExample>(input); Assert.That(result.Count, Is.EqualTo(0)); Assert.That(result.Flag, Is.False); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void Deserialize_ShouldHonorIgnoreAttribute() { const string input = @"Count,Flag,Description 5,true,""This is the description"""; var result = CsvConvert.Deserialize <IgnoreAttributeExample>(input); Assert.That(result.Count, Is.EqualTo(0)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void DeserializeShouldHandleMissingProperties() { const string input = @"Count 5"; var result = CsvConvert.Deserialize <SimpleExample>(input); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.False); Assert.That(result.Description, Is.EqualTo(default(string))); }
public void DeserializeRecord() { const string input = @"Count,Flag,Description 5,true,""This is the description"""; var result = CsvConvert.Deserialize <RecordExample>(input); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void FileWithHeaderAndModelWithoutAttributes() { var text = File.ReadAllText(Path.Combine("Files", "FileWithHeaderWithoutAttributes.csv")); var result = CsvConvert.Deserialize <FileWithHeaderWithoutAttributes>(text).ToList(); result.Count().Should().Be(3); result.First().Name.Should().Be("Gabs"); result.First().Age.Should().Be(35); result.Last().Name.Should().Be("Anna"); result.Last().Age.Should().Be(23); }
public void Deserialize_ShouldHonorEscapeDoubleQuote() { const string input = @"Count,Flag,Description 5,True,""This is a quote"""""; var result = CsvConvert.Deserialize <SimpleExample>(input); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is a quote\"")); }
public void Deserialize_DifferentSeparator() { const string input = @"Count!Flag!Description 5!true!""This is the description"""; var result = CsvConvert.Deserialize <SimpleExample>(input, new CsvConvertSettings { Separator = '!' }); Assert.That(result.Count, Is.EqualTo(5)); Assert.That(result.Flag, Is.True); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void DeserializeShouldIgnoreProtectedAccessors() { const string input = @"Flag,Description true,""This is the description"""; var result = CsvConvert.Deserialize <AccessModifierExample>(input); var privateAccessors = typeof(AccessModifierExample) .GetAccessors(BindingFlags.Instance | BindingFlags.NonPublic) .ToDictionary(gs => gs.Name, gs => gs); Assert.That(privateAccessors["Flag"].Value[result], Is.False); Assert.That(result.Description, Is.EqualTo("This is the description")); }
public void FileWithHeaderAndDateAsStream() { var text = File.ReadAllText(Path.Combine("Files", "FileWithHeaderAndDate.csv")); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(text); writer.Flush(); stream.Position = 0; var result = CsvConvert.Deserialize <FileWithHeaderAndDate>(stream).ToList(); result.First().Name.Should().Be("Gabs"); result.First().DateOfBirth.Should().Be(new DateTime(1980, 10, 11)); }
public void DeserializeShouldThrowUseErrorCallbackIfProvided() { const string input = @"Count ""This is the description"""; var onErrorWasCalled = false; CsvConvert.Deserialize <SimpleExample>(input, new CsvConvertSettings { OnError = _ => onErrorWasCalled = true }); Assert.That(onErrorWasCalled, Is.True); }
// Loads the specified CsvDataTable<TCsvData> type at the specified path, where type must be a generic. public override void LoadAsset(Type type, string path) { // Make sure its a generic type. Debug.Assert(type.IsGenericType, "type should be generic."); // Use the generic argument in type, as the arguments // in CsvConvert.Deserialize(CsvTable, Type). // The genericArgs should be of type CsvData. var genericArgs = type.GetGenericArguments()[0]; Debug.Assert(genericArgs.BaseType == typeof(CsvData) && !genericArgs.IsAbstract); // Load .csv file into a CsvTable object. var table = new CsvTable(path); // Convert that CsvTable object into a CsvDataTable<TCsvData> object. var dataTable = CsvConvert.Deserialize(table, genericArgs); Table.Add(dataTable); _type2id.Add(type, dataTable.KindID); }
public override void Execute() { CsvConvert.Deserialize(_table, typeof(BuildingData)); }
public void DeserializeEmptyString() { var result = CsvConvert.Deserialize <SimpleExample>(""); Assert.That(result, Is.SameAs(default(SimpleExample))); }
public void Deserialize_ReturnType() { var table = CsvConvert.Deserialize(_table, typeof(BuildingData)); Assert.IsInstanceOf <CsvDataTable <BuildingData> >(table); }
public void DeserializeIgnore() { IEnumerable <GeniusIgnore> genius = CsvConvert.Deserialize <GeniusIgnore>(Properties.Resources.sample, CultureInfo.InvariantCulture); Assert.AreEqual(3, geniusIgnore.Count()); }