// 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 BruTile.Cache; using NUnit.Framework; namespace Core.Components.BruTile.Test { [TestFixture] public class FileCacheManagerTest { [Test] public void Instance_Always_ReturnSameInstance() { // Setup FileCacheManager manager1 = FileCacheManager.Instance; // Call FileCacheManager manager2 = FileCacheManager.Instance; // Assert Assert.AreSame(manager1, manager2); } [Test] public void GetFileCache_PathNull_ThrowArgumentNullException() { // Call TestDelegate test = () => FileCacheManager.Instance.GetfileChache(null); // Assert var exception = Assert.Throws(test); Assert.AreEqual("cacheDirectoryPath", exception.ParamName); } [Test] public void GetfileCache_FileCacheNotRegistered_ReturnNewFileCache() { // Setup const string path = nameof(GetfileCache_FileCacheNotRegistered_ReturnNewFileCache); // Call FileCache fileCache = FileCacheManager.Instance.GetfileChache(path); // Assert Assert.IsNotNull(fileCache); } [Test] public void GetFileCache_FileCacheAlreadyRegistered_ReturnSameFileCache() { // Setup const string path = nameof(GetFileCache_FileCacheAlreadyRegistered_ReturnSameFileCache); FileCacheManager manager = FileCacheManager.Instance; FileCache fileCache1 = manager.GetfileChache(path); // Call FileCache fileCache2 = manager.GetfileChache(path); // Assert Assert.AreSame(fileCache1, fileCache2); } [Test] public void UnsubscribeFileCache_FileCacheNull_ThrowArgumentNullException() { // Call TestDelegate test = () => FileCacheManager.Instance.UnsubscribeFileCache(null); // Assert var exception = Assert.Throws(test); Assert.AreEqual("fileCache", exception.ParamName); } [Test] public void GivenFileCache_WhenUnsubscribingButFileCacheStillUsed_ThenFileCacheNotDisposed() { // Given const string path = nameof(GivenFileCache_WhenUnsubscribingButFileCacheStillUsed_ThenFileCacheNotDisposed); FileCacheManager manager = FileCacheManager.Instance; FileCache fileCache1 = manager.GetfileChache(path); FileCache fileCache2 = manager.GetfileChache(path); // When manager.UnsubscribeFileCache(fileCache1); FileCache fileCache3 = manager.GetfileChache(path); // Then Assert.AreSame(fileCache2, fileCache3); } [Test] public void GivenFileCache_WhenUnsubscribingAndFileCacheNotUsed_ThenFileCacheDisposed() { // Given const string path = nameof(GivenFileCache_WhenUnsubscribingAndFileCacheNotUsed_ThenFileCacheDisposed); FileCacheManager manager = FileCacheManager.Instance; FileCache fileCache1 = manager.GetfileChache(path); // When manager.UnsubscribeFileCache(fileCache1); FileCache fileCache2 = manager.GetfileChache(path); // Then Assert.AreNotSame(fileCache1, fileCache2); } } }