public async Task TestRemoveNonexistingFromShared()
        {
            IAsymmetricPublicKey key1           = New <IAsymmetricFactory>().CreatePublicKey(Resources.PublicKey1);
            UserPublicKey        userPublicKey1 = new UserPublicKey(EmailAddress.Parse("*****@*****.**"), key1);

            IAsymmetricPublicKey key2           = New <IAsymmetricFactory>().CreatePublicKey(Resources.PublicKey2);
            UserPublicKey        userPublicKey2 = new UserPublicKey(EmailAddress.Parse("*****@*****.**"), key2);

            using (KnownPublicKeys knownPublicKeys = New <KnownPublicKeys>())
            {
                knownPublicKeys.AddOrReplace(userPublicKey1);
                knownPublicKeys.AddOrReplace(userPublicKey2);
            }

            SharingListViewModel model = await SharingListViewModel.CreateForFilesAsync(new string[0], LogOnIdentity.Empty);

            Assert.That(model.SharedWith.Any(), Is.False, "There are no known public keys, and none are set as shared.");
            Assert.That(model.NotSharedWith.Count(), Is.EqualTo(2), "There are two known public keys, so they should be available as unshared.");

            await model.AddKeyShares.ExecuteAsync(new[] { userPublicKey1.Email, });

            Assert.That(model.SharedWith.Count(), Is.EqualTo(1), "One was set as shared, so there should be one here now.");
            Assert.That(model.NotSharedWith.Count(), Is.EqualTo(1), "One unshared was set as shared, so there should be one here now.");

            await model.RemoveKeyShares.ExecuteAsync(new[] { userPublicKey2, });

            Assert.That(model.SharedWith.Count(), Is.EqualTo(1), "A key that was not set as shared was attempted to remove, nothing should happen.");
            Assert.That(model.NotSharedWith.Count(), Is.EqualTo(1), "A key that was not set as shared was attempted to remove, nothing should happen.");
        }
Ejemplo n.º 2
0
        public KeyShareDialog(Form parent, SharingListViewModel viewModel)
            : this()
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            InitializeStyle(parent);

            _viewModel = viewModel;
            _viewModel.BindPropertyChanged <IEnumerable <UserPublicKey> >(nameof(SharingListViewModel.SharedWith), (aks) => { _sharedWith.Items.Clear(); _sharedWith.Items.AddRange(aks.Distinct(UserPublicKey.EmailComparer).ToArray()); SetNotSharedWithActionButtonsState(); });
            _viewModel.BindPropertyChanged <IEnumerable <UserPublicKey> >(nameof(SharingListViewModel.NotSharedWith), (aks) => { _notSharedWith.Items.Clear(); aks = FilterNotSharedContactsByCapability(aks); _notSharedWith.Items.AddRange(aks.ToArray()); SetNotSharedWithActionButtonsState(); });
            _viewModel.BindPropertyChanged <string>(nameof(SharingListViewModel.NewKeyShare), (email) => SetNotSharedWithActionButtonsState());
            _viewModel.BindPropertyChanged <bool>(nameof(SharingListViewModel.IsOnline), (isOnline) => { SetNewContactState(isOnline); });

            _sharedWith.SelectedIndexChanged    += (sender, e) => SetUnshareButtonState();
            _notSharedWith.SelectedIndexChanged += (sender, e) => SetNotSharedWithActionButtonsState();

            _sharedWith.MouseDoubleClick += async(sender, e) => await Unshare(_sharedWith.IndexFromPoint(e.Location));

            _notSharedWith.MouseDoubleClick += async(sender, e) =>
            {
                await ShareSelectedIndices(new int[] { _notSharedWith.IndexFromPoint(e.Location) });
            };

            _newContact.TextChanged += (sender, e) => { _viewModel.NewKeyShare = _newContact.Text.Trim(); ClearErrorProviders(); };
            _newContact.Enter       += (sender, e) => { _sharedWith.ClearSelected(); _notSharedWith.ClearSelected(); };

            _shareButton.Click += async(sender, e) =>
            {
                await ShareSelectedIndices(_notSharedWith.SelectedIndices.Cast <int>());

                AccountStatus accountStatus = await ShareNewContactAsync();

                if (accountStatus == AccountStatus.Unverified)
                {
                    await DisplayInviteMessageAsync(_viewModel.NewKeyShare);
                }
                if (accountStatus != AccountStatus.Unknown)
                {
                    _newContact.Text = string.Empty;
                }
            };
            _unshareButton.Click += async(sender, e) =>
            {
                await Unshare();

                SetUnshareButtonState();
            };

            _removeKnownContactButton.Click += async(sender, e) =>
            {
                await RemoveKnownContact();
            };

            SetOkButtonState();
            _notSharedWith.Focus();
        }
        public async Task TestInitialEmptyState()
        {
            using (KnownPublicKeys knownPublicKeys = New <KnownPublicKeys>())
            {
            }
            SharingListViewModel model = await SharingListViewModel.CreateForFilesAsync(new string[0], LogOnIdentity.Empty);

            Assert.That(model.SharedWith.Any(), Is.False, "There are no known public keys, and none are set as shared.");
            Assert.That(model.NotSharedWith.Any(), Is.False, "There are no known public kyes, so none can be unshared either.");
        }
        public async Task TestInitialOneKeyState()
        {
            IAsymmetricPublicKey key           = New <IAsymmetricFactory>().CreatePublicKey(Resources.PublicKey1);
            UserPublicKey        userPublicKey = new UserPublicKey(EmailAddress.Parse("*****@*****.**"), key);

            using (KnownPublicKeys knownPublicKeys = New <KnownPublicKeys>())
            {
                knownPublicKeys.AddOrReplace(userPublicKey);
            }

            SharingListViewModel model = await SharingListViewModel.CreateForFilesAsync(new string[0], LogOnIdentity.Empty);

            Assert.That(model.SharedWith.Any(), Is.False, "There are no known public keys, and none are set as shared.");
            Assert.That(model.NotSharedWith.Count(), Is.EqualTo(1), "There is one known public key, so this should be available as unshared.");
        }
        public async Task TestMoveTwoFromUnsharedToShared()
        {
            IAsymmetricPublicKey key1           = New <IAsymmetricFactory>().CreatePublicKey(Resources.PublicKey1);
            UserPublicKey        userPublicKey1 = new UserPublicKey(EmailAddress.Parse("*****@*****.**"), key1);

            IAsymmetricPublicKey key2           = New <IAsymmetricFactory>().CreatePublicKey(Resources.PublicKey2);
            UserPublicKey        userPublicKey2 = new UserPublicKey(EmailAddress.Parse("*****@*****.**"), key2);

            using (KnownPublicKeys knownPublicKeys = New <KnownPublicKeys>())
            {
                knownPublicKeys.AddOrReplace(userPublicKey1);
                knownPublicKeys.AddOrReplace(userPublicKey2);
            }

            SharingListViewModel model = await SharingListViewModel.CreateForFilesAsync(new string[0], LogOnIdentity.Empty);

            Assert.That(model.SharedWith.Any(), Is.False, "There are no known public keys, and none are set as shared.");
            Assert.That(model.NotSharedWith.Count(), Is.EqualTo(2), "There are two known public keys, so they should be available as unshared.");

            await model.AddKeyShares.ExecuteAsync(new[] { userPublicKey2.Email, userPublicKey1.Email, });

            Assert.That(model.SharedWith.Count(), Is.EqualTo(2), "Two were set as shared, so there should be two here now.");
            Assert.That(model.NotSharedWith.Count(), Is.EqualTo(0), "Both unshared were set as shared, so there should be none here now.");
        }