Exemplo n.º 1
0
        public async Task TestLoggingOffWhenLoggingOnWhenAlreadyLoggedOn()
        {
            int             wasLoggedOnCount    = 0;
            int             wasLoggedOffCount   = 0;
            SessionNotify   notificationMonitor = new SessionNotify();
            KnownIdentities knownIdentities     = new KnownIdentities(Resolve.FileSystemState, notificationMonitor);

            notificationMonitor.AddCommand((SessionNotification notification) =>
            {
                if (notification.NotificationType == SessionNotificationType.SignIn)
                {
                    Assert.That(knownIdentities.IsLoggedOn, Is.True, "The state of the IsLoggedOn property should be consistent with the event.");
                    ++wasLoggedOnCount;
                }
                if (notification.NotificationType == SessionNotificationType.SignOut)
                {
                    Assert.That(knownIdentities.IsLoggedOn, Is.False, "The state of the IsLoggedOn property should be consistent with the event.");
                    ++wasLoggedOffCount;
                }
                return(Constant.CompletedTask);
            });

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase1"));

            Assert.That(wasLoggedOnCount, Is.EqualTo(1));
            Assert.That(wasLoggedOffCount, Is.EqualTo(0));
            Assert.That(knownIdentities.IsLoggedOn, Is.True);

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase"));

            Assert.That(wasLoggedOnCount, Is.EqualTo(2));
            Assert.That(wasLoggedOffCount, Is.EqualTo(1));
            Assert.That(knownIdentities.IsLoggedOn, Is.True);
        }
Exemplo n.º 2
0
        public async Task TestExitEvent()
        {
            IDataStore dataStore             = New <IDataStore>(_helloWorldAxxPath);
            IEnumerable <LogOnIdentity> keys = new LogOnIdentity[] { new LogOnIdentity("a") };

            FakeLauncher launcher = new FakeLauncher();
            bool         called   = false;

            TypeMap.Register.New <ILauncher>(() => { called = true; launcher.WasStarted = true; return(launcher); });

            SessionNotify notificationMonitor = new SessionNotify();

            FileOperation        fileOperation = new FileOperation(Resolve.FileSystemState, notificationMonitor);
            FileOperationContext status        = await fileOperation.OpenAndLaunchApplication(keys, dataStore, new ProgressContext());

            Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Success), "The launch should succeed.");
            Assert.That(called, Is.True, "There should be a call to launch to try launching.");
            Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers.");

            bool changedWasRaised = false;

            notificationMonitor.AddCommand((SessionNotification notification) => { changedWasRaised = true; return(Constant.CompletedTask); });
            Assert.That(changedWasRaised, Is.False, "The global changed event should not have been raised yet.");

            launcher.RaiseExited();
            Assert.That(changedWasRaised, Is.True, "The global changed event should be raised when the process exits.");
        }
        public async Task TestChangedEvent()
        {
            bool wasHere = false;

            SessionNotify notificationMonitor = new SessionNotify();

            notificationMonitor.AddCommand((SessionNotification notification) => { wasHere = notification.NotificationType == SessionNotificationType.ActiveFileChange; return(Constant.CompletedTask); });
            await notificationMonitor.NotifyAsync(new SessionNotification(SessionNotificationType.ActiveFileChange));

            Assert.That(wasHere, Is.True, "The RaiseChanged() method should raise the event immediately.");
        }
Exemplo n.º 4
0
        public async Task TestChangedEventWhenAddingEmptyIdentity()
        {
            bool            wasChanged          = false;
            SessionNotify   notificationMonitor = new SessionNotify();
            KnownIdentities knownIdentities     = new KnownIdentities(Resolve.FileSystemState, notificationMonitor);

            notificationMonitor.AddCommand((SessionNotification notification) =>
            {
                wasChanged |= notification.NotificationType == SessionNotificationType.KnownKeyChange;
                return(Constant.CompletedTask);
            });
            LogOnIdentity key1 = new LogOnIdentity(String.Empty);
            await knownIdentities.AddAsync(key1);

            Assert.That(wasChanged, Is.False, "A new key should not trigger the Changed event.");
        }
Exemplo n.º 5
0
        public static async Task TestNotificationDuringProcessingOfNotification()
        {
            int notificationCount = 0;

            SessionNotify monitor = new SessionNotify();

            monitor.AddCommand((notification) =>
            {
                if (notification.NotificationType == SessionNotificationType.SignIn)
                {
                    ++notificationCount;
                }
                return(Constant.CompletedTask);
            });

            await monitor.NotifyAsync(new SessionNotification(SessionNotificationType.SignIn));

            Assert.That(notificationCount, Is.EqualTo(1));
        }
Exemplo n.º 6
0
        public IdentityViewModel(FileSystemState fileSystemState, KnownIdentities knownIdentities, UserSettings userSettings, SessionNotify sessionNotify)
        {
            _fileSystemState = fileSystemState;
            _knownIdentities = knownIdentities;
            _userSettings    = userSettings;
            _sessionNotify   = sessionNotify;

            LogOnIdentity = LogOnIdentity.Empty;

            LogOnAsync = new AsyncDelegateAction <object>(async(o) => { if (!_knownIdentities.IsLoggedOn)
                                                                        {
                                                                            LogOnIdentity = await LogOnActionAsync();
                                                                        }
                                                          });
            LogOff                  = new AsyncDelegateAction <object>(async(p) => { await LogOffAction(); LogOnIdentity = LogOnIdentity.Empty; }, (o) => Task.FromResult(_knownIdentities.IsLoggedOn));
            LogOnLogOff             = new AsyncDelegateAction <object>(async(o) => LogOnIdentity = await LogOnLogOffActionAsync());
            AskForDecryptPassphrase = new AsyncDelegateAction <string>(async(name) => LogOnIdentity = await AskForDecryptPassphraseActionAsync(name));
            AskForLogOnPassphrase   = new AsyncDelegateAction <LogOnIdentity>(async(id) => LogOnIdentity = await AskForLogOnPassphraseActionAsync(id, String.Empty));

            _sessionNotify.AddCommand(HandleLogOnLogOffNotifications);
        }
 private void SubscribeToModelEvents()
 {
     _sessionNotify.AddCommand(HandleKnownFolderAffectingEventsAsync);
 }
 private void SubscribeToModelEvents()
 {
     _sessionNotify.AddCommand(HandleSessionChanged);
 }