Esempio n. 1
0
        public void Save(ViewStateModel viewState)
        {
            var json = JsonConvert.SerializeObject(viewState);

            var fileInfo = new FileInfo(_fileLocation);

            if (fileInfo.Exists)
            {
                File.Delete(_fileLocation);
            }
            File.WriteAllText(_fileLocation, json);
        }
Esempio n. 2
0
        public ViewStateModel Open()
        {
            ViewStateModel value;
            var            fileInfo = new FileInfo(_fileLocation);

            if (fileInfo.Exists)
            {
                value = JsonConvert.DeserializeObject <ViewStateModel>(
                    File.ReadAllText(_fileLocation));
            }
            else
            {
                value = new ViewStateModel(
                    _fontColourLookupService.GetDefault(),
                    _fontFamilyLookupService.GetDefault(),
                    _fontZoomLookupService.GetDefault());
            }
            return(value);
        }
Esempio n. 3
0
        public void Init()
        {
            _fontZoomLookupService   = new FontZoomLookupService();
            _fontFamilyLookupService = new FontFamilyLookupService();
            _fontColourLookupService = new FontColourLookupService();

            var exampleViewStateModel = new ViewStateModel(
                _fontColourLookupService.GetDefault(),
                _fontFamilyLookupService.GetDefault(),
                _fontZoomLookupService.GetDefault());

            var mockViewStateService = new Mock <IViewStateService>();

            mockViewStateService.Setup(s => s.Open())
            .Returns(exampleViewStateModel);
            _viewStateService = mockViewStateService.Object;


            MockDialogService = new Mock <IDialogService>();
            MockDialogService.Setup(
                s => s.GetFileDialog <OpenFileDialog>())
            .Returns(It.IsAny <OpenFileDialog>());
            MockDialogService.Setup(
                s => s.GetFileDialog <SaveFileDialog>())
            .Returns(It.IsAny <SaveFileDialog>());


            var mockGoToVm = new Mock <IGoToDialogViewModel>();

            mockGoToVm.SetupGet(vm => vm.LineNumber)
            .Returns(DefaultLineToGoTo);

            MockDialogService.Setup(
                s => s.GetDialogViewModel <IGoToDialogViewModel>())
            .Returns(mockGoToVm.Object);

            var findVm = new FindDialogViewModel();

            MockDialogService.Setup(
                s => s.GetDialogViewModel <IFindDialogViewModel>())
            .Returns(findVm);


            var replaceVm = new ReplaceDialogViewModel();

            MockDialogService.Setup(
                s => s.GetDialogViewModel <IReplaceDialogViewModel>())
            .Returns(replaceVm);

            MockDialogService.Setup(
                s => s.ShowDialog(mockGoToVm.Object)).Returns(true);

            _dialogService = MockDialogService.Object;

            var mockFileModelService = new Mock <IFileModelService>();

            // TODO mock Load and Save
            _fileModelService = mockFileModelService.Object;

            MainVm = new MainViewModel(
                _dialogService,
                _viewStateService,
                _fontColourLookupService,
                _fontFamilyLookupService,
                _fontZoomLookupService,
                _fileModelService);

            MainVm.SelectedItem.Content = DefaultContent;

            MainVm.GoToRequested += OnGoToRequested;
        }