예제 #1
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new OpenSafeViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICryptoRandomService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IRepositoryStorageService>(),
                RedirectedFrom);

            Bindings.BindCommand("GoBack", _viewModel.GoBackCommand);
            Bindings.BindCommand("OkCommand", _viewModel.OkCommand);
            Bindings.BindCommand("CancelCommand", _viewModel.CancelCommand);
            Bindings.BindCommand("ResetSafeCommand", _viewModel.ResetSafeCommand);
            Bindings.BindText("Password", null, (v) => _viewModel.Password = SecureStringExtensions.StringToSecureString(v), null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindText("PasswordConfirmation", null, (v) => _viewModel.PasswordConfirmation = SecureStringExtensions.StringToSecureString(v), null, null, HtmlViewBindingMode.OneWayToViewmodel);
            Bindings.BindInvalid("Password", () => _viewModel.InvalidPasswordError, _viewModel, nameof(_viewModel.InvalidPasswordError), HtmlViewBindingMode.OneWayToView);
            Bindings.BindInvalid("PasswordConfirmation", () => _viewModel.InvalidPasswordConfirmationError, _viewModel, nameof(_viewModel.InvalidPasswordConfirmationError), HtmlViewBindingMode.OneWayToView);

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new OpenSafeViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICryptoRandomService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IRepositoryStorageService>(),
                RedirectedFrom);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(OpenSafeViewModel.GoBackCommand)),
                new VueBindingShortcut(VueBindingShortcut.KeyEnter, nameof(OpenSafeViewModel.OkCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
예제 #3
0
        public void ResetSafeRemovesNotesAndSafes()
        {
            Guid note1Id = new Guid("10000000000000000000000000000000");
            Guid note2Id = new Guid("20000000000000000000000000000000");
            Guid safeAId = new Guid("A0000000000000000000000000000000");
            Guid safeBId = new Guid("B0000000000000000000000000000000");
            NoteRepositoryModel repository = new NoteRepositoryModel();

            repository.Notes.Add(new NoteModel {
                Id = note1Id, SafeId = safeAId
            });                                                                     // locked, should be deleted
            repository.Notes.Add(new NoteModel {
                Id = note2Id, SafeId = null
            });                                                                  // unlocked, should be kept
            repository.Safes.Add(new SafeModel {
                Id = safeAId
            });
            repository.Safes.Add(new SafeModel {
                Id = safeBId
            });

            Mock <INavigationService>        navigationService        = new Mock <INavigationService>();
            Mock <IRepositoryStorageService> repositoryStorageService = new Mock <IRepositoryStorageService>();

            repositoryStorageService.
            Setup(m => m.LoadRepositoryOrDefault(out repository));
            Mock <IFeedbackService> feedbackService = new Mock <IFeedbackService>();

            feedbackService.
            Setup(m => m.ShowMessageAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <bool>()))
            .ReturnsAsync(MessageBoxResult.Continue);

            OpenSafeViewModel viewModel = new OpenSafeViewModel(
                navigationService.Object,
                CommonMocksAndStubs.LanguageService(),
                new Mock <ISvgIconService>().Object,
                new Mock <IThemeService>().Object,
                new Mock <IBaseUrlService>().Object,
                feedbackService.Object,
                CommonMocksAndStubs.CryptoRandomService(),
                new Mock <ISettingsService>().Object,
                repositoryStorageService.Object,
                null);

            viewModel.ResetSafeCommand.Execute(null);

            // Note is deleted and added to the deleted list
            Assert.AreEqual(1, repository.Notes.Count);
            Assert.AreEqual(note2Id, repository.Notes[0].Id);
            Assert.AreEqual(1, repository.DeletedNotes.Count);
            Assert.AreEqual(note1Id, repository.DeletedNotes[0]);

            // Safes are removed
            Assert.AreEqual(0, repository.Safes.Count);

            // Is marked as modified and navigated away, so it will be stored.
            Assert.IsTrue(viewModel.Modified);
            navigationService.Verify(m => m.Navigate(It.Is <Navigation>(v => v.ControllerId == ControllerNames.OpenSafe)));
            feedbackService.Verify(m => m.ShowMessageAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.Is <bool>(v => v == true)), Times.Once);
        }