public static Mock <IFile> GetModuleIOProvider(string version, string module, string fileName) { var stubSettingsPath = StubSettingsPath(version, module, fileName); Expression <Func <string, bool> > filterExpression = ModuleFilterExpression(module); return(IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression)); }
public static Mock <IIOProvider> GetGeneralSettingsIOProvider(string version) { var stubGeneralSettingsPath = string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, string.Empty, "settings.json"); Expression <Func <string, bool> > filterExpression = (string s) => s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal); var mockGeneralIOProvider = IIOProviderMocks.GetMockIOReadWithStubFile(stubGeneralSettingsPath, filterExpression); return(mockGeneralIOProvider); }
public static Mock <IIOProvider> GetModuleIOProvider(string version, string module, string fileName) { var stubSettingsPath = string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, module, fileName); Expression <Func <string, bool> > filterExpression = (string s) => s.Contains(module, StringComparison.Ordinal); var mockIOProvider = IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression); return(mockIOProvider); }
public static void VerifyGeneralSettingsIOProviderWasRead(Mock <IFile> provider, int expectedCallCount) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } IIOProviderMocks.VerifyIOReadWithStubFile(provider, SettingsFilterExpression, expectedCallCount); }
public static void VerifyModuleIOProviderWasRead(Mock <IFile> provider, string module, int expectedCallCount) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } Expression <Func <string, bool> > filterExpression = ModuleFilterExpression(module); IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount); }
public static void VerifyGeneralSettingsIOProviderWasRead(Mock <IIOProvider> provider, int expectedCallCount) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } // Using Ordinal since this is used internally for a path Expression <Func <string, bool> > filterExpression = (string s) => s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal); IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount); }
public static void VerifyModuleIOProviderWasRead(Mock <IIOProvider> provider, string module, int expectedCallCount) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } Expression <Func <string, bool> > filterExpression = (string s) => s.Contains(module, StringComparison.Ordinal); IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount); }
public void JPEGQualityLevelShouldSetValueToTenWhenSuccessful() { // arrange var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object); Func <string, int> SendMockIPCConfigMSG = msg => { return(0); }; ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository <GeneralSettings> .GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); // act viewModel.JPEGQualityLevel = 10; // Assert viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository <GeneralSettings> .GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); Assert.AreEqual(10, viewModel.JPEGQualityLevel); }
public void TiffCompressOption_ShouldSetValueToTen_WhenSuccessful() { // arrange var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object); Func <string, int> SendMockIPCConfigMSG = msg => { return(0); }; ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SendMockIPCConfigMSG); // act viewModel.TiffCompressOption = 10; // Assert viewModel = new ImageResizerViewModel(mockSettingsUtils, SendMockIPCConfigMSG); Assert.AreEqual(10, viewModel.TiffCompressOption); }
public void EncoderShouldUpdateValueWhenSuccessful() { // arrange var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object); Func <string, int> SendMockIPCConfigMSG = msg => { return(0); }; ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository <GeneralSettings> .GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); // act viewModel.Encoder = 3; // Assert viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository <GeneralSettings> .GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.EncoderGuid); Assert.AreEqual(3, viewModel.Encoder); }
public void FileNameShouldUpdateValueWhenSuccessful() { // arrange var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object); Func <string, int> SendMockIPCConfigMSG = msg => { return(0); }; ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository <GeneralSettings> .GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); string expectedValue = "%1 (%3)"; // act viewModel.FileName = expectedValue; // Assert viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository <GeneralSettings> .GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG); Assert.AreEqual(expectedValue, viewModel.FileName); }
public void SaveSettingsShouldCreateFileWhenFilePathIsNotFound() { // Arrange var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var settingsUtils = new SettingsUtils(mockIOProvider.Object); string file_name = "test\\Test Folder"; string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}"; BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content); settingsUtils.SaveSettings(file_contents_correct_json_content, file_name); BasePTSettingsTest actual_json = settingsUtils.GetSettings <BasePTSettingsTest>(file_name); // Assert Assert.AreEqual(expected_json.ToJsonString(), actual_json.ToJsonString()); }
public void SettingsFolderExistsShouldReturnFalseWhenFilePathIsNotFound() { // Arrange var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var settingsUtils = new SettingsUtils(mockIOProvider.Object); string file_name_random = "test\\" + RandomString(); string file_name_exists = "test\\exists"; string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}"; // Act bool pathNotFound = settingsUtils.SettingsExists(file_name_random); settingsUtils.SaveSettings(file_contents_correct_json_content, file_name_exists); bool pathFound = settingsUtils.SettingsExists(file_name_exists); // Assert Assert.IsFalse(pathNotFound); Assert.IsTrue(pathFound); }
public void ToJsonStringShouldReturnValidJSONOfModelWhenSuccessful() { //Mock Disk access string saveContent = string.Empty; string savePath = string.Empty; var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists(); var settingsUtils = new SettingsUtils(mockIOProvider.Object); // Arrange string file_name = "test\\BasePTModuleSettingsTest"; string expectedSchemaText = @" { '$schema': 'http://json-schema.org/draft-04/schema#', 'type': 'object', 'properties': { 'name': { 'type': 'string' }, 'version': { 'type': 'string' } }, 'additionalProperties': false }"; string testSettingsConfigs = new BasePTSettingsTest().ToJsonString(); settingsUtils.SaveSettings(testSettingsConfigs, file_name); JsonSchema expectedSchema = JsonSchema.Parse(expectedSchemaText); // Act JObject actualSchema = JObject.Parse(settingsUtils.GetSettings <BasePTSettingsTest>(file_name).ToJsonString()); bool valid = actualSchema.IsValid(expectedSchema); // Assert Assert.IsTrue(valid); }
public static Mock <IFile> GetGeneralSettingsIOProvider(string version) { var stubGeneralSettingsPath = StubGeneralSettingsPath(version); return(IIOProviderMocks.GetMockIOReadWithStubFile(stubGeneralSettingsPath, SettingsFilterExpression)); }