public void GetLocationsCount_DifferentFiles_ShouldReturnNumberOfLocations(string fileName, int expectedCount) { // Setup string path = Path.Combine(testDataPath, fileName); using (var reader = new CharacteristicPointsCsvReader(path)) { // Call int result = reader.GetLocationsCount(); // Assert Assert.AreEqual(expectedCount, result); } }
public void GetLocationsCount_DirectoryCannotBeFound_ThrowsCriticalFileReadException() { // Setup string path = Path.Combine(testDataPath, "..", "this_folder_does_not_exist", "I_do_not_exist.csv"); // Precondition Assert.IsFalse(File.Exists(path)); using (var reader = new CharacteristicPointsCsvReader(path)) { // Call TestDelegate call = () => reader.GetLocationsCount(); // Assert var exception = Assert.Throws <CriticalFileReadException>(call); string expectedMessage = new FileReaderErrorMessageBuilder(path).Build("Het bestandspad verwijst naar een map die niet bestaat."); Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf <DirectoryNotFoundException>(exception.InnerException); } }
public void GetLocationsCount_DuplicateColumnsInHeader_ThrowsCriticalFileReadException() { // Setup string path = Path.Combine(testDataPath, "2locations_header_duplicate_columns.krp.csv"); // Precondition Assert.IsTrue(File.Exists(path)); using (var reader = new CharacteristicPointsCsvReader(path)) { // Call TestDelegate call = () => reader.GetLocationsCount(); // Assert var exception = Assert.Throws <CriticalFileReadException>(call); string expectedMessage = new FileReaderErrorMessageBuilder(path) .WithLocation("op regel 1") .Build("Het bestand is niet geschikt om karakteristieke punten uit te lezen: koptekst komt niet overeen met wat verwacht wordt."); Assert.AreEqual(expectedMessage, exception.Message); } }
public void GetLocationsCount_EmptyFile_ThrowsCriticalFileReadException() { // Setup string path = Path.Combine(testDataPath, "empty.krp.csv"); // Precondition Assert.IsTrue(File.Exists(path)); using (var reader = new CharacteristicPointsCsvReader(path)) { // Call TestDelegate call = () => reader.GetLocationsCount(); // Assert var exception = Assert.Throws <CriticalFileReadException>(call); string expectedMessage = new FileReaderErrorMessageBuilder(path) .WithLocation("op regel 1") .Build("Het bestand is leeg."); Assert.AreEqual(expectedMessage, exception.Message); } }
public void ReadCharacteristicPointsLocation_OpenedValidFileWithHeaderAndTwoLocationsWhileAtTheEndOfFile_ReturnNull() { // Setup string path = Path.Combine(testDataPath, "2locations.krp.csv"); using (var reader = new CharacteristicPointsCsvReader(path)) { int locationsCount = reader.GetLocationsCount(); for (var i = 0; i < locationsCount; i++) { CharacteristicPoints characteristicPointsLocation = reader.ReadCharacteristicPointsLocation(); Assert.IsNotInstanceOf <IDisposable>(characteristicPointsLocation, "Fail Fast: Disposal logic required to be implemented in test."); Assert.IsNotNull(characteristicPointsLocation); } // Call CharacteristicPoints result = reader.ReadCharacteristicPointsLocation(); // Assert Assert.IsNull(result); } }