private static bool ExportLocationCalculationsForTargetProbabilities(
     IEnumerable <Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double> > calculationsForTargetProbabilities,
     HydraulicBoundaryLocationCalculationsType calculationsType, string folderPath)
 {
     return(HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                calculationsForTargetProbabilities, calculationsType, folderPath));
 }
        public bool Export()
        {
            try
            {
                if (!HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                        locationCalculationsForTargetProbabilities, calculationsType, tempFolderPath))
                {
                    return(false);
                }

                ZipFileExportHelper.CreateZipFileFromExportedFiles(tempFolderPath, filePath);

                return(true);
            }
            catch (CriticalFileWriteException e)
            {
                log.ErrorFormat(RiskeerCommonIOResources.HydraulicBoundaryLocationsExporter_Error_Exception_0_no_HydraulicBoundaryLocations_exported,
                                e.Message);
                return(false);
            }
            finally
            {
                if (Directory.Exists(tempFolderPath))
                {
                    DirectoryHelper.TryDelete(tempFolderPath);
                }
            }
        }
Esempio n. 3
0
        public void ExportLocationCalculationsForTargetProbabilities_FolderPathNull_ThrowsArgumentException()
        {
            // Call
            void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                Enumerable.Empty <Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double> >(), HydraulicBoundaryLocationCalculationsType.WaterLevel, null);

            // Assert
            Assert.Throws <ArgumentException>(Call);
        }
Esempio n. 4
0
        public void ExportLocationCalculationsForTargetProbabilities_CalculationsForTargetProbabilitiesNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                null,
                HydraulicBoundaryLocationCalculationsType.WaterLevel, string.Empty);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("calculationsForTargetProbabilities", exception.ParamName);
        }
Esempio n. 5
0
        public void ExportLocationCalculationsForTargetProbabilities_InvalidCalculationsType_ThrowsInvalidEnumArgumentException()
        {
            // Setup
            const HydraulicBoundaryLocationCalculationsType calculationsType = (HydraulicBoundaryLocationCalculationsType)99;

            // Call
            void Call() => HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                Enumerable.Empty <Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double> >(), calculationsType, string.Empty);

            // Assert
            string expectedMessage = $"The value of argument 'calculationsType' ({calculationsType}) " +
                                     $"is invalid for Enum type '{nameof(HydraulicBoundaryLocationCalculationsType)}'.";
            var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage);

            Assert.AreEqual("calculationsType", exception.ParamName);
        }
Esempio n. 6
0
        public void ExportLocationCalculationsForTargetProbabilities_ValidData_ReturnsTrueAndWritesCorrectData(HydraulicBoundaryLocationCalculationsType calculationsType,
                                                                                                               string expectedExportFileName)
        {
            // Setup
            const double targetProbability = 0.05;

            string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_ValidData_ReturnsTrueAndWritesCorrectData));

            Directory.CreateDirectory(directoryPath);

            string shapeFileName = GetExpectedShapeFileName(calculationsType, targetProbability);

            // Precondition
            FileTestHelper.AssertEssentialShapefilesExist(directoryPath, $"{shapeFileName}.shp", false);

            try
            {
                // Call
                bool isExported = HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                    new[]
                {
                    new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(new[]
                    {
                        new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2))
                    }, targetProbability)
                }, calculationsType, directoryPath);

                // Assert
                Assert.IsTrue(isExported);

                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, shapeFileName, true);
                FileTestHelper.AssertEssentialShapefileMd5Hashes(
                    directoryPath, shapeFileName,
                    Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO),
                                 nameof(HydraulicBoundaryLocationCalculationsExportHelper)),
                    expectedExportFileName, 28, 8, 628);
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
Esempio n. 7
0
        public void ExportLocationCalculationsForTargetProbabilities_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogErrorAndReturnFalse()
        {
            // Setup
            var    random            = new Random(21);
            double targetProbability = random.NextDouble(0, 0.1);
            var    calculationsType  = random.NextEnumValue <HydraulicBoundaryLocationCalculationsType>();

            string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogErrorAndReturnFalse));

            Directory.CreateDirectory(directoryPath);

            try
            {
                using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write))
                {
                    // Call
                    var isExported = true;

                    void Call() => isExported = HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                        new[]
                    {
                        new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(new[]
                        {
                            new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2))
                        }, targetProbability)
                    }, calculationsType, directoryPath);

                    // Assert
                    string fileName        = GetExpectedShapeFileName(calculationsType, targetProbability);
                    string filePath        = Path.Combine(directoryPath, $"{fileName}.shp");
                    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);
            }
        }
Esempio n. 8
0
        public void ExportLocationCalculationsForTargetProbabilities_DuplicateTargetProbability_ReturnsTrueAndWritesExpectedFiles(HydraulicBoundaryLocationCalculationsType calculationsType)
        {
            // Setup
            const double targetProbability = 0.00005;

            string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_DuplicateTargetProbability_ReturnsTrueAndWritesExpectedFiles));

            Directory.CreateDirectory(directoryPath);

            string shapeFileName = GetExpectedShapeFileName(calculationsType, targetProbability);

            // Precondition
            FileTestHelper.AssertEssentialShapefilesExist(directoryPath, $"{shapeFileName}.shp", false);

            try
            {
                // Call
                bool isExported = HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                    new[]
                {
                    new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(
                        Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), targetProbability),
                    new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(
                        Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), targetProbability)
                }, calculationsType, directoryPath);

                // Assert
                Assert.IsTrue(isExported);

                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, shapeFileName, true);
                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, $"{shapeFileName} (1)", true);
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }