public void Clean_MatchingDaemonFoldersNotFound_NoError_NotDeleted() { // Arrange var fileSystemMock = new Mock <IFileSystem>(); var mockLogger = new Mock <ILogger>(); SetupDirectories(fileSystemMock, "c:\\", "aaa", "bbb"); // Mark the first directory as not existing fileSystemMock.Setup(x => x.Directory.Exists("c:\\aaa")).Returns(false); var cleaner = new LegacyInstallationCleanup( mockLogger.Object, "c:\\", fileSystemMock.Object); // Act cleaner.Clean(); // Assert AssertRenamedFolderDeleted(fileSystemMock, "c:\\bbb"); AssertDeleteCalledExpectedTimes(fileSystemMock, 1); }
public void Clean_ErrorDuringDelete_ErrorSuppressedAndOtherFoldersDeleted() { // Arrange var fileSystemMock = new Mock <IFileSystem>(); var mockLogger = new Mock <ILogger>(); SetupDirectories(fileSystemMock, "c:\\aaa\\rootfolder", "xxx", "yyy"); // Set up to throw when the first directory is deleted fileSystemMock .Setup(x => x.Directory.Delete(It.Is <string>(n => n.StartsWith("c:\\aaa\\rootfolder\\xxx")), true)) .Throws(new FileNotFoundException()); var cleaner = new LegacyInstallationCleanup( mockLogger.Object, "c:\\aaa\\rootfolder", fileSystemMock.Object); // Act cleaner.Clean(); // Assert AssertRenamedFolderDeleted(fileSystemMock, "c:\\aaa\\rootfolder\\xxx"); AssertRenamedFolderDeleted(fileSystemMock, "c:\\aaa\\rootfolder\\yyy"); AssertDeleteCalledExpectedTimes(fileSystemMock, 2); }
public void Clean_FolderDoesNotExist_NoError() { // Arrange // "Strict" mocks, so will throw if any methods on the mock are called // (we don't expect either the logger or directory wrapper to be used if // the legacy folder does not exist) var fileSystemMock = new Mock <IFileSystem>(MockBehavior.Strict); var mockLogger = new Mock <ILogger>(MockBehavior.Strict); fileSystemMock.Setup(x => x.Directory.GetDirectories(It.IsAny <string>(), It.IsAny <string>())).Returns(new string[] { }); var cleaner = new LegacyInstallationCleanup( mockLogger.Object, "c:\\dummy directory\\that does\\not\\exist", fileSystemMock.Object); // Act cleaner.Clean(); // Assert AssertDeleteCalledExpectedTimes(fileSystemMock, 0); }
public void Clean_MatchingDaemonFoldersExist_Deleted() { // Arrange var fileSystemMock = new Mock <IFileSystem>(); var mockLogger = new Mock <ILogger>(); SetupDirectories(fileSystemMock, "c:\\aaa\\rootfolder", "sonarlint-daemon-match1-windows", "sonarlint-daemon-2.17.0.899-windows"); var cleaner = new LegacyInstallationCleanup( mockLogger.Object, "c:\\aaa\\rootfolder", fileSystemMock.Object); // Act cleaner.Clean(); // Assert AssertRenamedFolderDeleted(fileSystemMock, "c:\\aaa\\rootfolder\\sonarlint-daemon-match1-windows"); AssertRenamedFolderDeleted(fileSystemMock, "c:\\aaa\\rootfolder\\sonarlint-daemon-2.17.0.899-windows"); AssertDeleteCalledExpectedTimes(fileSystemMock, 2); }