public void FindArchivialFilesToRestoreCommand_CanQueryByNetworkSource()
        {
            var mockedDb = new Mock <IClientDatabase>();

            SourceLocation dbSubmittedSource = null;
            int            dbSubmittedLimit  = 0;

            mockedDb.Setup(x => x.FindArchivialFilesToRestoreBySource(It.IsAny <SourceLocation>(), It.IsAny <int>()))
            .ReturnsAsync(new BackupFileSearchResults())
            .Callback <SourceLocation, int>((x, y) =>
            {
                dbSubmittedSource = x;
                dbSubmittedLimit  = y;
            });

            var mockedCoreSettings = new Mock <ICoreSettings>();

            var depedencies = new CmdletDependencies()
            {
                ClientDatabase = mockedDb.Object,
                CoreSettings   = mockedCoreSettings.Object
            };

            var command = new FindArchivialFilesToRestoreCommand(depedencies)
            {
                Source = new NetworkSourceLocation()
                {
                    ID = 5
                },
                LimitResults = 10
            };

            var result = command.Invoke().GetEnumerator().MoveNext();

            mockedDb.Verify(x => x.FindArchivialFilesToRestoreBySource(It.IsAny <SourceLocation>(), It.IsAny <int>()), Times.Once);

            Assert.IsNotNull(dbSubmittedSource);
            Assert.AreEqual(5, dbSubmittedSource.ID);
            Assert.AreEqual(10, dbSubmittedLimit);
        }
        public void FindArchivialFilesToRestoreCommand_CanQueryAllFiles()
        {
            var mockedDb = new Mock <IClientDatabase>();

            mockedDb.Setup(x => x.FindAllArchivialFilesToRestore()).ReturnsAsync(new BackupFileSearchResults());

            var mockedCoreSettings = new Mock <ICoreSettings>();

            var depedencies = new CmdletDependencies()
            {
                ClientDatabase = mockedDb.Object,
                CoreSettings   = mockedCoreSettings.Object
            };

            var command = new FindArchivialFilesToRestoreCommand(depedencies)
            {
                All = true
            };

            var result = command.Invoke().GetEnumerator().MoveNext();

            mockedDb.Verify(x => x.FindAllArchivialFilesToRestore(), Times.Once);
        }
        public void FindArchivialFilesToRestoreCommand_CanQueryByMatchFilter()
        {
            var mockedDb = new Mock <IClientDatabase>();

            string dbSubmittedMatch = null;
            int    dbSubmittedLimit = 0;

            mockedDb.Setup(x => x.FindArchivialFilesToRestoreByFilter(It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync(new BackupFileSearchResults())
            .Callback <string, int>((x, y) =>
            {
                dbSubmittedMatch = x;
                dbSubmittedLimit = y;
            });

            var mockedCoreSettings = new Mock <ICoreSettings>();

            var depedencies = new CmdletDependencies()
            {
                ClientDatabase = mockedDb.Object,
                CoreSettings   = mockedCoreSettings.Object
            };

            var command = new FindArchivialFilesToRestoreCommand(depedencies)
            {
                MatchFilter  = "*.docx",
                LimitResults = 10
            };

            var result = command.Invoke().GetEnumerator().MoveNext();

            mockedDb.Verify(x => x.FindArchivialFilesToRestoreByFilter(It.IsAny <string>(), It.IsAny <int>()), Times.Once);

            Assert.AreEqual(10, dbSubmittedLimit);
            Assert.AreEqual("\"*.docx\"", dbSubmittedMatch); // wrapped in quotes is expected for SQL full-text search support
        }