Ejemplo n.º 1
0
        public void OriginalFilesModificationTest(string version, string fileName)
        {
            var mockIOProvider    = BackCompatTestProperties.GetModuleIOProvider(version, PowerRenameSettings.ModuleName, fileName);
            var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
            PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettings <PowerRenameLocalProperties>(PowerRenameSettings.ModuleName);

            var             mockGeneralIOProvider     = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
            var             mockGeneralSettingsUtils  = new SettingsUtils(mockGeneralIOProvider.Object);
            GeneralSettings originalGeneralSettings   = mockGeneralSettingsUtils.GetSettings <GeneralSettings>();
            var             generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository <GeneralSettings>(mockGeneralSettingsUtils);

            // Initialise View Model with test Config files
            Func <string, int>   SendMockIPCConfigMSG = msg => { return(0); };
            PowerRenameViewModel viewModel            = new PowerRenameViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG);

            // Verifiy that the old settings persisted
            Assert.AreEqual(originalGeneralSettings.Enabled.PowerRename, viewModel.IsEnabled);
            Assert.AreEqual(originalSettings.ExtendedContextMenuOnly, viewModel.EnabledOnContextExtendedMenu);
            Assert.AreEqual(originalSettings.MRUEnabled, viewModel.MRUEnabled);
            Assert.AreEqual(originalSettings.ShowIcon, viewModel.EnabledOnContextMenu);

            //Verify that the stub file was used
            var expectedCallCount = 2;  //once via the view model, and once by the test (GetSettings<T>)

            BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerRenameSettings.ModuleName, expectedCallCount);
            BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
        }
Ejemplo n.º 2
0
        public PowerRenameViewModel()
        {
            try
            {
                PowerRenameLocalProperties localSettings = SettingsUtils.GetSettings <PowerRenameLocalProperties>(ModuleName, "power-rename-settings.json");
                Settings = new PowerRenameSettings(localSettings);
            }
            catch
            {
                PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
                Settings = new PowerRenameSettings(localSettings);
                SettingsUtils.SaveSettings(localSettings.ToJsonString(), ModuleName, "power-rename-settings.json");
            }

            _powerRenameEnabledOnContextMenu         = Settings.Properties.ShowIcon.Value;
            _powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
            _powerRenameRestoreFlagsOnLaunch         = Settings.Properties.PersistState.Value;
            _powerRenameMaxDispListNumValue          = Settings.Properties.MaxMRUSize.Value;
            _autoComplete = Settings.Properties.MRUEnabled.Value;

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            _powerRenameEnabled = generalSettings.Enabled.PowerRename;
        }
Ejemplo n.º 3
0
        public PowerRenameViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;
            _settingsUtils            = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            try
            {
                PowerRenameLocalProperties localSettings = _settingsUtils.GetSettings <PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
                Settings = new PowerRenameSettings(localSettings);
            }
            catch
            {
                PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
                Settings = new PowerRenameSettings(localSettings);
                _settingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "power-rename-settings.json");
            }

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;

            _powerRenameEnabledOnContextMenu         = Settings.Properties.ShowIcon.Value;
            _powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
            _powerRenameRestoreFlagsOnLaunch         = Settings.Properties.PersistState.Value;
            _powerRenameMaxDispListNumValue          = Settings.Properties.MaxMRUSize.Value;
            _autoComplete       = Settings.Properties.MRUEnabled.Value;
            _powerRenameEnabled = GeneralSettingsConfig.Enabled.PowerRename;
        }
Ejemplo n.º 4
0
        public PowerRenameViewModel(Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // Update Settings file folder:
            SettingsConfigFileFolder = configFileSubfolder;

            try
            {
                PowerRenameLocalProperties localSettings = SettingsUtils.GetSettings <PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
                Settings = new PowerRenameSettings(localSettings);
            }
            catch
            {
                PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
                Settings = new PowerRenameSettings(localSettings);
                SettingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "power-rename-settings.json");
            }

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;

            _powerRenameEnabledOnContextMenu         = Settings.Properties.ShowIcon.Value;
            _powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
            _powerRenameRestoreFlagsOnLaunch         = Settings.Properties.PersistState.Value;
            _powerRenameMaxDispListNumValue          = Settings.Properties.MaxMRUSize.Value;
            _autoComplete = Settings.Properties.MRUEnabled.Value;

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            _powerRenameEnabled = generalSettings.Enabled.PowerRename;
        }