Ejemplo n.º 1
0
        public void Service_WillObjectThrowExceptionWithEmptyLanguageLabel_Exception()
        {
            IPrepareService prepareService = new PrepareService();

            Assert.Throws <InvalidLanguageLabelException>(() =>
            {
                prepareService.SetLanguageLabel(string.Empty);
            });
        }
Ejemplo n.º 2
0
        public void Service_WillObjectThrowExceptionWithNullText_Exception()
        {
            IPrepareService prepareService = new PrepareService();

            Assert.Throws <InvalidTextToTrainException>(() =>
            {
                prepareService.SetSampleTextToPrepareSample(null);
            });
        }
Ejemplo n.º 3
0
        public void Service_WillObjectThrowExceptionWithEmptyText_Exception()
        {
            IPrepareService prepareService = new PrepareService();

            Assert.Throws <InvalidTextToTrainException>(() =>
            {
                prepareService.SetSampleTextToPrepareSample(new StringBuilder(""));
            });
        }
Ejemplo n.º 4
0
        public void Service_WillObjectThrowExceptionWithEmptyPath_Exception()
        {
            IPrepareService prepareService = new PrepareService();

            Assert.Throws <InvalidPathException>(() =>
            {
                prepareService.SetPathToSaveSample(string.Empty);
            });
        }
Ejemplo n.º 5
0
        private IEnumerable <RestitutionData> GetAllProjectDetails()
        {
            var projects = new PrepareService().GetProjects();

            var analyzeService = new AnalyzeService();

            foreach (var project in projects.Projects)
            {
                yield return(analyzeService.GetFullProjectDetails(project.ProjectId));
            }
        }
Ejemplo n.º 6
0
        public void Cleanup()
        {
            // Suppression des projets créés.

            var prepapreService = new PrepareService();

            var projects = prepapreService.GetProjects().Projects.Where(p => p.Label == Add_Action_Original_ProjectName);

            foreach (var project in projects)
            {
                project.MarkAsDeleted();
                prepapreService.SaveProject(project);
            }
        }
