Exemplo n.º 1
0
        public MainViewModelTests()
        {
            _mockedFileSystem = new MockFileSystem();

            var commonsMock = new Mock <ICommons>();

            commonsMock.SetupGet(x => x.CurrentLanguage).Returns(() => "English");
            commonsMock.SetupGet(x => x.CurrentLanguageCode).Returns(() => "eng");
            commonsMock.SetupGet(x => x.LanguageCodeMap).Returns(() => new Dictionary <string, string>());
            _mockedCommons = commonsMock.Object;

            var mockedLocalizationHelper = new Mock <ILocalizationHelper>();

            mockedLocalizationHelper.Setup(x => x.GetLocalization(It.IsAny <string>())).Returns <string>(x => x);
            mockedLocalizationHelper.Setup(x => x.GetLocalization(It.IsAny <string>(), It.IsAny <string>())).Returns((string value, string langauge) => value);
            _mockedLocalizationHelper = mockedLocalizationHelper.Object;

            Localization.Localization.Init(_mockedCommons);

            _mockedAppSettings = new Mock <IAppSettings>().Object;

            var annoCanvasMock = new Mock <IAnnoCanvas>();

            annoCanvasMock.SetupAllProperties();
            //The QuadTree does not have a default constructor, so we need to explicitly set up the property
            annoCanvasMock.Setup(x => x.PlacedObjects).Returns(new Core.DataStructures.QuadTree <LayoutObject>(new Rect(-100, -100, 200, 200)));
            _mockedAnnoCanvas = annoCanvasMock.Object;

            _inMemoryRecentFilesHelper = new RecentFilesHelper(new RecentFilesInMemorySerializer(), new MockFileSystem());

            _mockedMessageBoxService = new Mock <IMessageBoxService>().Object;
            _mockedUpdateHelper      = new Mock <IUpdateHelper>().Object;
            _mockedCellGrouper       = Mock.Of <IAdjacentCellGrouper>();
        }
Exemplo n.º 2
0
        public GeneralSettingsViewModel(IAppSettings appSettingsToUse, ICommons commonsToUse, IRecentFilesHelper recentFilesHelperToUse)
        {
            _appSettings = appSettingsToUse;
            _commons     = commonsToUse;
            _commons.SelectedLanguageChanged += Commons_SelectedLanguageChanged;
            _recentFilesHelper = recentFilesHelperToUse;

            UseZoomToPoint            = _appSettings.UseZoomToPoint;
            ZoomSensitivityPercentage = _appSettings.ZoomSensitivityPercentage;
            HideInfluenceOnSelection  = _appSettings.HideInfluenceOnSelection;
            ShowScrollbars            = _appSettings.ShowScrollbars;
            InvertPanningDirection    = _appSettings.InvertPanningDirection;
            InvertScrollingDirection  = _appSettings.InvertScrollingDirection;
            MaxRecentFiles            = _appSettings.MaxRecentFiles;

            ResetZoomSensitivityCommand = new RelayCommand(ExecuteResetZoomSensitivity, CanExecuteResetZoomSensitivity);
            ResetMaxRecentFilesCommand  = new RelayCommand(ExecuteResetMaxRecentFiles, CanExecuteResetMaxRecentFiles);
            ClearRecentFilesCommand     = new RelayCommand(ExecuteClearRecentFiles, CanExecuteClearRecentFiles);

            GridLineColors = new ObservableCollection <UserDefinedColor>();
            RefreshGridLineColors();
            var savedGridLineColor = SerializationHelper.LoadFromJsonString <UserDefinedColor>(_appSettings.ColorGridLines);

            if (savedGridLineColor is null)
            {
                SelectedGridLineColor       = GridLineColors.First();
                SelectedCustomGridLineColor = SelectedGridLineColor.Color;
            }
            else
            {
                SelectedGridLineColor       = GridLineColors.SingleOrDefault(x => x.Type == savedGridLineColor.Type);
                SelectedCustomGridLineColor = savedGridLineColor.Color;
            }

            ObjectBorderLineColors = new ObservableCollection <UserDefinedColor>();
            RefreshObjectBorderLineColors();
            var savedObjectBorderLineColor = SerializationHelper.LoadFromJsonString <UserDefinedColor>(_appSettings.ColorObjectBorderLines);

            if (savedObjectBorderLineColor is null)
            {
                SelectedObjectBorderLineColor       = ObjectBorderLineColors.First();
                SelectedCustomObjectBorderLineColor = SelectedObjectBorderLineColor.Color;
            }
            else
            {
                SelectedObjectBorderLineColor       = ObjectBorderLineColors.SingleOrDefault(x => x.Type == savedObjectBorderLineColor.Type);
                SelectedCustomObjectBorderLineColor = savedObjectBorderLineColor.Color;
            }
        }
Exemplo n.º 3
0
 private MainViewModel GetViewModel(ICommons commonsToUse                       = null,
                                    IAppSettings appSettingsToUse               = null,
                                    IRecentFilesHelper recentFilesHelperToUse   = null,
                                    IMessageBoxService messageBoxServiceToUse   = null,
                                    IUpdateHelper updateHelperToUse             = null,
                                    ILocalizationHelper localizationHelperToUse = null,
                                    IAnnoCanvas annoCanvasToUse                 = null,
                                    IFileSystem fileSystemToUse                 = null)
 {
     return(new MainViewModel(commonsToUse ?? _mockedCommons,
                              appSettingsToUse ?? _mockedAppSettings,
                              recentFilesHelperToUse ?? _inMemoryRecentFilesHelper,
                              messageBoxServiceToUse ?? _mockedMessageBoxService,
                              updateHelperToUse ?? _mockedUpdateHelper,
                              localizationHelperToUse ?? _mockedLocalizationHelper,
                              fileSystemToUse ?? _mockedFileSystem)
     {
         AnnoCanvas = annoCanvasToUse ?? _mockedAnnoCanvas
     });
 }