internal static async Task <ConfigTestData> LoadAsync(string portfolio)
        {
            var config = new ConfigTestData(portfolio);
            await config.LoadAsync();

            return(config);
        }
        public async Task UpdateCategoryWithHistoryCheck()
        {
            var         projectId               = TestSettings.TestProjectId;
            var         testCategory            = "EXTRA CATEGORY";
            string      originalCategoryViewKey = null;
            Func <Task> updateCategory          = async() => {
                originalCategoryViewKey = await UpdateProjectCategory(projectId, testCategory);
            };

            // Test procedure:
            // 1. Update config to add the category
            // - at the midpoint, update the project to use the test category
            // - config then resets - but category is in use so is only hidden
            await ConfigurationTestUtils.TestCollectionLabel(ProjectPropertyConstants.category, testCategory, midpointTest : updateCategory);

            // 2. Update the project to not use the label
            var project = await ProjectTestData.LoadAsync(projectId);

            project.ProjectUpdate.category = originalCategoryViewKey;
            await project.UpdateAsync();

            // 3. Check the option has disappeared.
            await project.LoadAsync();

            var categoryItem = project.DTO.Options.CategoryItems.SingleOrDefault(i => i.Display == testCategory);

            Assert.IsNull(categoryItem);

            // 4. Do a no-change update on config (hidden option should be removed - but no way to verify!)
            var config = await ConfigTestData.LoadAsync(TestSettings.TestPortfolio);

            await config.UpdateAsync();
        }
        public ConfigTestData Clone()
        {
            var clone = new ConfigTestData(portfolio);

            clone.Config = TestMapper.ProjectMapper.Map <PortfolioConfigModel>(Config);
            return(clone);
        }
示例#4
0
        public async Task UpdateWithNoChange()
        {
            var before = await ConfigTestData.LoadAsync(TestSettings.TestPortfolio);

            var update = before.Clone();
            await update.UpdateAsync();

            var after = await ConfigTestData.LoadAsync(TestSettings.TestPortfolio);

            Assert.AreEqual(before.ConfigJSON, after.ConfigJSON);
        }
        internal static async Task TestCollectionLabel(string fieldName, string testValue, bool addToCurrent = true, Func <Task> midpointTest = null)
        {
            // 1. GET CONFIG the original
            var initialState = await ConfigTestData.LoadAsync(TestSettings.TestPortfolio);

            var original_Config_Expected     = initialState.ConfigJSON;
            var original_LabelValue_Expected = initialState.GetLabel(fieldName).InputValue;

            // 2. UPDATE CONFIG with new label and check values
            var updatedState = initialState.Clone();
            var updateLabel  = updatedState.GetLabel(fieldName);

            // Add the additional values to the current label value (as the existing ones may be in use)...
            var updated_LabelValue_Expected = addToCurrent ? $"{original_LabelValue_Expected}, {testValue}" : testValue;

            updateLabel.InputValue = updated_LabelValue_Expected;
            var updated_Config_Expected = updatedState.ConfigJSON;
            await updatedState.UpdateAsync();

            var afterUpdateState = await ConfigTestData.LoadAsync(TestSettings.TestPortfolio);

            var updated_Config_Actual     = afterUpdateState.ConfigJSON;
            var updated_LabelValue_Actual = afterUpdateState.GetLabel(fieldName).InputValue;

            // 3. Do midpoint testing
            if (midpointTest != null)
            {
                await midpointTest();
            }

            // 4. UPDATE CONFIG to set it back to original
            var resetState = afterUpdateState.Clone();

            resetState.GetLabel(fieldName).InputValue = original_LabelValue_Expected;
            await resetState.UpdateAsync();

            var afterResetState = await ConfigTestData.LoadAsync(TestSettings.TestPortfolio);

            var original_Config_Actual     = afterResetState.ConfigJSON;
            var original_LabelValue_Actual = afterResetState.GetLabel(fieldName).InputValue;

            // Verify update
            Assert.AreEqual(updated_LabelValue_Expected, updated_LabelValue_Actual);
            VerifyConfigs(updated_Config_Expected, updated_Config_Actual);

            // Verify reset to original
            Assert.AreEqual(original_LabelValue_Expected, original_LabelValue_Actual);
            VerifyConfigs(original_Config_Expected, original_Config_Actual);
        }