Beispiel #1
0
        public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse()
        {
            // Setup
            const string folderName    = nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse);
            string       directoryPath = TestHelper.GetScratchPadPath(folderName);

            using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), folderName))
            {
                string filePath = Path.Combine(directoryPath, "test.xml");

                TCalculationConfigurationExporter exporter = CallConfigurationFilePathConstructor(new[]
                {
                    CreateCalculation()
                }, filePath);

                disposeHelper.LockDirectory(FileSystemRights.Write);

                // Call
                var isExported = true;
                void Call() => isExported = exporter.Export();

                // Assert
                IEnumerable <Tuple <string, LogLevelConstant> > logMessages = GetExpectedExportFailedLogMessages(filePath);
                TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, logMessages);
                Assert.IsFalse(isExported);
            }
        }
Beispiel #2
0
        public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(1.1, 2.2),
                new Point2D(11.11, 22.22)
            });

            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.shp");
                var    exporter = new ReferenceLineExporter(referenceLine, "anId", 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}'.{Environment.NewLine}Er is geen referentielijn geëxporteerd.";
                TestHelper.AssertLogMessageIsGenerated(call, expectedMessage);
                Assert.IsFalse(isExported);
            }
        }
Beispiel #3
0
        public void OneTimeSetUp()
        {
            testSettingsHelper = new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = TestHelper.GetScratchPadPath(nameof(WellKnownTileSourceLayerConfigurationTest))
            };

            directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(WellKnownTileSourceLayerConfigurationTest));
        }
        public void OneTimeSetUp()
        {
            testSettingsHelper = new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = TestHelper.GetScratchPadPath(nameof(RiskeerMapControlTest))
            };

            directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(RiskeerMapControlTest));
        }
        public void WriteDuneLocationCalculations_InvalidDirectoryRights_ThrowCriticalFileWriteException()
        {
            // Setup
            string directoryPath = TestHelper.GetScratchPadPath(nameof(WriteDuneLocationCalculations_InvalidDirectoryRights_ThrowCriticalFileWriteException));

            using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(WriteDuneLocationCalculations_InvalidDirectoryRights_ThrowCriticalFileWriteException)))
            {
                string filePath = Path.Combine(directoryPath, "test.bnd");
                disposeHelper.LockDirectory(FileSystemRights.Write);

                // Call
                void Call() => DuneLocationCalculationsWriter.WriteDuneLocationCalculations(Enumerable.Empty <ExportableDuneLocationCalculation>(), 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 <UnauthorizedAccessException>(exception.InnerException);
            }
        }
Beispiel #6
0
        public void Write_InvalidDirectoryRights_ThrowCriticalFileWriteException()
        {
            // Setup
            string directoryPath = TestHelper.GetScratchPadPath(nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException));

            using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException)))
            {
                string filePath = Path.Combine(directoryPath, "test.xml");
                disposeHelper.LockDirectory(FileSystemRights.Write);
                TWriter writer = CreateWriterInstance(filePath);

                // Call
                TestDelegate call = () => writer.Write(Enumerable.Empty <IConfigurationItem>());

                // Assert
                var exception = Assert.Throws <CriticalFileWriteException>(call);
                AssertInvalidDirectoryRights(exception, filePath);
            }
        }
Beispiel #7
0
        public void Perform_InsufficientAccessRights_ExpectedExceptionThrown()
        {
            // Setup
            string writableDirectory = Path.Combine(testWorkDir, nameof(Perform_InsufficientAccessRights_ExpectedExceptionThrown));
            string targetFilePath    = Path.Combine(writableDirectory, "targetFile.txt");

            using (var directoryDisposeHelper = new DirectoryDisposeHelper(testWorkDir, nameof(Perform_InsufficientAccessRights_ExpectedExceptionThrown)))
            {
                directoryDisposeHelper.LockDirectory(FileSystemRights.Write);

                var writer = new SafeFileWriter(targetFilePath, temporaryFileExtension);

                // Call
                var exception = Assert.Throws <IOException>(() => writer.Perform(() => {}));

                // Assert
                Assert.AreEqual("Onvoldoende rechten voor het schrijven van het doelbestand.", exception.Message);
            }
        }
        public void SaveAs_InvalidDirectoryRights_ThrowCriticalFileWriteException()
        {
            string directoryPath = TestHelper.GetScratchPadPath(nameof(SaveAs_InvalidDirectoryRights_ThrowCriticalFileWriteException));
            string filePath      = Path.Combine(directoryPath, "test.shp");

            using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(SaveAs_InvalidDirectoryRights_ThrowCriticalFileWriteException)))
                using (var writer = new TestShapeFileWriterBase())
                {
                    disposeHelper.LockDirectory(FileSystemRights.Write);

                    // Call
                    TestDelegate call = () => writer.SaveAs(filePath);

                    // Assert
                    string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.";
                    string message         = Assert.Throws <CriticalFileWriteException>(call).Message;
                    Assert.AreEqual(expectedMessage, message);
                }
        }
        public void WriteAssembly_InvalidDirectoryRights_ThrowsCriticalFileWriteException()
        {
            // Setup
            const string directoryName = nameof(WriteAssembly_InvalidDirectoryRights_ThrowsCriticalFileWriteException);
            string       directoryPath = TestHelper.GetScratchPadPath(directoryName);

            using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), directoryName))
            {
                string filePath = Path.Combine(directoryPath, "test.bnd");
                disposeHelper.LockDirectory(FileSystemRights.Write);

                // Call
                void Call() => SerializableAssemblyWriter.WriteAssembly(new SerializableAssembly(), 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 <UnauthorizedAccessException>(exception.InnerException);
            }
        }
Beispiel #10
0
        public void CreateInitializedConfiguration_CannotCreateFileCache_ThrowConfigurationInitializationException(ImageBasedMapData mapData)
        {
            // Setup
            using (new UseCustomSettingsHelper(new TestSettingsHelper
            {
                ApplicationLocalUserSettingsDirectory = Path.Combine(TestHelper.GetScratchPadPath(), nameof(BrutileConfigurationFactoryTest))
            }))
                using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(BrutileConfigurationFactoryTest)))
                    using (new UseCustomTileSourceFactoryConfig(mapData))
                    {
                        disposeHelper.LockDirectory(FileSystemRights.Write);

                        // Call
                        TestDelegate test = () => BrutileConfigurationFactory.CreateInitializedConfiguration(mapData);

                        // Assert
                        var exception = Assert.Throws <ConfigurationInitializationException>(test);
                        Assert.IsInstanceOf <CannotCreateTileCacheException>(exception.InnerException);
                        Assert.AreEqual("Configuratie van kaartgegevens hulpbestanden is mislukt.", exception.Message);
                    }
        }
        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);
            }
        }
Beispiel #12
0
 public void OneTimeSetUp()
 {
     directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(StorageMigrationIntegrationTest));
 }
Beispiel #13
0
 public void Setup()
 {
     directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), testDirectory);
 }