public void Constructor_ValidParameters_ExpectedValues() { // Setup string filePath = TestHelper.GetScratchPadPath(Path.Combine(nameof(DuneLocationCalculationsExporterTest), "test.bnd")); // Call var exporter = new DuneLocationCalculationsExporter(Enumerable.Empty <ExportableDuneLocationCalculation>(), filePath); // Assert Assert.IsInstanceOf <IFileExporter>(exporter); }
public void Export_ValidData_ReturnTrueAndWritesFile() { // Setup var calculationWithoutOutput = new ExportableDuneLocationCalculation( new DuneLocationCalculation(CreateDuneLocationForExport(9, 9740, 1.9583e-4)), 0.5); var calculationWithNotCalculatedOutput = new ExportableDuneLocationCalculation( new DuneLocationCalculation(CreateDuneLocationForExport(10, 9770.1, 1.9583e-4)) { Output = CreateDuneLocationCalculationOutputForExport(double.NaN, double.NaN, double.NaN) }, 0.25); var calculationWithOutput = new ExportableDuneLocationCalculation( new DuneLocationCalculation(CreateDuneLocationForExport(11, 9771.34, 1.337e-4)) { Output = CreateDuneLocationCalculationOutputForExport(5.89, 14.11, 8.53) }, 0.1); ExportableDuneLocationCalculation[] exportableDuneLocationCalculations = { calculationWithoutOutput, calculationWithNotCalculatedOutput, calculationWithOutput }; string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_ValidData_ReturnTrueAndWritesFile)); using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_ValidData_ReturnTrueAndWritesFile))) { string filePath = Path.Combine(directoryPath, "test.bnd"); var exporter = new DuneLocationCalculationsExporter(exportableDuneLocationCalculations, filePath); // Call bool isExported = exporter.Export(); // Assert Assert.IsTrue(isExported); Assert.IsTrue(File.Exists(filePath)); string fileContent = File.ReadAllText(filePath); string expectedText = $"Kv\tNr\tRp\tHs\tTp\tTm-1,0\tD50\t_BOI2023_Waarde{Environment.NewLine}" + $"*Kustvaknummer\tMetrering\tRekenpeil\tSignificante golfhoogte\tPiekperiode\tSpectrale periode\tKorreldiameter\tPfdsn{Environment.NewLine}" + $"*[-]\t[dam]\t[m+NAP]\t[m]\t[s]\t[s]\t[m]\t[1/jaar]{Environment.NewLine}" + $"9\t9740\t*\t*\t*\t*\t0.000196\t0.5{Environment.NewLine}" + $"10\t9770.1\t*\t*\t*\t*\t0.000196\t0.25{Environment.NewLine}" + $"11\t9771.3\t5.89\t8.53\t14.11\t*\t0.000134\t0.1{Environment.NewLine}"; Assert.AreEqual(expectedText, fileContent); } }
public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse() { // Setup string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse)); using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse))) { string filePath = Path.Combine(directoryPath, "test.bnd"); var exporter = new DuneLocationCalculationsExporter(Enumerable.Empty <ExportableDuneLocationCalculation>(), filePath); disposeHelper.LockDirectory(FileSystemRights.Write); var isExported = true; // Call Action 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); } }