Beispiel #1
0
        public void TestExecuteWhenPathIsDirectotyAndDeleteWithoutConfirmation()
        {
            localFileSystemProviderMock
            .Setup(call => call.IsDirectory(@"c:\sql-backups"))
            .Returns(true);

            var files = new BakFileListFactory().WithDatabases("db1").Create(DateTime.Now, 2);

            localFileSystemProviderMock
            .Setup(call => call.GetFiles(@"c:\sql-backups", "*.bak"))
            .Returns(files);

            Mock <IPruneService>()
            .Setup(call => call.FlagPrunableBackupsInSet(It.IsAny <IEnumerable <BakModel> >()))
            .Callback <IEnumerable <BakModel> >((x) => x.First().Prunable = true);

            var result = command.Execute(new PruneCommand.Options {
                Path = @"c:\sql-backups", Delete = true, FileExtensions = "*.bak", NoConfirm = true
            });

            s3ProviderMock
            .Verify(call => call.IsDirectory(It.IsAny <string>()), Times.Never());

            localFileSystemProviderMock
            .Verify(call => call.Delete(It.IsAny <string>()), Times.Once());

            localFileSystemProviderMock
            .Verify(call => call.Delete(files.Keys.First()), Times.Once());

            Assert.AreEqual(0, result);
        }
Beispiel #2
0
        public void TestExecuteWhenPathIsDirectoryButSimulationOnlys()
        {
            localFileSystemProviderMock
            .Setup(call => call.IsDirectory(@"c:\sql-backups"))
            .Returns(true);

            var files = new BakFileListFactory().WithDatabases("db1").Create(DateTime.Now, 2);

            localFileSystemProviderMock
            .Setup(call => call.GetFiles(@"c:\sql-backups", "*.bak"))
            .Returns(files);

            var result = command.Execute(new PruneCommand.Options {
                Path = @"c:\sql-backups", FileExtensions = "*.bak"
            });

            s3ProviderMock
            .Verify(call => call.IsDirectory(It.IsAny <string>()), Times.Never());

            Mock <IPruneService>()
            .Verify(call => call.FlagPrunableBackupsInSet(It.Is <IEnumerable <BakModel> >(x => x.Count() == 2)),
                    Times.Once());

            localFileSystemProviderMock
            .Verify(call => call.Delete(It.IsAny <string>()), Times.Never());

            Assert.AreEqual(0, result);
        }
Beispiel #3
0
        /// <summary>
        /// Generates a backup set.
        /// </summary>
        /// <param name="from">Date to generate backups from.</param>
        /// <param name="howManyDays">The how many days to go in the past from the <see cref="from"/> date (must be a positive value).</param>
        /// <returns></returns>
        private static List <BakModel> GenerateBackupSet(DateTime from, int howManyDays)
        {
            var now = from;

            var paths = new BakFileListFactory().WithDatabases(new[] { "db1" })
                        .Create(now.AddDays(-howManyDays), now);

            return(InitaliseBackupSet(paths.Keys));
        }