Ejemplo n.º 7
0
        private void GetScenarios(int scenarioId)
        {
            var service = new PrepareService();

            var           mre  = new System.Threading.ManualResetEvent(false);
            ScenariosData data = null;
            Exception     e    = null;

            service.GetScenarios(scenarioId, d =>
            {
                data = d;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

            mre.WaitOne();

            // Pour l'instant vérifie qu'aucune exception n'a été levée
            AssertExt.IsExceptionNull(e);
        }
Ejemplo n.º 8
0
        public void GetProjectsTest()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();
            var service = new PrepareService();

            var          mre  = new System.Threading.ManualResetEvent(false);
            ProjectsData data = null;
            Exception    e    = null;

            service.GetProjects(d =>
            {
                data = d;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

            mre.WaitOne();

            // Pour l'instant vérifie qu'aucune exception n'a été levée
            AssertExt.IsExceptionNull(e);
        }
Ejemplo n.º 9
0
        public void BulkScenarioCloneTests()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();
            var service = new PrepareService();

            int[] projectIds;
            using (var context = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                projectIds = context.Projects.Select(p => p.ProjectId).ToArray();
            }

            foreach (var pid in projectIds)
            {
                var mre = new System.Threading.ManualResetEvent(false);

                Exception     e    = null;
                ScenariosData data = null;

                service.GetScenarios(pid, d =>
                {
                    data = d;
                    mre.Set();
                }, ex =>
                {
                    e = ex;
                    mre.Set();
                });

                mre.WaitOne();
                AssertExt.IsExceptionNull(e);
                Assert.IsNotNull(data);

                foreach (var scenario in data.Scenarios.Where(s => s.NatureCode != KnownScenarioNatures.Realized))
                {
                    if (scenario.NatureCode == KnownScenarioNatures.Target && scenario.Actions.Any(a => !a.IsReduced))
                    {
                        // Il s'agit d'un vieux projet. Tous les actions d'un scénario cible doivent aujourd'hui avoir une partie réduite
                        continue;
                    }

                    mre.Reset();

                    Scenario newScenario = null;

                    service.CreateScenario(pid, scenario, true, s =>
                    {
                        newScenario = s;
                        mre.Set();
                    }, ex =>
                    {
                        e = ex;
                        mre.Set();
                    });

                    mre.WaitOne();
                    AssertExt.IsExceptionNull(e);
                    Assert.IsNotNull(newScenario);

                    // Vérification de l'intégrité du scénario
                    ActionsTimingsMoveManagement.DebugCheckAllWBS(EnumerableExt.Concat(newScenario));

                    // Vérifier qu'il n'y ai pas de tâche avec un temps process nul
                    if (scenario.NatureCode != KnownScenarioNatures.Initial && newScenario.Actions.Any(a => a.BuildDuration <= 0))
                    {
                        Assert.Fail("Une action a un temps invalide");
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void Add_Action_Original()
        {
            var prepareService = new PrepareService();
            var analyzeService = new AnalyzeService();

            // Création du projet
            var project = new Project
            {
                Label         = Add_Action_Original_ProjectName,
                ObjectiveCode = "PROD01",
                Workshop      = "Test_Add_Action_Original",
            };

            prepareService.SaveProject(project);

            // Création du scénario initial
            var initialScenario = prepareService.CreateInitialScenario(project.ProjectId);

            initialScenario.StateCode = KnownScenarioStates.Validated;
            prepareService.SaveScenario(project.ProjectId, initialScenario);

            // Création du scénario cible 1
            var targetScenario1 = prepareService.CreateScenario(project.ProjectId, initialScenario);

            targetScenario1.Label = "Target 1";
            prepareService.SaveScenario(project.ProjectId, targetScenario1);

            // Création du scénario cible 2 - hérite du scénario cible 1
            var targetScenario2 = prepareService.CreateScenario(project.ProjectId, targetScenario1);

            targetScenario2.Label = "Target 2";
            prepareService.SaveScenario(project.ProjectId, targetScenario2);

            // Passage du scénario initial en non figé
            targetScenario1.StateCode = KnownScenarioStates.Draft;
            prepareService.SaveScenario(project.ProjectId, targetScenario1);

            // Requêtage des données rafraichies
            var scenarios = analyzeService.GetAcquireData(project.ProjectId);

            initialScenario = scenarios.Scenarios[0];
            targetScenario1 = scenarios.Scenarios[1];
            targetScenario2 = scenarios.Scenarios[2];

            // Ajout de la tâche T1 dans le scénario Initial
            var t1Initial = new KAction
            {
                WBS         = "1",
                Start       = 0,
                Finish      = 1,
                BuildStart  = 0,
                BuildFinish = 1,
            };


            initialScenario.Actions.Add(t1Initial);
            analyzeService.SaveAcquireData(new Scenario[] { initialScenario, targetScenario1, targetScenario2 }, initialScenario);

            // Requêtage des données rafraichies
            scenarios       = analyzeService.GetAcquireData(project.ProjectId);
            initialScenario = scenarios.Scenarios[0];
            targetScenario1 = scenarios.Scenarios[1];
            targetScenario2 = scenarios.Scenarios[2];

            // Vérification de la correspondance entre les actions/originaux
            Assert.AreEqual(initialScenario.Actions[0], targetScenario1.Actions[0].Original);
            Assert.AreEqual(targetScenario1.Actions[0], targetScenario2.Actions[0].Original);
        }
Ejemplo n.º 11
0
        public void Servce_WillObjectThrowAnyExceptionAtFirstCreateSampleInvoke_AnyException()
        {
            IPrepareService prepareService = new PrepareService();

            Assert.That(() => prepareService.CreateSample(), Throws.Exception);
        }
Ejemplo n.º 12
0
        public void ImportProjectServiceWithMigrationTest()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();

            var importData = PrepareImport();

            var service = new ImportExportService();

            var mre = new System.Threading.ManualResetEvent(false);

            KProcess.Ksmed.Business.Dtos.Export.ProjectImport projectImport = null;
            Exception e = null;

            int newProjectId = -1;

            service.PredictMergedReferentialsProject(importData, pi =>
            {
                projectImport = pi;

                service.ImportProject(pi, false, TestContext.DeploymentDirectory, p =>
                {
                    newProjectId = p.ProjectId;
                    mre.Set();
                }, ex =>
                {
                    e = ex;
                    mre.Set();
                });
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

            mre.WaitOne();
            AssertExt.IsExceptionNull(e);
            Assert.IsNotNull(projectImport);

            Assert.IsTrue(projectImport.ExportedProject.Project.Label.EndsWith(" migré"));

            // Récupérer le projet depuis la base et tester
            var prepareService = new PrepareService();

            mre.Reset();
            ProjectsData data = null;

            prepareService.GetProjects(d =>
            {
                data = d;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

            mre.WaitOne();
            AssertExt.IsExceptionNull(e);

            var project = data.Projects.First(p => p.ProjectId == newProjectId);

            Assert.IsTrue(project.Label.EndsWith(" migré"));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Obtient toutes les données du projet spécifié.
        /// </summary>
        /// <param name="projectId">L'identifiant du projet.</param>
        public virtual async Task <RestitutionData> GetFullProjectDetails(int projectId) =>
        await Task.Run(async() =>
        {
            using (var context = ContextFactory.GetNewContext(_securityContext.CurrentUser, _localizationManager))
            {
                IDictionary <ProcessReferentialIdentifier, bool> referentialsUsed = await _sharedScenarioActionsOperations.GetReferentialsUse(context, projectId);
                Referentials referentials = await Queries.LoadAllReferentialsOfProject(context, projectId, referentialsUsed);

                //await context.Videos.Where(v => v.ProjectId == projectId).ToArrayAsync();
                await context.ScenarioNatures.ToArrayAsync();
                await context.ScenarioStates.ToArrayAsync();
                await context.ActionTypes.ToArrayAsync();
                await context.ActionValues.ToArrayAsync();

                Project project = await context.Projects
                                  .Include(nameof(Project.Process))
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.Videos)}")
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.UserRoleProcesses)}")
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.UserRoleProcesses)}.{nameof(UserRoleProcess.User)}")
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.UserRoleProcesses)}.{nameof(UserRoleProcess.User)}.{nameof(User.DefaultLanguage)}")
                                  .Include(nameof(Project.Scenarios))
                                  .Include($"{nameof(Project.Scenarios)}.{nameof(Scenario.Actions)}")
                                  .Include(nameof(Project.Objective))
                                  .FirstAsync(s => s.ProjectId == projectId);

                project.ScenariosCriticalPath = PrepareService.GetSummary(project, true);

                // Scénarios
                foreach (Scenario scenario in project.Scenarios.Where(s => s.OriginalScenarioId.HasValue))
                {
                    // Remapper l'original
                    scenario.Original = project.Scenarios.Single(s => s.ScenarioId == scenario.OriginalScenarioId);

                    ScenarioCriticalPath matchingCriticalItem = project.ScenariosCriticalPath.FirstOrDefault(i => i.Id == scenario.ScenarioId);
                    if (matchingCriticalItem != null)
                    {
                        matchingCriticalItem.OriginalLabel = scenario.Original.Label;
                    }
                }

                ProjectReferential[] projectReferentials = await context.ProjectReferentials.Where(pr => pr.ProjectId == projectId).ToArrayAsync();

                User user = await context.Users.FirstAsync(u => u.UserId == project.CreatedByUserId);

                ModificationsUsers modificationsUsers = new ModificationsUsers
                {
                    CreatedByFullName      = (await context.Users.FirstAsync(u => u.UserId == project.ModifiedByUserId)).FullName,
                    LastModifiedByFullName = (await context.Users.FirstAsync(u => u.UserId == project.ModifiedByUserId)).FullName
                };

                Scenario[] scenarios = await context.Scenarios
                                       .Where(s => s.ProjectId == projectId)
                                       .ToArrayAsync();

                await Queries.LoadScenariosDetails(context, scenarios, referentialsUsed);

                ILookup <int, KAction> actionsToLoad = scenarios
                                                       .SelectMany(a => a.Actions)
                                                       .Where(a => a.IsReduced && a.OriginalActionId.HasValue)
                                                       .ToLookup(a => a.OriginalActionId.Value, a => a);

                if (actionsToLoad.Any())
                {
                    foreach (var duration in await _sharedScenarioActionsOperations.GetActionsBuildDurations(context, actionsToLoad.Select(g => g.Key)))
                    {
                        foreach (KAction action in actionsToLoad[duration.ActionId])
                        {
                            action.Reduced.Saving = duration.BuildDuration - action.BuildDuration;
                        }
                    }
                }

                ScenarioActionHierarchyHelper.MapScenariosActionsOriginals(scenarios);

                return(new RestitutionData()
                {
                    Project = project,
                    ProjectCreatedByUser = user,
                    Scenarios = scenarios,
                    ActionCategories = referentials.Categories,
                    ModificationsUsers = modificationsUsers,
                    ReferentialsUse = projectReferentials,
                });
            }
        });
Ejemplo n.º 14
0
        public void TestsIsActionInternalExternalDeletedMutuallyExclusive()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();
            // Vérifie dans toutes les actions de la BDD si les actions sont soi I, E ou S et jamais aucun des trois ou plus d'un des 3 à la fois.
            var prepareService = new PrepareService();
            var analyzeService = new AnalyzeService();
            var mre            = new System.Threading.ManualResetEvent(false);

            ProjectsData pData     = null;
            Exception    exception = null;

            prepareService.GetProjects(d =>
            {
                pData = d;
                mre.Set();
            }, ex =>
            {
                exception = ex;
                mre.Set();
            });

            mre.WaitOne();
            AssertExt.IsExceptionNull(exception);

            foreach (var project in pData.Projects)
            {
                mre.Reset();
                RestitutionData rData = null;
                analyzeService.GetFullProjectDetails(project.ProjectId, d =>
                {
                    rData = d;
                    mre.Set();
                }, ex =>
                {
                    exception = ex;
                    mre.Set();
                });

                mre.WaitOne();
                AssertExt.IsExceptionNull(exception);

                foreach (var scenario in rData.Scenarios)
                {
                    foreach (var action in scenario.Actions)
                    {
                        bool i = ActionsTimingsMoveManagement.IsActionInternal(action);
                        bool e = ActionsTimingsMoveManagement.IsActionExternal(action);
                        bool s = ActionsTimingsMoveManagement.IsActionDeleted(action);

                        Assert.IsTrue(i || e || s);

                        if (i)
                        {
                            Assert.IsFalse(e || s);
                        }
                        else if (e)
                        {
                            Assert.IsFalse(i || s);
                        }
                        else
                        {
                            Assert.IsFalse(i || e);
                        }
                    }
                }
            }
        }