Пример #1
0
        public void WriteWaveConditions_InvalidDirectoryRights_ThrowCriticalFileWriteException()
        {
            // Setup
            string directoryPath = TestHelper.GetScratchPadPath("WriteWaveConditions_InvalidDirectoryRights_ThrowCriticalFileWriteException");

            Directory.CreateDirectory(directoryPath);
            string filePath = Path.Combine(directoryPath, "test.csv");

            // Call
            void Call() => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty <ExportableWaveConditions>(), filePath);

            try
            {
                using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write))
                {
                    // Assert
                    var exception = Assert.Throws <CriticalFileWriteException>(Call);
                    Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message);
                    Assert.IsInstanceOf <UnauthorizedAccessException>(exception.InnerException);
                }
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
Пример #2
0
        public void WriteWaveConditions_FilePathNull_ThrowArgumentNullException()
        {
            // Call
            void Call() => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty <ExportableWaveConditions>(), null);

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

            Assert.AreEqual("filePath", exception.ParamName);
        }
Пример #3
0
        public void WriteWaveConditions_ExportableWaveConditionsCollectionNull_ThrowArgumentNullException()
        {
            // Call
            void Call() => WaveConditionsWriter.WriteWaveConditions(null, "afilePath");

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

            Assert.AreEqual("exportableWaveConditionsCollection", exception.ParamName);
        }
Пример #4
0
        public void WriteWaveConditions_FilePathInvalid_ThrowCriticalFileWriteException(string filePath)
        {
            // Call
            void Call() => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty <ExportableWaveConditions>(), filePath);

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

            Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message);
            Assert.IsInstanceOf <ArgumentException>(exception.InnerException);
        }
Пример #5
0
        public void WriteWaveConditions_FileInUse_ThrowCriticalFileWriteException()
        {
            // Setup
            string path = TestHelper.GetScratchPadPath(nameof(WriteWaveConditions_FileInUse_ThrowCriticalFileWriteException));

            using (var fileDisposeHelper = new FileDisposeHelper(path))
            {
                fileDisposeHelper.LockFiles();

                // Call
                void Call() => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty <ExportableWaveConditions>(), path);

                // Assert
                var exception = Assert.Throws <CriticalFileWriteException>(Call);
                Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{path}'.", exception.Message);
                Assert.IsInstanceOf <IOException>(exception.InnerException);
            }
        }
Пример #6
0
        public void WriteWaveConditions_ValidData_ValidFile()
        {
            // Setup
            ExportableWaveConditions[] exportableWaveConditions =
            {
                new ExportableWaveConditions("blocksName",                                                                               new WaveConditionsInput
                {
                    HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1,                                                         string.Empty,                                      0,       0),
                    LowerBoundaryRevetment    = (RoundedDouble)5.68,
                    UpperBoundaryRevetment    = (RoundedDouble)7.214,
                    StepSize = WaveConditionsInputStepSize.Half,
                    LowerBoundaryWaterLevels = (RoundedDouble)2.689,
                    UpperBoundaryWaterLevels = (RoundedDouble)77.8249863247,
                    UseBreakWater            = true
                },                                                                                                                       CreateWaveConditionsOutputForExport(1.11111, 2.22222,  3.33333, 4.4, 5.5555555), CoverType.StoneCoverBlocks, "1/100"),
                new ExportableWaveConditions("columnsName",                                                                              new WaveConditionsInput
                {
                    HydraulicBoundaryLocation = new HydraulicBoundaryLocation(8,                                                         "aLocation",                                      44, 123.456),
                    LowerBoundaryRevetment    = (RoundedDouble)1.384,
                    UpperBoundaryRevetment    = (RoundedDouble)11.54898963,
                    StepSize = WaveConditionsInputStepSize.One,
                    LowerBoundaryWaterLevels = (RoundedDouble)1.98699,
                    UpperBoundaryWaterLevels = (RoundedDouble)84.26548
                },                                                                                                                       CreateWaveConditionsOutputForExport(3.33333, 1.11111,  4.44444, 2.2,   6.66666), CoverType.StoneCoverColumns, "1/100")
            };

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

            using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(WriteWaveConditions_ValidData_ValidFile)))
            {
                string filePath = Path.Combine(directoryPath, "test.csv");

                // Call
                WaveConditionsWriter.WriteWaveConditions(exportableWaveConditions, filePath);

                // Assert
                Assert.IsTrue(File.Exists(filePath));
                string fileContent  = File.ReadAllText(filePath);
                string expectedText = $"Naam berekening; Naam HB locatie; X HB locatie (RD) [m]; Y HB locatie (RD) [m]; Naam voorlandprofiel; Dam gebruikt; Voorlandgeometrie gebruikt; Type bekleding; Doelkans [1/jaar]; Waterstand [m+NAP]; Golfhoogte (Hs) [m]; Golfperiode (Tp) [s]; Golfrichting t.o.v. dijknormaal [°]; Golfrichting t.o.v. Noord [°]{Environment.NewLine}" +
                                      $"blocksName; ; 0.000; 0.000; ; ja; nee; Steen (blokken); 1/100; 1.11; 2.22; 3.33; 4.40; 5.56{Environment.NewLine}" +
                                      $"columnsName; aLocation; 44.000; 123.456; ; nee; nee; Steen (zuilen); 1/100; 3.33; 1.11; 4.44; 2.20; 6.67{Environment.NewLine}";
                Assert.AreEqual(expectedText, fileContent);
            }
        }