Пример #1
0
        public void MergeCategoriesTest()
        {
            SampleData.ClearDatabaseThenImportDefaultProject();

            var service = new ReferentialsService();

            ActionCategory[] categories;
            using (var ctx = KProcess.Ksmed.Data.ContextFactory.GetNewContext())
            {
                categories = ctx.ActionCategories.ToArray();
            }

            service.MergeReferentials(new ActionCategoryProject {
                ActionCategoryId = categories[0].ActionCategoryId
            }, new ActionCategory[]
            {
                categories[1],
                categories[2],
                categories[3],
            });
        }
Пример #2
0
        public void MergeMultipleReferentialsTest()
        {
            SampleData.ClearDatabase();
            // Importer le projet une deuxième fois
            SampleData.ImportProject(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("KProcess.Ksmed.Business.Tests.Resources.MergeMultipleReferentials.ksp"));
            SampleData.ImportProject(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("KProcess.Ksmed.Business.Tests.Resources.MergeMultipleReferentials.ksp"));

            // Mémoriser les Ref1 de chaque tâche de chaque projet

            var projects    = GetAllProjectDetails().ToArray();
            var actionsRef1 = projects.SelectMany(p => p.Scenarios.SelectMany(s => s.Actions.SelectMany(a => a.Ref1))).ToDictionary(al => al.ActionId, al => al.Referential.Label);

            // Créer un référentiel standard pour chaque ref1
            var masterSlaves = new Dictionary <Ref1Standard, Ref1Project[]>();

            foreach (var ref1 in projects[0].Project.Ref1)
            {
                var standard = new Ref1Standard
                {
                    Label = ref1.Label,
                };

                masterSlaves[standard] = new Ref1Project[]
                {
                    ref1,
                    projects[1].Project.Ref1.First(r => r.Label == ref1.Label),
                };

                new ReferentialsService().SaveReferentials <Ref1>(new Ref1Standard[]
                {
                    standard,
                });
            }

            // Merger chaque ref standard avec les deux ref projets
            var service = new ReferentialsService();

            foreach (var standard in masterSlaves.Keys)
            {
                // Copier pour éviter les références inutiles
                var std = new Ref1Standard
                {
                    RefId = standard.RefId,
                };
                standard.MarkAsUnchanged();

                var slaves = masterSlaves[standard].Select(s => new Ref1Project {
                    RefId = s.RefId
                }).ToArray();
                foreach (var slave in slaves)
                {
                    slave.MarkAsUnchanged();
                }

                service.MergeReferentials(std, slaves);
            }

            // Vérifier que les référentiels des tâches correspondent
            projects = GetAllProjectDetails().ToArray();
            var actionsRef1Final = projects.SelectMany(p => p.Scenarios.SelectMany(s => s.Actions.SelectMany(a => a.Ref1))).ToDictionary(al => al.ActionId, al => al.Referential.Label);

            CollectionAssert.AreEquivalent(actionsRef1, actionsRef1Final);
        }