public void Export_WithVariousAssessmentSectionConfigurations_ReturnsTrueAndWritesCorrectData( AssessmentSectionStub assessmentSection, IEnumerable <string> expectedFiles) { // Setup string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_WithVariousAssessmentSectionConfigurations_ReturnsTrueAndWritesCorrectData)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "test.zip"); var exporter = new HydraulicBoundaryLocationCalculationsExporter(assessmentSection, filePath); try { // Call bool isExported = exporter.Export(); // Assert Assert.IsTrue(isExported); using (ZipArchive zipArchive = ZipFile.OpenRead(filePath)) { CollectionAssert.IsSubsetOf(expectedFiles, zipArchive.Entries.Select(e => e.FullName)); } } finally { DirectoryHelper.TryDelete(directoryPath); } }
public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); string filePath = TestHelper.GetScratchPadPath(Path.Combine("export", "test.shp")); // Call var exporter = new HydraulicBoundaryLocationCalculationsExporter(assessmentSection, filePath); // Assert Assert.IsInstanceOf <IFileExporter>(exporter); mocks.VerifyAll(); }
public void Export_CreatingZipFileThrowsCriticalFileWriteException_LogErrorAndReturnFalse() { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) }); string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_CreatingZipFileThrowsCriticalFileWriteException_LogErrorAndReturnFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "test.zip"); var exporter = new HydraulicBoundaryLocationCalculationsExporter(assessmentSection, 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_LogErrorAndReturnFalse() { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) }); string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogErrorAndReturnFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "test.zip"); var exporter = new HydraulicBoundaryLocationCalculationsExporter(assessmentSection, filePath); try { using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write)) { // Call var isExported = true; void Call() => isExported = exporter.Export(); // Assert string expectedFilePath = Path.Combine(directoryPath, "~temp", "Waterstanden bij vaste doelkans", "Waterstanden_30000.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); } }