public async Task TestHandleSessionEvents(CryptoImplementation cryptoImplementation)
        {
            SetupAssembly.AssemblySetupCrypto(cryptoImplementation);

            MockAxCryptFile mock      = new MockAxCryptFile();
            int             callTimes = 0;

            mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) => { await Task.Delay(0); if (folderInfos.First().FullName == @"C:\My Documents\".NormalizeFilePath())
                                                                                                                                                                                           {
                                                                                                                                                                                               ++callTimes;
                                                                                                                                                                                           }
            };

            Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>();

            SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object);

            FakeDataStore.AddFolder(@"C:\My Documents");
            LogOnIdentity key = new LogOnIdentity("passphrase");
            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\My Documents", key.Tag));

            List <SessionNotification> sessionEvents = new List <SessionNotification>();

            sessionEvents.Add(new SessionNotification(SessionNotificationType.WatchedFolderAdded, new LogOnIdentity("passphrase1"), @"C:\My Documents\"));
            sessionEvents.Add(new SessionNotification(SessionNotificationType.WatchedFolderAdded, new LogOnIdentity("passphrase"), @"C:\My Documents\"));

            foreach (SessionNotification sessionEvent in sessionEvents)
            {
                await handler.HandleNotificationAsync(sessionEvent);
            }
            Assert.That(callTimes, Is.EqualTo(2));
        }
        public async Task TestHandleSessionEventLogOffWithWatchedFolders(CryptoImplementation cryptoImplementation)
        {
            SetupAssembly.AssemblySetupCrypto(cryptoImplementation);

            MockAxCryptFile mock   = new MockAxCryptFile();
            bool            called = false;

            mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) => { await Task.Delay(0); called = true; };

            Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>();

            await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase"));

            SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object);

            FakeDataStore.AddFolder(@"C:\WatchedFolder");
            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder", Resolve.KnownIdentities.DefaultEncryptionIdentity.Tag));

            called = false;
            await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.EncryptPendingFiles));

            await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.SignOut, Resolve.KnownIdentities.DefaultEncryptionIdentity));

            Assert.That(called, Is.True, nameof(AxCryptFile.EncryptFoldersUniqueWithBackupAndWipeAsync) + " should be called when a signing out.");
        }
        public async Task TestHandleSessionEventLogOn(CryptoImplementation cryptoImplementation)
        {
            SetupAssembly.AssemblySetupCrypto(cryptoImplementation);

            MockAxCryptFile mock        = new MockAxCryptFile();
            bool            called      = false;
            int             folderCount = -1;

            mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) =>
            {
                folderCount = folderInfos.Count();
                called      = true;
                await Task.Delay(0);
            };

            Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>();

            SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object);

            FakeDataStore.AddFolder(@"C:\WatchedFolder");
            LogOnIdentity key = new LogOnIdentity("passphrase");
            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder", key.Tag));

            await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.SignIn, key));

            Assert.That(called, Is.True);
            Assert.That(folderCount, Is.EqualTo(1), "There should be one folder passed for encryption as a result of the event.");
        }
        public async Task TestHandleSessionEventLogOffWithNoWatchedFolders()
        {
            MockAxCryptFile mock   = new MockAxCryptFile();
            bool            called = false;

            mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) => { await Task.Delay(0); called = true; };

            Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>();

            SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object);

            await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.SignOut, new LogOnIdentity("passphrase")));

            Assert.That(called, Is.False);
        }
        public async Task TestHandleSessionEventWatchedFolderRemoved()
        {
            FakeDataStore.AddFolder(@"C:\My Documents\");
            MockAxCryptFile       mock = new MockAxCryptFile();
            Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>();
            bool called = false;

            mock.DecryptFilesUniqueWithWipeOfOriginalMockAsync = (IDataContainer fileInfo, LogOnIdentity decryptionKey, IStatusChecker statusChecker, IProgressContext progress) => { called = fileInfo.FullName == @"C:\My Documents\".NormalizeFilePath(); };

            TypeMap.Register.New <AxCryptFile>(() => mock);

            SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object);

            await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.WatchedFolderRemoved, new LogOnIdentity("passphrase"), @"C:\My Documents\"));

            Assert.That(called, Is.True);
        }