private static async Task TestPhaseChange(string startPhases, string changedPhases, string[] ignorePhases = null)
        {
            // Ensure the projects are there
            await ProjectClient.EnsureTestProjects();

            // DATA SET UP -------------------------------
            // Reconfigure the categories
            var categoriesBackup = await PortfolioConfigClient.UpdatePhasesAsync(TestSettings.TestPortfolio, startPhases);

            Assert.AreEqual(PhaseBackup, categoriesBackup);

            GetProjectQueryDTO options = await PortfolioConfigClient.GetFilterOptionsAsync(TestSettings.TestPortfolio);

            var phaseOptions = options.Options.PhaseItems;

            if (ignorePhases != null)
            {
                phaseOptions.RemoveAll(p => ignorePhases.Contains(p.Display));
            }

            List <ProjectUpdateModel>           updates     = new List <ProjectUpdateModel>();
            Action <ProjectUpdateModel, string> ensurePhase = (p, ph) =>
            {
                if (p.phase != ph)
                {
                    p.phase = ph;
                    updates.Add(p);
                }
            };

            var testProjects = await ProjectClient.GetTestProjectsAsync();

            int ci = 0;

            for (int i = 0; i < ProjectClient.TestProjectCount; i++)
            {
                ensurePhase(testProjects[i], phaseOptions[ci++].Value);
                if (ci >= phaseOptions.Count)
                {
                    ci = 0;
                }
            }

            await ProjectClient.UpdateProjectsAsync(updates);

            updates.Clear();

            // CHANGE CATEGORIES  -------------------------------
            categoriesBackup = await PortfolioConfigClient.UpdatePhasesAsync(TestSettings.TestPortfolio, changedPhases);

            Assert.AreEqual(startPhases, categoriesBackup);

            // Restore the categories
            categoriesBackup = await PortfolioConfigClient.UpdatePhasesAsync(TestSettings.TestPortfolio, categoriesBackup);

            Assert.AreEqual(changedPhases, categoriesBackup);
        }
Пример #2
0
        public async Task <GetProjectQueryDTO> FilterOptionsAsync([FromUri(Name = "portfolio")] string viewKey)
        {
            GetProjectQueryDTO result = null;

            using (var context = new PortfolioContext())
            {
                var config = await portfolioService.GetConfigAsync(viewKey);

                var customFields = portfolioService.GetCustomFilterLabels(config);

                result = new GetProjectQueryDTO()
                {
                    Config  = PortfolioMapper.GetProjectLabelConfigModel(config, PortfolioFieldFlags.FilterProject | PortfolioFieldFlags.FilterRequired, customLabels: customFields),
                    Options = await portfolioService.GetNewProjectOptionsAsync(config)
                };
            }
            return(result);
        }
        public async Task ReconfigureCategoriesTest()
        {
            // Ensure the projects are there
            await ProjectClient.EnsureTestProjects();

            // DATA SET UP -------------------------------
            // Reconfigure the categories
            var categoriesBackup = await PortfolioConfigClient.UpdateCategoriesAsync(TestSettings.TestPortfolio, TestStartCategories);

            Assert.AreEqual(CategoryBackup, categoriesBackup);

            GetProjectQueryDTO options = await PortfolioConfigClient.GetFilterOptionsAsync(TestSettings.TestPortfolio);

            var categoryOptions = options.Options.CategoryItems;

            List <ProjectUpdateModel>           updates        = new List <ProjectUpdateModel>();
            Action <ProjectUpdateModel, string> ensureCategory = (p, c) => {
                if (p.category != c)
                {
                    p.category = c;
                    updates.Add(p);
                }
            };
            Action <ProjectUpdateModel, string> ensureSubCategory = (p, c) =>
            {
                var _cat = categoryOptions.Single(_c => _c.Display == c);
                if (p.subcat == null || !p.subcat.Contains(_cat.Value))
                {
                    var subCats = new List <string>();
                    if (p.subcat != null)
                    {
                        subCats.AddRange(p.subcat); // Add the existing values
                    }
                    subCats.Add(_cat.Value);        // Add the new value
                    updates.Add(p);
                }
            };

            var testProjects = await ProjectClient.GetTestProjectsAsync();

            int ci = 0;

            for (int i = 0; i < ProjectClient.TestProjectCount; i++)
            {
                ensureCategory(testProjects[i], categoryOptions[ci++].Value);
                if (ci >= categoryOptions.Count)
                {
                    ci = 0;
                }
            }

            ensureSubCategory(testProjects[0], "Best regulator");
            ensureSubCategory(testProjects[1], "Chemical contaminants");
            ensureSubCategory(testProjects[1], "Nutrition and health");
            ensureSubCategory(testProjects[1], "Consumer and business behaviour");
            ensureSubCategory(testProjects[2], "Novel food and processes");
            ensureSubCategory(testProjects[2], "Data and digital");
            ensureSubCategory(testProjects[2], "Best regulator");
            ensureSubCategory(testProjects[3], "Emerging risks and opportunities");
            ensureSubCategory(testProjects[3], "Best regulator");
            ensureSubCategory(testProjects[3], "Chemical contaminants");
            ensureSubCategory(testProjects[4], "Nutrition and health");
            ensureSubCategory(testProjects[4], "Consumer and business behaviour");
            ensureSubCategory(testProjects[5], "Novel food and processes");
            ensureSubCategory(testProjects[6], "Data and digital");
            ensureSubCategory(testProjects[7], "Best regulator");
            ensureSubCategory(testProjects[8], "Emerging risks and opportunities");

            await ProjectClient.UpdateProjectsAsync(updates);

            updates.Clear();

            // CHANGE CATEGORIES  -------------------------------
            categoriesBackup = await PortfolioConfigClient.UpdateCategoriesAsync(TestSettings.TestPortfolio, TestChangedCategories);

            Assert.AreEqual(TestStartCategories, categoriesBackup);

            // Restore the categories
            categoriesBackup = await PortfolioConfigClient.UpdateCategoriesAsync(TestSettings.TestPortfolio, categoriesBackup);

            Assert.AreEqual(TestChangedCategories, categoriesBackup);
        }