public void Constructor_ExpectedValues() { // Setup string filePath = TestHelper.GetScratchPadPath(Path.Combine("export", "test.shp")); // Call var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( Enumerable.Empty <Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double> >(), HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); // Assert Assert.IsInstanceOf <IFileExporter>(exporter); }
public void Export_WithHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue( HydraulicBoundaryLocationCalculationsType calculationsType, string expectedCalculationsTypeName) { // Setup string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_WithHydraulicBoundaryLocationCalculationsForTargetProbabilities_WritesFilesAndReturnsTrue)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); var random = new Random(21); var calculationsForTargetProbabilities = new[] { new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>( new List <HydraulicBoundaryLocationCalculation>(), random.NextDouble(0, 0.1)), new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>( new List <HydraulicBoundaryLocationCalculation>(), random.NextDouble(0, 0.01)) }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( calculationsForTargetProbabilities, calculationsType, filePath); try { // Call bool isExported = exporter.Export(); // Assert Assert.IsTrue(isExported); string[] expectedFiles = { $"{expectedCalculationsTypeName}_{GetReturnPeriodText(calculationsForTargetProbabilities.First().Item2)}.shp", $"{expectedCalculationsTypeName}_{GetReturnPeriodText(calculationsForTargetProbabilities.Last().Item2)}.shp" }; using (ZipArchive zipArchive = ZipFile.OpenRead(filePath)) { CollectionAssert.IsSubsetOf(expectedFiles, zipArchive.Entries.Select(e => e.FullName)); } } finally { DirectoryHelper.TryDelete(directoryPath); } }
public void Export_CreatingZipFileThrowsCriticalFileWriteException_LogsErrorAndReturnsFalse() { // Setup string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_CreatingZipFileThrowsCriticalFileWriteException_LogsErrorAndReturnsFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); var calculationsForTargetProbabilities = new[] { new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>( Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), 0.1) }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( calculationsForTargetProbabilities, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); try { using (var helper = new FileDisposeHelper(filePath)) { helper.LockFiles(); // Call var isExported = true; void Call() => isExported = exporter.Export(); // Assert string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " + "Er zijn geen hydraulische belastingenlocaties geëxporteerd."; TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage); Assert.IsFalse(isExported); } } finally { DirectoryHelper.TryDelete(directoryPath); } }
public void Export_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogsErrorAndReturnsFalse() { // Setup string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogsErrorAndReturnsFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "export.zip"); var calculationsForTargetProbabilities = new[] { new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>( Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), 0.1) }; var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilitiesExporter( calculationsForTargetProbabilities, HydraulicBoundaryLocationCalculationsType.WaterLevel, filePath); try { using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.CreateDirectories)) { // Call var isExported = true; void Call() => isExported = exporter.Export(); // Assert string expectedFilePath = Path.Combine(directoryPath, "~temp", "Waterstanden_10.shp"); string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{expectedFilePath}'. " + "Er zijn geen hydraulische belastingenlocaties geëxporteerd."; TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage); Assert.IsFalse(isExported); } } finally { DirectoryHelper.TryDelete(directoryPath); } }