public void LoadSettingsCreatesDefaultIfNoFileFound() { Mock <IXmlFileService> fileService = new Mock <IXmlFileService>(); fileService. Setup(m => m.Exists(It.IsAny <string>())). Returns(false); RepositoryStorageServiceBase service = new TestableService(fileService.Object); RepositoryStorageLoadResult result = service.LoadRepositoryOrDefault(out NoteRepositoryModel repository); // Created new settings and stored it Assert.AreEqual(RepositoryStorageLoadResult.CreatedNewEmptyRepository, result); Assert.IsNotNull(repository); fileService.Verify(m => m.TrySerializeAndSave(It.IsAny <string>(), It.IsAny <NoteRepositoryModel>()), Times.Once); }
public void Version1ConfigWillBeUpdated() { XDocument xml = XDocument.Parse(Version1Repository); Mock <IXmlFileService> fileService = new Mock <IXmlFileService>(); fileService. Setup(m => m.TryLoad(It.IsAny <string>(), out xml)). Returns(true); fileService. Setup(m => m.Exists(It.IsAny <string>())). Returns(true); RepositoryStorageServiceBase service = new TestableService(fileService.Object); RepositoryStorageLoadResult result = service.LoadRepositoryOrDefault(out NoteRepositoryModel repository); Assert.AreEqual(RepositoryStorageLoadResult.SuccessfullyLoaded, result); Assert.IsNotNull(repository); Assert.AreEqual(NoteRepositoryModel.NewestSupportedRevision, repository.Revision); fileService.Verify(m => m.TrySerializeAndSave(It.IsAny <string>(), It.IsAny <NoteRepositoryModel>()), Times.Once); }
public void DoesNotOverwriteIvalidRepository() { XDocument xml = new XDocument(new XElement("Invalid")); Mock <IXmlFileService> fileService = new Mock <IXmlFileService>(); fileService. Setup(m => m.TryLoad(It.IsAny <string>(), out xml)). Returns(true); fileService. Setup(m => m.Exists(It.IsAny <string>())). Returns(true); RepositoryStorageServiceBase service = new TestableService(fileService.Object); RepositoryStorageLoadResult result = service.LoadRepositoryOrDefault(out NoteRepositoryModel repository); // Loaded existing settings and did not store it Assert.AreEqual(RepositoryStorageLoadResult.InvalidRepository, result, "Please remove DEMO from Directory.Build.props and run again"); Assert.IsNull(repository); fileService.Verify(m => m.TrySerializeAndSave(It.IsAny <string>(), It.IsAny <NoteRepositoryModel>()), Times.Never); }
public void LoadsSettingsReturnsStoredSettings() { NoteRepositoryModel storedSettings = new NoteRepositoryModel { Id = new Guid(), Revision = NoteRepositoryModel.NewestSupportedRevision }; XDocument xml = XmlUtils.SerializeToXmlDocument(storedSettings); Mock <IXmlFileService> fileService = new Mock <IXmlFileService>(); fileService. Setup(m => m.TryLoad(It.IsAny <string>(), out xml)). Returns(true); fileService. Setup(m => m.Exists(It.IsAny <string>())). Returns(true); RepositoryStorageServiceBase service = new TestableService(fileService.Object); RepositoryStorageLoadResult result = service.LoadRepositoryOrDefault(out NoteRepositoryModel repository); // Loaded existing settings and did not store it Assert.AreEqual(RepositoryStorageLoadResult.SuccessfullyLoaded, result); Assert.IsNotNull(repository); Assert.AreEqual(storedSettings.Id, repository.Id); fileService.Verify(m => m.TrySerializeAndSave(It.IsAny <string>(), It.IsAny <NoteRepositoryModel>()), Times.Never); }
/// <inheritdoc/> public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom) { base.ShowInView(htmlView, variables, redirectedFrom); IRepositoryStorageService repositoryService = Ioc.GetOrCreate <IRepositoryStorageService>(); _scrollToNote = variables?.GetValueOrDefault(ControllerParameters.NoteId); RepositoryStorageLoadResult loadResult = repositoryService.LoadRepositoryOrDefault(out _); if (loadResult != RepositoryStorageLoadResult.InvalidRepository) { _viewModel = new NoteRepositoryViewModel( Ioc.GetOrCreate <INavigationService>(), Ioc.GetOrCreate <ILanguageService>(), Ioc.GetOrCreate <ISvgIconService>(), Ioc.GetOrCreate <IThemeService>(), Ioc.GetOrCreate <IBaseUrlService>(), Ioc.GetOrCreate <IStoryBoardService>(), Ioc.GetOrCreate <IFeedbackService>(), Ioc.GetOrCreate <ISettingsService>(), Ioc.GetOrCreate <IEnvironmentService>(), Ioc.GetOrCreate <ICryptoRandomService>(), repositoryService); VueBindingShortcut[] shortcuts = new[] { new VueBindingShortcut("s", nameof(_viewModel.SynchronizeCommand)) { Ctrl = true }, new VueBindingShortcut("n", nameof(_viewModel.NewNoteCommand)) { Ctrl = true }, new VueBindingShortcut("l", nameof(_viewModel.NewChecklistCommand)) { Ctrl = true }, new VueBindingShortcut("r", nameof(_viewModel.ShowRecycleBinCommand)) { Ctrl = true }, new VueBindingShortcut("i", nameof(_viewModel.ShowInfoCommand)) { Ctrl = true }, new VueBindingShortcut(VueBindingShortcut.KeyHome, "ScrollToTop") { Ctrl = true }, new VueBindingShortcut(VueBindingShortcut.KeyEnd, "ScrollToBottom") { Ctrl = true }, }; VueBindings = new VueDataBinding(_viewModel, View, shortcuts); VueBindings.DeclareAdditionalVueMethod("ScrollToTop", "scrollToTop();"); VueBindings.DeclareAdditionalVueMethod("ScrollToBottom", "scrollToBottom();"); _viewModel.VueDataBindingScript = VueBindings.BuildVueScript(); VueBindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler; VueBindings.ViewLoadedEvent += ViewLoadedEventHandler; VueBindings.StartListening(); _viewModel.PropertyChanged += ViewmodelPropertyChangedEventHandler; string html = _viewService.GenerateHtml(_viewModel); View.LoadHtml(html); } else { // Show error message and stop loading the application _stopViewModel = new StopViewModel( Ioc.GetOrCreate <INavigationService>(), Ioc.GetOrCreate <ILanguageService>(), Ioc.GetOrCreate <ISvgIconService>(), Ioc.GetOrCreate <IThemeService>(), Ioc.GetOrCreate <IBaseUrlService>()); string html = _viewStop.GenerateHtml(_stopViewModel); View.LoadHtml(html); } }
/// <inheritdoc/> public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom) { base.ShowInView(htmlView, variables, redirectedFrom); View.NavigationCompleted += NavigationCompletedEventHandler; IRepositoryStorageService repositoryService = Ioc.GetOrCreate <IRepositoryStorageService>(); _scrollToNote = variables?.GetValueOrDefault(ControllerParameters.NoteId); RepositoryStorageLoadResult loadResult = repositoryService.LoadRepositoryOrDefault(out _); if (loadResult != RepositoryStorageLoadResult.InvalidRepository) { _viewModel = new NoteRepositoryViewModel( Ioc.GetOrCreate <INavigationService>(), Ioc.GetOrCreate <ILanguageService>(), Ioc.GetOrCreate <ISvgIconService>(), Ioc.GetOrCreate <IThemeService>(), Ioc.GetOrCreate <IBaseUrlService>(), Ioc.GetOrCreate <IStoryBoardService>(), Ioc.GetOrCreate <IFeedbackService>(), Ioc.GetOrCreate <ISettingsService>(), Ioc.GetOrCreate <IEnvironmentService>(), Ioc.GetOrCreate <ICryptoRandomService>(), repositoryService); Bindings.BindCommand("NewNote", _viewModel.NewNoteCommand); Bindings.BindCommand("NewChecklist", _viewModel.NewChecklistCommand); Bindings.BindCommand("Synchronize", _viewModel.SynchronizeCommand); Bindings.BindCommand("ShowTransferCode", _viewModel.ShowTransferCodeCommand); Bindings.BindCommand("ShowRecycleBin", _viewModel.ShowRecycleBinCommand); Bindings.BindCommand("ShowSettings", _viewModel.ShowSettingsCommand); Bindings.BindCommand("ShowInfo", _viewModel.ShowInfoCommand); Bindings.BindCommand("OpenSafe", _viewModel.OpenSafeCommand); Bindings.BindCommand("CloseSafe", _viewModel.CloseSafeCommand); Bindings.BindCommand("ChangeSafePassword", _viewModel.ChangeSafePasswordCommand); Bindings.BindCommand("FilterButtonCancel", _viewModel.ClearFilterCommand); Bindings.BindText("TxtFilter", () => _viewModel.Filter, (value) => _viewModel.Filter = value, _viewModel, nameof(_viewModel.Filter), HtmlViewBindingMode.TwoWay); Bindings.BindVisibility("FilterButtonMagnifier", () => string.IsNullOrEmpty(_viewModel.Filter), _viewModel, nameof(_viewModel.FilterButtonMagnifierVisible), HtmlViewBindingMode.OneWayToView); Bindings.BindVisibility("FilterButtonCancel", () => !string.IsNullOrEmpty(_viewModel.Filter), _viewModel, nameof(_viewModel.FilterButtonCancelVisible), HtmlViewBindingMode.OneWayToView); Bindings.BindGeneric <object>( NotesChangedEventHandler, null, null, null, new HtmlViewBindingViewmodelNotifier(_viewModel, "Notes"), HtmlViewBindingMode.OneWayToView); Bindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler; // Load html page and content (notes) string html = _viewService.GenerateHtml(_viewModel); string htmlNotes = _viewContentService.GenerateHtml(_viewModel); html = html.Replace("<ul id=\"note-repository\"></ul>", htmlNotes); // Replace node "note-repository" with content View.LoadHtml(html); } else { // Show error message and stop loading the application _stopViewModel = new StopViewModel( Ioc.GetOrCreate <INavigationService>(), Ioc.GetOrCreate <ILanguageService>(), Ioc.GetOrCreate <ISvgIconService>(), Ioc.GetOrCreate <IThemeService>(), Ioc.GetOrCreate <IBaseUrlService>()); string html = _viewStop.GenerateHtml(_stopViewModel); View.LoadHtml(html); } }