public void returns_validation_error_for_incorrect_attribute_ordering() { //Arrange var reader = new DelimitedDataReader<InvalidTestFileImport>(); string fileData = "FirstName 20 20.5 2011/09/01"; //Act Tuple<ICollection<ValidationResult>, InvalidTestFileImport> dataResult = reader.ReadLine(fileData); //Assert Assert.False(dataResult.IsValid()); }
public void returns_validation_error_with_new_instance_for_single_data_field() { //Arrange var reader = new DelimitedDataReader<TestFileImport>(); string fileData = "data"; //Act Tuple<ICollection<ValidationResult>, TestFileImport> dataResult = reader.ReadLine(fileData); //Assert Assert.False(dataResult.IsValid()); }
public void returns_zero_validation_errors_for_correct_file_data() { //Arrange var reader = new DelimitedDataReader<TestFileImportWithNullableTypesDataAnnotations>(); string fileData = "20 20.5 2011/09/01"; //Act Tuple<ICollection<ValidationResult>, TestFileImportWithNullableTypesDataAnnotations> dataResult = reader.ReadLine(fileData); //Assert Assert.True(dataResult.IsValid()); }
public void returns_two_validation_errors_for_mising_name_age() { //Arrange var reader = new DelimitedDataReader<TestFileImportWithDataAnnotations>(); string fileData = " 20.5 2011/09/01"; //Act Tuple<ICollection<ValidationResult>, TestFileImportWithDataAnnotations> dataResult = reader.ReadLine(fileData); //Assert Assert.Equal(2, dataResult.ValidationResultCount()); }
public void returns_one_validation_errors_for_incorrect_type() { //Arrange var reader = new DelimitedDataReader<TestFileImportWithNullableTypesDataAnnotations>(); string fileData = "foo 20.5 2011/09/01"; //Act Tuple<ICollection<ValidationResult>, TestFileImportWithNullableTypesDataAnnotations> dataResult = reader.ReadLine(fileData); //Assert Assert.Equal(1, dataResult.ValidationResultCount()); }
public void returns_property_count_mismatch_validation_error_for_null_input() { //Arrange var reader = new DelimitedDataReader<TestFileImport>(); string fileData = " "; //Act Tuple<ICollection<ValidationResult>, TestFileImport> readLine = reader.ReadLine(fileData); //Assert Assert.False(readLine.IsValid()); }
public void returns_() { //Arrange var reader = new DelimitedDataReader<SingleObject>(); string fileData = " "; //Act Tuple<ICollection<ValidationResult>, SingleObject> readLine = reader.ReadLine(fileData); //Assert Assert.False(readLine.IsValid()); }
public void throw_when_destination_has_no_order_attributes() { //Arrange var reader = new DelimitedDataReader<TestFileImportWithNoAttributes>(); string fileData = "FirstName 20 20.5 2011/09/01"; //Act var exception = Assert.Throws<ValidationException>(() => reader.ReadLine(fileData)); //Assert Assert.Contains("does not have Order attribute", exception.Message); }
public void returns_field_with_quotes_removed() { //Arrange var reader = new DelimitedDataReader<TestFileImport>(); string fileData = "\"FirstName\" \"20\" \"20.5\" \"2011/09/01\""; var expected = new TestFileImport { Name = "FirstName", Age = 20, Wage = 20.5, EventDate = new DateTime(2011, 9, 01) }; //Act Tuple<ICollection<ValidationResult>, TestFileImport> actual = reader.ReadLine(fileData); //Assert Assert.Equal(expected, actual.Item2); }
public void CanReadCsvSingleLine(string line, params string[] expectedValues) { using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(line))) { using (var reader = new DelimitedDataReader(',', memoryStream)) { var fields = reader.ReadLine(); for (var i = 0; i < expectedValues.Length; i++) { Assert.AreEqual(expectedValues[i], fields[i]); } } } }
public void CanReadCsvSingleLineWithEmptyFields() { using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes("One,,Three\r\n\"\",Five,Six"))) { using (var reader = new DelimitedDataReader(',', memoryStream)) { var lines = reader.ReadAllLines(); Assert.AreEqual("One", lines[0][0]); Assert.AreEqual(string.Empty, lines[0][1]); Assert.AreEqual("Three", lines[0][2]); Assert.AreEqual(string.Empty, lines[1][0]); Assert.AreEqual("Five", lines[1][1]); Assert.AreEqual("Six", lines[1][2]); } } }
public void CanReadCsvMultiLinesWithNestedCRLF() { using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes("One,\"\r\nTwo\",Three\r\nFour,Five,Six"))) { using (var reader = new DelimitedDataReader(',', memoryStream)) { var lines = reader.ReadAllLines(); Assert.AreEqual("One", lines[0][0]); Assert.AreEqual("\r\nTwo", lines[0][1]); Assert.AreEqual("Three", lines[0][2]); Assert.AreEqual("Four", lines[1][0]); Assert.AreEqual("Five", lines[1][1]); Assert.AreEqual("Six", lines[1][2]); } } }