Index: Core/Common/test/Core.Common.TestUtil/DirectoryDisposeHelper.cs =================================================================== diff -u -r28abea0fa843f62a5c0835cba5831cf2206abc5d -rf02614d781e389e05b9b481e8d165286e6baad4d --- Core/Common/test/Core.Common.TestUtil/DirectoryDisposeHelper.cs (.../DirectoryDisposeHelper.cs) (revision 28abea0fa843f62a5c0835cba5831cf2206abc5d) +++ Core/Common/test/Core.Common.TestUtil/DirectoryDisposeHelper.cs (.../DirectoryDisposeHelper.cs) (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -104,9 +104,11 @@ directoryPermissionsRevoker?.Dispose(); + var directoryDeleted = false; try { Directory.Delete(rootPathToTemp, true); + directoryDeleted = true; } catch { @@ -118,7 +120,7 @@ directoryPermissionsRevoker = null; } - disposed = true; + disposed = !directoryDeleted; } /// Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileSettings.cs =================================================================== diff -u -r86b2665e1dd51dc99d33568d1f4206f3da204254 -rf02614d781e389e05b9b481e8d165286e6baad4d --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileSettings.cs (.../BruTileSettings.cs) (revision 86b2665e1dd51dc99d33568d1f4206f3da204254) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileSettings.cs (.../BruTileSettings.cs) (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -62,6 +62,12 @@ /// /// Gets the root directory path for the persistent cache. /// - public static string PersistentCacheDirectoryRoot { get; } = SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory("tilecaches"); + public static string PersistentCacheDirectoryRoot + { + get + { + return SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory("tilecaches"); + } + } } } \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -r46997e65ad8ad93701ea46c519d8c75e2b6cc0c0 -rf02614d781e389e05b9b481e8d165286e6baad4d --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 46997e65ad8ad93701ea46c519d8c75e2b6cc0c0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -29,6 +29,7 @@ using BruTile; using Core.Common.Base.Data; using Core.Common.Base.Geometry; +using Core.Common.Gui.TestUtil.Settings; using Core.Common.TestUtil; using Core.Components.DotSpatial.Layer.BruTile; using Core.Components.DotSpatial.Layer.BruTile.Configurations; @@ -53,6 +54,8 @@ public class MapControlTest { private const double padding = 0.05; + private const string tileCachesFolder = "tilecaches"; + private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.DotSpatial.Forms); [Test] public void DefaultConstructor_DefaultValues() @@ -229,7 +232,8 @@ Action call = () => map.BackgroundMapData = container; // Then - const string expectedMessage = "Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden. De achtergrondkaart kan nu niet getoond worden."; + const string expectedMessage = "Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden. " + + "De achtergrondkaart kan nu niet getoond worden."; TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); Assert.AreEqual(0, mapView.Layers.Count); @@ -241,69 +245,81 @@ [Test] public void GivenMapControlWithEmptyBackgroundMapDataContainer_WhenSettingBackgroundAndFailingToCreateCache_ThenLogErrorAndDoNotAddBackgroundLayer() { - DoWhileTileCacheRootLocked(() => + // Given + string folderWithoutPermission = Path.GetRandomFileName(); + WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); + var mapDataContainer = new BackgroundMapDataContainer(); + + using (new UseCustomSettingsHelper(new TestSettingsHelper { - // Given - WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); - var mapDataContainer = new BackgroundMapDataContainer(); + ExpectedApplicationLocalUserSettingsDirectory = Path.Combine(testDataPath, folderWithoutPermission) + })) + using (var disposeHelper = new DirectoryDisposeHelper(testDataPath, folderWithoutPermission, tileCachesFolder)) + using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) + using (var map = new MapControl + { + BackgroundMapData = mapDataContainer + }) + { + var mapView = map.Controls.OfType().First(); + var originalProjection = mapView.Projection; - using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) - using (var map = new MapControl + disposeHelper.LockDirectory(FileSystemRights.Write); + + // When + Action call = () => { - BackgroundMapData = mapDataContainer - }) - { - var mapView = map.Controls.OfType().First(); - var originalProjection = mapView.Projection; + mapDataContainer.MapData = backgroundMapData; + mapDataContainer.NotifyObservers(); + }; - // When - Action call = () => - { - mapDataContainer.MapData = backgroundMapData; - mapDataContainer.NotifyObservers(); - }; + // Then + const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. " + + "De achtergrondkaart kan nu niet getoond worden."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); - // Then - const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. De achtergrondkaart kan nu niet getoond worden."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.AreEqual(0, mapView.Layers.Count); - Assert.AreEqual(0, mapView.Layers.Count); - - Assert.AreSame(originalProjection, mapView.Projection); - } - }); + Assert.AreSame(originalProjection, mapView.Projection); + } } [Test] public void GivenMapControlWithoutBackgroundMapData_WhenSettingBackgroundAndFailingToCreateCache_ThenLogErrorAndDoNotAddBackgroundLayer() { - DoWhileTileCacheRootLocked(() => + // Given + string folderWithoutPermission = Path.GetRandomFileName(); + WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); + var mapDataContainer = new BackgroundMapDataContainer { - // Given - WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); - var mapDataContainer = new BackgroundMapDataContainer - { - MapData = backgroundMapData - }; + MapData = backgroundMapData + }; - using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) - using (var map = new MapControl()) - { - var mapView = map.Controls.OfType().First(); - var originalProjection = mapView.Projection; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = Path.Combine(testDataPath, folderWithoutPermission) + })) + using (var disposeHelper = new DirectoryDisposeHelper(testDataPath, folderWithoutPermission, tileCachesFolder)) + using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + var originalProjection = mapView.Projection; - // When - Action call = () => map.BackgroundMapData = mapDataContainer; + disposeHelper.LockDirectory(FileSystemRights.Write); - // Then - const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. De achtergrondkaart kan nu niet getoond worden."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + // When + Action call = () => map.BackgroundMapData = mapDataContainer; - Assert.AreEqual(0, mapView.Layers.Count); + // Then + const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. " + + "De achtergrondkaart kan nu niet getoond worden."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); - Assert.AreSame(originalProjection, mapView.Projection); - } - }); + Assert.AreEqual(0, mapView.Layers.Count); + + Assert.AreSame(originalProjection, mapView.Projection); + } } [Test] @@ -325,7 +341,8 @@ { // Precondition Action setAndCauseFailingInitialization = () => map.BackgroundMapData = mapDataContainer; - const string expectedMessage = "Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden. De achtergrondkaart kan nu niet getoond worden."; + const string expectedMessage = "Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden. " + + "De achtergrondkaart kan nu niet getoond worden."; TestHelper.AssertLogMessageIsGenerated(setAndCauseFailingInitialization, expectedMessage, 1); using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) @@ -348,22 +365,31 @@ public void GivenMapControlWithFailedCacheForBackgroundMapData_WhenBackgroundNotifiesObserversAndLayerInitializationSuccessful_ThenBackgroundLayerAdded() { // Given + string folderWithoutPermission = Path.GetRandomFileName(); + string settingsDirectory = Path.Combine(testDataPath, folderWithoutPermission); + WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); var mapDataContainer = new BackgroundMapDataContainer { MapData = backgroundMapData }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = settingsDirectory + })) + using (new DirectoryDisposeHelper(testDataPath, folderWithoutPermission, tileCachesFolder)) using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) using (var map = new MapControl()) { - DoWhileTileCacheRootLocked(() => + using (new DirectoryPermissionsRevoker(settingsDirectory, FileSystemRights.Write)) { // Precondition Action setAndCauseCacheInitializationFailure = () => map.BackgroundMapData = mapDataContainer; - const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. De achtergrondkaart kan nu niet getoond worden."; + const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. " + + "De achtergrondkaart kan nu niet getoond worden."; TestHelper.AssertLogMessageIsGenerated(setAndCauseCacheInitializationFailure, expectedMessage, 1); - }); + } // When backgroundMapData.NotifyObservers(); @@ -400,7 +426,8 @@ // Precondition Action setAndCauseFailToInitializeLayer = () => map.BackgroundMapData = mapDataContainer; - const string expectedMessage = "Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden. De achtergrondkaart kan nu niet getoond worden."; + const string expectedMessage = "Verbinden met WMTS is mislukt waardoor geen kaartgegevens ingeladen kunnen worden. " + + "De achtergrondkaart kan nu niet getoond worden."; TestHelper.AssertLogMessageIsGenerated(setAndCauseFailToInitializeLayer, expectedMessage, 1); // When @@ -418,37 +445,44 @@ [Test] public void GivenMapControlWithFailedCacheforBackgroundMapData_WhenBackgroundNotifiesObservers_ThenFailedInitializationShouldNotGenerateLogMessage() { - DoWhileTileCacheRootLocked(() => + // Given + string folderWithoutPermission = Path.GetRandomFileName(); + + WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); + var mapDataContainer = new BackgroundMapDataContainer { - // Given - WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); - var mapDataContainer = new BackgroundMapDataContainer - { - MapData = backgroundMapData - }; + MapData = backgroundMapData + }; - using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) - using (var map = new MapControl()) - { - var mapView = map.Controls.OfType().First(); - var originalProjection = mapView.Projection; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = Path.Combine(testDataPath, folderWithoutPermission) + })) + using (var disposeHelper = new DirectoryDisposeHelper(testDataPath, folderWithoutPermission, tileCachesFolder)) + using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + var originalProjection = mapView.Projection; - // Precondition - Action setAndCauseCacheInitializationFailure = () => map.BackgroundMapData = mapDataContainer; - const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. De achtergrondkaart kan nu niet getoond worden."; - TestHelper.AssertLogMessageIsGenerated(setAndCauseCacheInitializationFailure, expectedMessage, 1); + disposeHelper.LockDirectory(FileSystemRights.Write); - // When - Action call = () => backgroundMapData.NotifyObservers(); + // Precondition + Action setAndCauseCacheInitializationFailure = () => map.BackgroundMapData = mapDataContainer; + const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. " + + "De achtergrondkaart kan nu niet getoond worden."; + TestHelper.AssertLogMessageIsGenerated(setAndCauseCacheInitializationFailure, expectedMessage, 1); - // Then - TestHelper.AssertLogMessagesCount(call, 0); + // When + Action call = () => backgroundMapData.NotifyObservers(); - Assert.AreEqual(0, mapView.Layers.Count); + // Then + TestHelper.AssertLogMessagesCount(call, 0); - Assert.AreSame(originalProjection, mapView.Projection); - } - }); + Assert.AreEqual(0, mapView.Layers.Count); + + Assert.AreSame(originalProjection, mapView.Projection); + } } [Test] @@ -529,7 +563,7 @@ var mapDataContainer = new BackgroundMapDataContainer { IsVisible = true, - Transparency = (RoundedDouble)0.25, + Transparency = (RoundedDouble) 0.25, MapData = originalBackGroundMapData }; @@ -544,7 +578,7 @@ // Precondition Assert.AreEqual(1, mapView.Layers.Count); - var layer = (BruTileLayer)mapView.Layers[0]; + var layer = (BruTileLayer) mapView.Layers[0]; Assert.AreEqual(true, layer.IsVisible); Assert.AreEqual(0.25, layer.Transparency); Assert.AreEqual(layer.Projection, mapView.Projection); @@ -634,7 +668,7 @@ // Then Assert.AreEqual(1, mapView.Layers.Count); - var layer = (BruTileLayer)mapView.Layers[0]; + var layer = (BruTileLayer) mapView.Layers[0]; Assert.AreEqual(true, layer.IsVisible); Assert.AreEqual(0.75, layer.Transparency); Assert.IsTrue(layer.Projection.Equals(mapView.Projection)); @@ -761,7 +795,7 @@ // Precondition IMapLayer[] layersBeforeUpdate = mapView.Layers.ToArray(); - var pointFeatureLayer = (FeatureLayer)layersBeforeUpdate[0]; + var pointFeatureLayer = (FeatureLayer) layersBeforeUpdate[0]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(1.1, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X); Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y); @@ -892,7 +926,7 @@ Assert.AreEqual(2, mapView.Layers.Count); IMapLayer[] layersBeforeUpdate = mapView.Layers.ToArray(); Assert.IsInstanceOf(mapView.Layers[0]); - var pointFeatureLayer = (FeatureLayer)layersBeforeUpdate[1]; + var pointFeatureLayer = (FeatureLayer) layersBeforeUpdate[1]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(523414.9114786592, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X, @@ -1017,7 +1051,7 @@ // Precondition var mapView = map.Controls.OfType().First(); - var pointFeatureLayer = (FeatureLayer)mapView.Layers[0]; + var pointFeatureLayer = (FeatureLayer) mapView.Layers[0]; Assert.AreEqual(1, mapView.Layers.Count); Assert.AreEqual(1.1, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X); Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y); @@ -1029,7 +1063,7 @@ // Then Assert.AreEqual(2, mapView.Layers.Count); Assert.IsInstanceOf(mapView.Layers[0]); - pointFeatureLayer = (FeatureLayer)mapView.Layers[1]; + pointFeatureLayer = (FeatureLayer) mapView.Layers[1]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(523414.9114786592, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X, "Coordinate does not match. (Ball park expected value can be calculated from https://epsg.io/transform#s_srs=28992&t_srs=25831&x=1.1000000&y=2.2000000)."); @@ -1126,7 +1160,7 @@ // Precondition var mapView = map.Controls.OfType().First(); - var pointFeatureLayer = (FeatureLayer)mapView.Layers[0]; + var pointFeatureLayer = (FeatureLayer) mapView.Layers[0]; Assert.AreEqual(1, mapView.Layers.Count); Assert.AreEqual(1.1, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X); Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y); @@ -1137,7 +1171,7 @@ // Then Assert.AreEqual(1, mapView.Layers.Count); - pointFeatureLayer = (FeatureLayer)mapView.Layers[0]; + pointFeatureLayer = (FeatureLayer) mapView.Layers[0]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(1.1, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X); Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y); @@ -1232,7 +1266,7 @@ var mapView = map.Controls.OfType().First(); Assert.AreEqual(2, mapView.Layers.Count); Assert.IsInstanceOf(mapView.Layers[0]); - var pointFeatureLayer = (FeatureLayer)mapView.Layers[1]; + var pointFeatureLayer = (FeatureLayer) mapView.Layers[1]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(1.1, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X); Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y); @@ -1247,7 +1281,7 @@ // Then Assert.AreEqual(2, mapView.Layers.Count); Assert.IsInstanceOf(mapView.Layers[0]); - pointFeatureLayer = (FeatureLayer)mapView.Layers[1]; + pointFeatureLayer = (FeatureLayer) mapView.Layers[1]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(523414.9114786592, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X, "Coordinate does not match. (Ball park expected value can be calculated from https://epsg.io/transform#s_srs=28992&t_srs=25831&x=1.1000000&y=2.2000000)."); @@ -1359,7 +1393,7 @@ var mapView = map.Controls.OfType().First(); Assert.AreEqual(2, mapView.Layers.Count); Assert.IsInstanceOf(mapView.Layers[0]); - var pointFeatureLayer = (FeatureLayer)mapView.Layers[1]; + var pointFeatureLayer = (FeatureLayer) mapView.Layers[1]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(523414.9114786592, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X, "Coordinate does not match. (Ball park expected value can be calculated from https://epsg.io/transform#s_srs=28992&t_srs=25831&x=1.1000000&y=2.2000000)."); @@ -1375,12 +1409,12 @@ // Then Assert.AreEqual(1, mapView.Layers.Count); - pointFeatureLayer = (FeatureLayer)mapView.Layers[0]; + pointFeatureLayer = (FeatureLayer) mapView.Layers[0]; Assert.IsTrue(mapView.Projection.Equals(pointFeatureLayer.Projection)); Assert.AreEqual(1.1, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].X, 1e-8, - "Layer is reprojected, so minor delta is acceptable."); + "Layer is reprojected, so minor delta is acceptable."); Assert.AreEqual(2.2, pointFeatureLayer.FeatureSet.Features[0].BasicGeometry.Coordinates[0].Y, 1e-8, - "Layer is reprojected, so minor delta is acceptable."); + "Layer is reprojected, so minor delta is acceptable."); } } } @@ -1627,59 +1661,66 @@ [Test] public void GivenMapControl_WhenBackgroundAndThenMapDataSetAndFailingToCreateCache_MapControlUpdated() { - DoWhileTileCacheRootLocked(() => + // Given + string folderWithoutPermission = Path.GetRandomFileName(); + + WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); + var mapDataContainer = new BackgroundMapDataContainer { - // Given - WmtsMapData backgroundMapData = WmtsMapData.CreateDefaultPdokMapData(); - var mapDataContainer = new BackgroundMapDataContainer - { - MapData = backgroundMapData - }; + MapData = backgroundMapData + }; - using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) - using (var map = new MapControl()) - { - var mapView = map.Controls.OfType().First(); - var originalProjection = mapView.Projection; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = Path.Combine(testDataPath, folderWithoutPermission) + })) + using (var disposeHelper = new DirectoryDisposeHelper(testDataPath, folderWithoutPermission, tileCachesFolder)) + using (new UseCustomTileSourceFactoryConfig(backgroundMapData)) + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + var originalProjection = mapView.Projection; - var mapPointData = new MapPointData("Points") + disposeHelper.LockDirectory(FileSystemRights.Write); + + var mapPointData = new MapPointData("Points") + { + Features = new[] { - Features = new[] + new MapFeature(new[] { - new MapFeature(new[] + new MapGeometry(new[] { - new MapGeometry(new[] + new[] { - new[] - { - new Point2D(1.1, 2.2) - } - }) + new Point2D(1.1, 2.2) + } }) - } - }; - var mapDataCollection = new MapDataCollection("Root collection"); - mapDataCollection.Add(mapPointData); + }) + } + }; + var mapDataCollection = new MapDataCollection("Root collection"); + mapDataCollection.Add(mapPointData); - // When - Action call = () => - { - map.BackgroundMapData = mapDataContainer; - map.Data = mapDataCollection; - }; + // When + Action call = () => + { + map.BackgroundMapData = mapDataContainer; + map.Data = mapDataCollection; + }; - // Then - const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. De achtergrondkaart kan nu niet getoond worden."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + // Then + const string expectedMessage = "Configuratie van kaartgegevens hulpbestanden is mislukt. " + + "De achtergrondkaart kan nu niet getoond worden."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); - Assert.AreEqual(1, mapView.Layers.Count); - var pointsLayer = (FeatureLayer) mapView.Layers[0]; - Assert.AreEqual(mapPointData.Name, pointsLayer.Name); - Assert.AreSame(originalProjection, pointsLayer.Projection); + Assert.AreEqual(1, mapView.Layers.Count); + var pointsLayer = (FeatureLayer) mapView.Layers[0]; + Assert.AreEqual(mapPointData.Name, pointsLayer.Name); + Assert.AreSame(originalProjection, pointsLayer.Projection); - Assert.AreSame(originalProjection, mapView.Projection); - } - }); + Assert.AreSame(originalProjection, mapView.Projection); + } } [Test] @@ -2732,37 +2773,6 @@ .SetName($"{prefix}: Tile source factory throws CannotFindTileSourceException."); } - private static void DoWhileTileCacheRootLocked(Action test) - { - string expectedTileCachePath = Path.Combine(BruTileSettings.PersistentCacheDirectoryRoot, "wmts"); - - string backupTileCachePath = expectedTileCachePath + "_bak"; - if (Directory.Exists(backupTileCachePath)) - { - Directory.Delete(backupTileCachePath, true); - } - - if (Directory.Exists(expectedTileCachePath)) - { - Directory.Move(expectedTileCachePath, backupTileCachePath); - } - - try - { - using (new DirectoryPermissionsRevoker(BruTileSettings.PersistentCacheDirectoryRoot, FileSystemRights.Write)) - { - test(); - } - } - finally - { - if (Directory.Exists(backupTileCachePath)) - { - Directory.Move(backupTileCachePath, expectedTileCachePath); - } - } - } - private static MapDataCollection GetTestData() { var mapDataCollection = new MapDataCollection("Test data"); Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs =================================================================== diff -u -rdf1c6b4964f21984dab85a5f8becb0824a82800f -rf02614d781e389e05b9b481e8d165286e6baad4d --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs (.../WmtsLocationControlTest.cs) (revision df1c6b4964f21984dab85a5f8becb0824a82800f) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs (.../WmtsLocationControlTest.cs) (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -159,34 +159,35 @@ public void WmtsLocationControl_WithData_DataGridViewCorrectlyInitialized() { // Setup - SettingsHelper.Instance = new TestSettingsHelper + using (new UseCustomSettingsHelper(new TestSettingsHelper { ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - - // Call - using (WmtsLocationControl control = ShowFullyConfiguredWmtsLocationControl()) + })) { - Form form = control.FindForm(); + // Call + using (WmtsLocationControl control = ShowFullyConfiguredWmtsLocationControl()) + { + Form form = control.FindForm(); - // Assert - var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; - DataGridViewRowCollection rows = dataGridViewControl.Rows; - Assert.AreEqual(2, rows.Count); + // Assert + var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; + DataGridViewRowCollection rows = dataGridViewControl.Rows; + Assert.AreEqual(2, rows.Count); - DataGridViewCellCollection cells = rows[0].Cells; - Assert.AreEqual(4, cells.Count); - Assert.AreEqual("-", cells[mapLayerIdColumnIndex].FormattedValue); - Assert.AreEqual("image/png", cells[mapLayerFormatColumnIndex].FormattedValue); - Assert.AreEqual("-", cells[mapLayerTitleColumnIndex].FormattedValue); - Assert.AreEqual("-", cells[mapLayerCoordinateSystemColumnIndex].FormattedValue); + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("-", cells[mapLayerIdColumnIndex].FormattedValue); + Assert.AreEqual("image/png", cells[mapLayerFormatColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[mapLayerTitleColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[mapLayerCoordinateSystemColumnIndex].FormattedValue); - cells = rows[1].Cells; - Assert.AreEqual(4, cells.Count); - Assert.AreEqual("brtachtergrondkaart(EPSG:28992)", cells[mapLayerIdColumnIndex].FormattedValue); - Assert.AreEqual("image/png8", cells[mapLayerFormatColumnIndex].FormattedValue); - Assert.AreEqual("brtachtergrondkaart", cells[mapLayerTitleColumnIndex].FormattedValue); - Assert.AreEqual("EPSG:28992", cells[mapLayerCoordinateSystemColumnIndex].FormattedValue); + cells = rows[1].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("brtachtergrondkaart(EPSG:28992)", cells[mapLayerIdColumnIndex].FormattedValue); + Assert.AreEqual("image/png8", cells[mapLayerFormatColumnIndex].FormattedValue); + Assert.AreEqual("brtachtergrondkaart", cells[mapLayerTitleColumnIndex].FormattedValue); + Assert.AreEqual("EPSG:28992", cells[mapLayerCoordinateSystemColumnIndex].FormattedValue); + } } } @@ -212,16 +213,16 @@ public void GetSelectedMapData_WithSelectedComboBoxWithoutSelectedRow_ReturnsNull() { // Setup - SettingsHelper.Instance = new TestSettingsHelper + using (new UseCustomSettingsHelper(new TestSettingsHelper { ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - - // Call + })) using (WmtsLocationControl control = ShowFullyConfiguredWmtsLocationControl()) { - // Assert + // Call MapData selectedMapData = control.SelectedMapData; + + // Assert Assert.IsNull(selectedMapData); } } @@ -257,11 +258,10 @@ public void GetSelectedMapData_WithSelectedData_ReturnsSelectedMapData() { // Setup - SettingsHelper.Instance = new TestSettingsHelper + using (new UseCustomSettingsHelper(new TestSettingsHelper { ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - + })) using (WmtsLocationControl control = ShowFullyConfiguredWmtsLocationControl()) { Form form = control.FindForm(); @@ -287,32 +287,33 @@ public void GivenValidWmtsConnectionInfos_WhenConstructed_ThenExpectedProperties() { // Given - SettingsHelper.Instance = new TestSettingsHelper + using (new UseCustomSettingsHelper(new TestSettingsHelper { ExpectedApplicationVersion = "twoValidWmtsConnectionInfos", ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath) - }; - - // When - using (var control = new WmtsLocationControl()) - using (var form = new Form()) + })) { - form.Controls.Add(control); + // When + using (var control = new WmtsLocationControl()) + using (var form = new Form()) + { + form.Controls.Add(control); - // Then - var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; - var dataSource = (List) comboBox.DataSource; - Assert.AreEqual(2, dataSource.Count); + // Then + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(2, dataSource.Count); - var firstWmtsConnectionInfo = (WmtsConnectionInfo) comboBox.Items[0]; - Assert.AreEqual("Actueel Hoogtebestand Nederland (AHN1)", firstWmtsConnectionInfo.Name); - Assert.AreEqual("https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilities", - firstWmtsConnectionInfo.Url); + var firstWmtsConnectionInfo = (WmtsConnectionInfo) comboBox.Items[0]; + Assert.AreEqual("Actueel Hoogtebestand Nederland (AHN1)", firstWmtsConnectionInfo.Name); + Assert.AreEqual("https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilities", + firstWmtsConnectionInfo.Url); - var secondWmtsConnectionInfo = (WmtsConnectionInfo) comboBox.Items[1]; - Assert.AreEqual("Zeegraskartering", secondWmtsConnectionInfo.Name); - Assert.AreEqual("https://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilities", - secondWmtsConnectionInfo.Url); + var secondWmtsConnectionInfo = (WmtsConnectionInfo) comboBox.Items[1]; + Assert.AreEqual("Zeegraskartering", secondWmtsConnectionInfo.Name); + Assert.AreEqual("https://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilities", + secondWmtsConnectionInfo.Url); + } } } @@ -321,51 +322,51 @@ public void GivenInvalidWmtsConnectionInfos_WhenConstructed_ThenLogGenerated() { // Given - SettingsHelper.Instance = new TestSettingsHelper + using (new UseCustomSettingsHelper(new TestSettingsHelper { ExpectedApplicationVersion = "WmtsConnectionInfosWithoutWmtsConnectionsElement", ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath) - }; - - // When - Action action = () => + })) { - using (var control = new WmtsLocationControl()) - using (var form = new Form()) + // When + Action action = () => { - form.Controls.Add(control); + using (var control = new WmtsLocationControl()) + using (var form = new Form()) + { + form.Controls.Add(control); - // Then - var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; - var dataSource = (List) comboBox.DataSource; - Assert.AreEqual(0, dataSource.Count); - } - }; + // Then + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(0, dataSource.Count); + } + }; - string wmtsConnectionInfoConfig = Path.Combine(TestHelper.GetTestDataPath( - testPath, - "WmtsConnectionInfosWithoutWmtsConnectionsElement"), - "wmtsConnectionInfo.config"); - var expectedMessage = $"Fout bij het lezen van bestand '{wmtsConnectionInfoConfig}': " - + "het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie."; - TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(expectedMessage, LogLevelConstant.Error)); + string wmtsConnectionInfoConfig = Path.Combine(TestHelper.GetTestDataPath( + testPath, + "WmtsConnectionInfosWithoutWmtsConnectionsElement"), + "wmtsConnectionInfo.config"); + var expectedMessage = $"Fout bij het lezen van bestand '{wmtsConnectionInfoConfig}': " + + "het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie."; + TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(expectedMessage, LogLevelConstant.Error)); + } } [Test] [Apartment(ApartmentState.STA)] public void GivenWmtsLocationControlAndAddLocationClicked_WhenDialogCanceled_ThenWmtsLocationsNotUpdated() { // Given - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - DialogBoxHandler = (formName, wnd) => { using (new FormTester(formName)) {} }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) using (var form = new Form()) using (var control = new WmtsLocationControl()) { @@ -392,11 +393,6 @@ const string name = @"someName"; const string url = @"someUrl"; - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - var mockRepository = new MockRepository(); var tileFactory = mockRepository.StrictMock(); tileFactory.Expect(tf => tf.GetWmtsTileSources(url)).Return(Enumerable.Empty()); @@ -418,6 +414,10 @@ } }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) using (new FileDisposeHelper(Path.Combine(SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(), wmtsconnectioninfoConfigFile))) using (new UseCustomTileSourceFactoryConfig(tileFactory)) @@ -452,11 +452,6 @@ public void GivenWmtsLocationControlAndAddLocationClicked_WhenInValidDataInDialog_ThenWmtsLocationsNotUpdated() { // Given - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - DialogBoxHandler = (formName, wnd) => { using (var formTester = new FormTester(formName)) @@ -470,6 +465,10 @@ } }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) using (var form = new Form()) using (var control = new WmtsLocationControl()) { @@ -499,11 +498,6 @@ const string name = @"someName"; const string url = @"someUrl"; - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - var mockRepository = new MockRepository(); var tileFactory = mockRepository.StrictMock(); tileFactory.Expect(tf => tf.GetWmtsTileSources(url)).Return(Enumerable.Empty()); @@ -525,29 +519,36 @@ } }; - string configFilePath = Path.Combine(SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(), - wmtsconnectioninfoConfigFile); - using (var fileDisposeHelper = new FileDisposeHelper(configFilePath)) - using (new UseCustomTileSourceFactoryConfig(tileFactory)) - using (var form = new Form()) - using (var control = new WmtsLocationControl()) + using (new UseCustomSettingsHelper(new TestSettingsHelper { - form.Controls.Add(control); - form.Show(); + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) + { + string configFilePath = Path.Combine(SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(), + wmtsconnectioninfoConfigFile); - fileDisposeHelper.LockFiles(); + using (var fileDisposeHelper = new FileDisposeHelper(configFilePath)) + using (new UseCustomTileSourceFactoryConfig(tileFactory)) + using (var form = new Form()) + using (var control = new WmtsLocationControl()) + { + form.Controls.Add(control); + form.Show(); - var buttonAddLocation = new ButtonTester("addLocationButton", form); + fileDisposeHelper.LockFiles(); - // When - Action action = () => { buttonAddLocation.Click(); }; + var buttonAddLocation = new ButtonTester("addLocationButton", form); - // Then - string exceptionMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{configFilePath}'."; - TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(exceptionMessage, LogLevelConstant.Error)); - var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; - var dataSource = (List) comboBox.DataSource; - Assert.AreEqual(1, dataSource.Count); + // When + Action action = () => { buttonAddLocation.Click(); }; + + // Then + string exceptionMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{configFilePath}'."; + TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(exceptionMessage, LogLevelConstant.Error)); + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(1, dataSource.Count); + } } mockRepository.VerifyAll(); @@ -558,16 +559,15 @@ public void GivenWmtsLocationControlAndEditLocationClicked_WhenDialogCanceled_ThenWmtsLocationsNotUpdated() { // Given - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - DialogBoxHandler = (formName, wnd) => { using (new FormTester(formName)) {} }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) using (var form = new Form()) using (var control = new WmtsLocationControl()) { @@ -603,11 +603,6 @@ const string newName = @"newName"; const string newUrl = @"newUrl"; - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - var mockRepository = new MockRepository(); var tileFactory = mockRepository.StrictMock(); tileFactory.Expect(tf => tf.GetWmtsTileSources(newUrl)).Return(Enumerable.Empty()); @@ -629,6 +624,10 @@ } }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) using (new FileDisposeHelper(Path.Combine(SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(), wmtsconnectioninfoConfigFile))) using (new UseCustomTileSourceFactoryConfig(tileFactory)) @@ -666,11 +665,6 @@ public void GivenWmtsLocationControlAndEditLocationClicked_WhenInValidDataInDialog_ThenWmtsLocationsNotUpdated() { // Given - SettingsHelper.Instance = new TestSettingsHelper - { - ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") - }; - DialogBoxHandler = (formName, wnd) => { using (var formTester = new FormTester(formName)) @@ -688,6 +682,10 @@ } }; + using (new UseCustomSettingsHelper(new TestSettingsHelper + { + ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig") + })) using (var form = new Form()) using (var control = new WmtsLocationControl()) { Index: Core/Components/test/Core.Components.DotSpatial.TestUtil.Test/Core.Components.DotSpatial.TestUtil.Test.csproj =================================================================== diff -u -r6e93798b2be731889dadc6c50247ea16f4d13d9c -rf02614d781e389e05b9b481e8d165286e6baad4d --- Core/Components/test/Core.Components.DotSpatial.TestUtil.Test/Core.Components.DotSpatial.TestUtil.Test.csproj (.../Core.Components.DotSpatial.TestUtil.Test.csproj) (revision 6e93798b2be731889dadc6c50247ea16f4d13d9c) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil.Test/Core.Components.DotSpatial.TestUtil.Test.csproj (.../Core.Components.DotSpatial.TestUtil.Test.csproj) (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -72,6 +72,7 @@ + @@ -85,6 +86,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {30E4C2AE-719E-4D70-9FA9-668A9767FBFA} + Core.Common.Gui + {d749ee4c-ce50-4c17-bf01-9a953028c126} Core.Common.TestUtil Index: Core/Components/test/Core.Components.DotSpatial.TestUtil.Test/UseCustomSettingsHelperTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.TestUtil.Test/UseCustomSettingsHelperTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil.Test/UseCustomSettingsHelperTest.cs (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Core.Common.Gui.Settings; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Components.DotSpatial.TestUtil.Test +{ + [TestFixture] + public class UseCustomSettingsHelperTest + { + [Test] + public void GivenSettingsHelperInstance_WhenNewSettingsHelper_ThenSingletonInstanceTemporarilyChanged() + { + // Given + ISettingsHelper originalHelper = SettingsHelper.Instance; + + var mocks = new MockRepository(); + var helper = mocks.Stub(); + mocks.ReplayAll(); + + // When + using (new UseCustomSettingsHelper(helper)) + { + // Then + Assert.AreSame(helper, SettingsHelper.Instance); + } + Assert.AreSame(originalHelper, SettingsHelper.Instance); + mocks.VerifyAll(); + } + + [Test] + public void Dispose_AlreadyDisposed_DoesNotThrowException() + { + // Setup + var mocks = new MockRepository(); + var helper = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => + { + using (var control = new UseCustomSettingsHelper(helper)) + { + control.Dispose(); + } + }; + + // Assert + Assert.DoesNotThrow(call); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj =================================================================== diff -u -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 -rf02614d781e389e05b9b481e8d165286e6baad4d --- Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj (.../Core.Components.DotSpatial.TestUtil.csproj) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj (.../Core.Components.DotSpatial.TestUtil.csproj) (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -59,6 +59,7 @@ + @@ -67,6 +68,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {30E4C2AE-719E-4D70-9FA9-668A9767FBFA} + Core.Common.Gui + {aa47e858-a2a7-470e-8b2d-c76ae8ed9ccd} Core.Components.DotSpatial Index: Core/Components/test/Core.Components.DotSpatial.TestUtil/UseCustomSettingsHelper.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.TestUtil/UseCustomSettingsHelper.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil/UseCustomSettingsHelper.cs (revision f02614d781e389e05b9b481e8d165286e6baad4d) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Gui.Settings; + +namespace Core.Components.DotSpatial.TestUtil +{ + /// + /// Configures to temporarily use a different + /// instance. + /// + public sealed class UseCustomSettingsHelper : IDisposable + { + private readonly ISettingsHelper originalHelper; + private bool disposed; + + /// + /// Creates a new instance of . + /// + /// The temporary helper to be used. + public UseCustomSettingsHelper(ISettingsHelper settingsHelper) + { + originalHelper = SettingsHelper.Instance; + SettingsHelper.Instance = settingsHelper; + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + { + return; + } + + SettingsHelper.Instance = originalHelper; + disposed = true; + } + + ~UseCustomSettingsHelper() + { + Dispose(false); + } + } +} \ No newline at end of file