Exemple #1
0
        public static void ImportProject(Stream kspStream)
        {
            Exception e   = null;
            var       mre = new System.Threading.ManualResetEvent(false);

            byte[] importData;
            using (var memoryStream = new MemoryStream()) { kspStream.CopyTo(memoryStream, StreamExtensions.BufferSize); importData = memoryStream.ToArray(); }

            // Ouvrir le fichier
            Project project = null;

            new ImportExportService().PredictMergedReferentialsProject(importData, pi =>
            {
                new ImportExportService().ImportProject(pi, false, @"D:\Videos\Sample Videos", p =>
                {
                    project = p;
                    mre.Set();
                }, ex =>
                {
                    e = ex;
                    mre.Set();
                });
            }, ex =>
            {
                e = ex;
                mre.Set();
            });


            mre.WaitOne();
            AssertExt.IsExceptionNull(e);
            Assert.IsNotNull(project);
        }
Exemple #2
0
        public void ExportProjectExcelTest()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();
            string outFile = Path.Combine(TestContext.DeploymentDirectory, ExcelExporter.GetFileNameWithExtension("project export"));

            var service = new AnalyzeService();

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

            RestitutionData data = null;
            Exception       e    = null;

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

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

            new KProcess.Ksmed.Presentation.ViewModels.Restitution.ExportProjectToExcel(data, new ExportResult
            {
                Accepts         = true,
                OpenWhenCreated = false,
                Filename        = outFile,
            }).Export();

            TestContext.AddResultFile(outFile);
        }
Exemple #3
0
        public void PredictMergedReferentials_Tests()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();

            // Exporter le projet
            var service = new ImportExportService();

            var       mre    = new System.Threading.ManualResetEvent(false);
            Stream    stream = null;
            Exception e      = null;

            service.ExportProject(SampleData.GetProjectId(), d =>
            {
                stream = d;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

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

            stream.Position = 0;

            byte[] importData;
            using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream, StreamExtensions.BufferSize); importData = memoryStream.ToArray(); }

            // PredictMergedReferentials
            mre.Reset();
            KProcess.Ksmed.Business.Dtos.Export.ProjectImport import = null;
            service.PredictMergedReferentialsProject(importData, pi =>
            {
                import = pi;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

            mre.WaitOne();
            AssertExt.IsExceptionNull(e);
            Assert.IsNotNull(import);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
        public void ConvertActionToReducedActionTest()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();
            AnalyzeService service = new AnalyzeService();

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

            service.GetBuildData(SampleData.GetProjectId(), 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);
        }
Exemple #7
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");
                    }
                }
            }
        }
Exemple #8
0
        public void GanttGridTests()
        {
            KProcess.Ksmed.Business.Tests.SampleData.ClearDatabaseThenImportDefaultProject();

            // On récupère les données
            var service = new AnalyzeService();

            var mre = new ManualResetEvent(false);

            var collection     = new BulkObservableCollection <DataTreeGridItem>();
            var actionsManager = new GridActionsManager(collection, null, null);

            actionsManager.ChangeView(Core.GanttGridView.WBS, null);

            var categories = new BulkObservableCollection <ActionCategory>();

            Video[]    videos    = null;
            Scenario[] scenarios = null;
            Scenario   scenario  = null;

            Exception ex = null;

            service.GetAcquireData(SampleData.GetProjectId(),
                                   data =>
            {
                categories.AddRange(data.Categories);
                videos = data.Videos;

                scenarios = data.Scenarios;

                scenario = scenarios.First();

                foreach (var action in scenario.Actions)
                {
                    action.StartTracking();
                }

                mre.Set();
            },
                                   e =>
            {
                ex = e;
                mre.Set();
            });

            mre.WaitOne();

            AssertExt.IsExceptionNull(ex);

            actionsManager.RegisterInitialActions(scenario.Actions);

            Assert.IsTrue(scenario.Actions.Count > 1);
            Assert.IsTrue(collection.Count > 1);
            Assert.IsTrue(videos.Length > 0);
            Assert.IsTrue(scenario.Actions[1].Video != null);

            // Capturons l'état de toutes les éléments
            var originalValues = GetCurrentValues(scenario.Actions, categories, videos);

            Modify(actionsManager, collection, scenario);

            var modifiedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsFalse(AreDumpsEqual(originalValues, modifiedValues));

            // On annule les changements
            actionsManager.UnregisterAllItems();
            ObjectWithChangeTrackerExtensions.CancelChanges(scenario.Actions, categories, videos);

            var revertedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsTrue(AreDumpsEqual(originalValues, revertedValues));



            // On recommence
            actionsManager.RegisterInitialActions(scenario.Actions);
            Modify(actionsManager, collection, scenario);

            modifiedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsFalse(AreDumpsEqual(originalValues, modifiedValues));

            // On annule les changements
            actionsManager.UnregisterAllItems();
            ObjectWithChangeTrackerExtensions.CancelChanges(scenario.Actions, categories, videos);

            revertedValues = GetCurrentValues(scenario.Actions, categories, videos);

            Assert.IsTrue(AreDumpsEqual(originalValues, revertedValues));
        }
