Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #7
0
        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);
        }