Exemple #9
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é"));
        }
Exemple #10
0
        /// <summary>
        /// Exporte le projet spécifié.
        /// </summary>
        private void ExportVideoDecomposition(int projectId, int scenarioId, int videoId, int targetProjectId, bool merge)
        {
            var service = new ImportExportService();

            string fileName = string.Format("out{0}.xml", fileNumber++);

            KProcess.Ksmed.Business.Dtos.Export.VideoDecompositionExport oldVideoExport;
            using (var context = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                oldVideoExport = new VideoDecompositionExporter(context, projectId, scenarioId, videoId).CreateExport();
            }

            var       mre    = new System.Threading.ManualResetEvent(false);
            Stream    stream = null;
            Exception e      = null;

            service.ExportVideoDecomposition(projectId, scenarioId, videoId, d =>
            {
                stream = d;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

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

            using (var reader = new StreamReader(stream))
            {
                string xml = reader.ReadToEnd();
                File.WriteAllText(fileName, xml);

                Assert.IsNotNull(xml);
            }
            stream.Close();

            Initialization.SetCurrentUser("paula");

            // Ouvrir le fichier
            mre.Reset();
            service.PredictMergedReferentialsVideoDecomposition(targetProjectId, File.OpenRead(fileName), vdi =>
            {
                service.ImportVideoDecomposition(vdi, merge, TestContext.DeploymentDirectory, targetProjectId, success =>
                {
                    Assert.IsTrue(success);
                    mre.Set();
                }, ex =>
                {
                    e = ex;
                    mre.Set();
                });
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

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

            // Récupérer le numéro de scénario initial du projet
            Scenario targetScenario;
            int      newVideoId;

            using (var context = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                targetScenario = context.Scenarios.Single(s => s.ProjectId == targetProjectId && s.StateCode == KnownScenarioStates.Draft && s.NatureCode == KnownScenarioNatures.Initial);
                var oldVideoName = context.Videos.Single(v => v.VideoId == videoId).Name;
                newVideoId = context.Videos.Where(v => v.ProjectId == targetProjectId && v.Name == oldVideoName)
                             .AsEnumerable().Last().VideoId;
            }

            //Réexporter la décompo
            KProcess.Ksmed.Business.Dtos.Export.VideoDecompositionExport newVideoExport;
            using (var context = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                newVideoExport = new VideoDecompositionExporter(context, targetScenario.ProjectId, targetScenario.ScenarioId, newVideoId).CreateExport();
            }

            // Comparer les valeurs

            // Vidéo
            var oldVideo = oldVideoExport.Video;
            var newVideo = newVideoExport.Video;

            AssertVideo(oldVideo, newVideo);

            // Référentiels
            var p1RerentialsProject  = ReferentialsHelper.GetAllReferentialsProject(oldVideoExport.Actions).ToArray();
            var p1RerentialsStandard = ReferentialsHelper.GetAllReferentialsStandardUsed(oldVideoExport.Actions).ToArray();

            var p2RerentialsProject  = ReferentialsHelper.GetAllReferentialsProject(newVideoExport.Actions).ToArray();
            var p2RerentialsStandard = ReferentialsHelper.GetAllReferentialsStandardUsed(newVideoExport.Actions).ToArray();

            Assert.IsTrue(p1RerentialsProject.Length <= p2RerentialsProject.Length);
            Assert.AreEqual(p1RerentialsProject.Length + p1RerentialsStandard.Length, p2RerentialsProject.Length);
            Assert.AreEqual(0, p2RerentialsStandard.Length);

            // Vérifier que toutes les actions de l'ancien export soient également maintenant dans le projet de destination
            var oldActions = oldVideoExport.Actions.OrderBy(a => WBSHelper.GetParts(a.WBS), new WBSHelper.WBSComparer()).ToArray();
            var newActions = newVideoExport.Actions.OrderBy(a => WBSHelper.GetParts(a.WBS), new WBSHelper.WBSComparer()).ToArray();

            Assert.AreEqual(oldActions.Length, newActions.Length);

            // Actions
            for (int j = 0; j < oldActions.Length; j++)
            {
                var oldAction = oldActions[j];
                var newAction = newActions[j];

                AssertAction(oldAction, newAction);

                // Actions réduites
                AssertActionReduced(oldAction.Reduced, newAction.Reduced);
            }

            ServicesDiagnosticsDebug.CheckReferentialsState();
        }
Exemple #11
0
        /// <summary>
        /// Exporte le projet spécifié.
        /// </summary>
        /// <param name="projectId">L'identifiant du projet.</param>
        private void ExportProject(int projectId, bool merge)
        {
            var service = new ImportExportService();

            string fileName = string.Format("out{0}.xml", fileNumber++);

            KProcess.Ksmed.Business.Dtos.Export.ProjectExport oldProjectExport;
            using (var context = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                oldProjectExport = service.CreateProjectExport(context, projectId);
            }

            var       mre    = new System.Threading.ManualResetEvent(false);
            Stream    stream = null;
            Exception e      = null;

            service.ExportProject(projectId, d =>
            {
                stream = d;
                mre.Set();
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

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

            using (var reader = new StreamReader(stream))
            {
                string xml = reader.ReadToEnd();
                File.WriteAllText(fileName, xml);

                Assert.IsNotNull(xml);
            }
            stream.Close();

            Initialization.SetCurrentUser("paula");

            // Ouvrir le fichier
            mre.Reset();
            int newProjectId = -1;

            service.PredictMergedReferentialsProject(File.ReadAllBytes(fileName), pi =>
            {
                service.ImportProject(pi, merge, TestContext.DeploymentDirectory, p =>
                {
                    newProjectId = p.ProjectId;
                    mre.Set();
                }, ex =>
                {
                    e = ex;
                    mre.Set();
                });
            }, ex =>
            {
                e = ex;
                mre.Set();
            });

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

            // Réexporter le projet
            KProcess.Ksmed.Business.Dtos.Export.ProjectExport newProjectExport;
            using (var context = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                newProjectExport = service.CreateProjectExport(context, newProjectId);
            }

            // Comparer les valeurs

            // Projet
            AssertProject(oldProjectExport.Project, newProjectExport.Project);

            // Vidéos
            var oldVideos = oldProjectExport.Project.Videos.OrderBy(v => v.Name).ToArray();
            var newVideos = newProjectExport.Project.Videos.OrderBy(v => v.Name).ToArray();

            for (int i = 0; i < oldVideos.Length; i++)
            {
                AssertVideo(oldVideos[i], newVideos[i]);
            }

            // Scénarios
            var oldScenarios = oldProjectExport.Project.Scenarios.OrderBy(s => s.Label).ToArray();
            var newScenarios = newProjectExport.Project.Scenarios.OrderBy(s => s.Label).ToArray();

            for (int i = 0; i < oldProjectExport.Project.Scenarios.Count; i++)
            {
                var oldScenario = oldScenarios[i];
                var newScenario = newScenarios[i];

                AssertScenario(oldScenario, newScenario);

                var oldActions = oldScenario.Actions.OrderBy(a => WBSHelper.GetParts(a.WBS), new WBSHelper.WBSComparer()).ToArray();
                var newActions = newScenario.Actions.OrderBy(a => WBSHelper.GetParts(a.WBS), new WBSHelper.WBSComparer()).ToArray();

                // Actions
                for (int j = 0; j < oldScenario.Actions.Count; j++)
                {
                    var oldAction = oldActions[j];
                    var newAction = newActions[j];

                    AssertAction(oldAction, newAction);

                    // Actions réduites
                    AssertActionReduced(oldAction.Reduced, newAction.Reduced);
                }
            }
        }
Exemple #12
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);
                        }
                    }
                }
            }
        }