public void GenerateEducationPlan_ManagerCalled()
        {
            // Arrange
            var courses = new Collection <RestEducationPlanCourse> {
                new RestEducationPlanCourse
                {
                    Code = "2NETARCH"
                },
                new RestEducationPlanCourse
                {
                    Code = "ADCSB"
                },
            };

            RestEducationPlan restEducationPlan = GetDummyRestEducationPlan(courses);

            var educationPlanManagerMock = new Mock <IEducationPlanManager>(MockBehavior.Strict);

            educationPlanManagerMock.Setup(manager => manager.PreviewEducationPlan(restEducationPlan)).Returns(GetDummyEducationPlan());

            EducationPlanController controller = new EducationPlanController(educationPlanManagerMock.Object);

            // Act
            controller.GenerateEducationPlan(restEducationPlan);


            // Assert
            educationPlanManagerMock.Verify(manager => manager.PreviewEducationPlan(restEducationPlan));
        }
        public void Put_ManagerCalled()
        {
            // Arrange
            var courses = new Collection <RestEducationPlanCourse> {
                new RestEducationPlanCourse
                {
                    Code = "2NETARCH"
                },
                new RestEducationPlanCourse
                {
                    Code = "ADCSB"
                },
            };
            RestEducationPlan restEducationPlan = GetDummyRestEducationPlan(courses);

            var educationPlanManagerMock = new Mock <IEducationPlanManager>(MockBehavior.Strict);

            educationPlanManagerMock.Setup(manager => manager.SaveEducationPlan(restEducationPlan)).Returns(1);

            EducationPlanController controller = new EducationPlanController(educationPlanManagerMock.Object);

            // Act
            var result = controller.Put(restEducationPlan);


            // Assert
            Assert.AreEqual(1, result);
            educationPlanManagerMock.Verify(manager => manager.SaveEducationPlan(restEducationPlan));
        }
        public void GenerateEducationPlan_null_ExceptionThrowed()
        {
            // Arrange
            var courses = new Collection <RestEducationPlanCourse> {
                new RestEducationPlanCourse
                {
                    Code = "2NETARCH"
                },
                new RestEducationPlanCourse
                {
                    Code = "ADCSB"
                },
            };

            var educationPlanDataMapperMock = new Mock <IEducationPlanDataMapper>(MockBehavior.Strict);
            var educationPlanOutputterMock  = new Mock <IEducationPlanOutputter>(MockBehavior.Strict);
            var plannerMock                = new Mock <IPlanner>(MockBehavior.Strict);
            var courseServiceMock          = new Mock <ICourseService>(MockBehavior.Strict);
            var profileDataMapperMock      = new Mock <IDataMapper <CourseProfile> >(MockBehavior.Strict);
            var educationPlanConverterMock = new Mock <IEducationPlanConverter>(MockBehavior.Strict);
            var moduleDataMapperMock       = new Mock <IDataMapper <Module> >(MockBehavior.Strict);

            EducationPlanManager manager       = new EducationPlanManager(courseServiceMock.Object, plannerMock.Object, educationPlanOutputterMock.Object, profileDataMapperMock.Object, educationPlanDataMapperMock.Object, educationPlanConverterMock.Object, moduleDataMapperMock.Object);
            RestEducationPlan    educationPlan = GetDummyRestEducationPlan(courses);

            // Act
            var result = manager.GenerateEducationPlan(null, null);

            // Assert ArgumentNullException
        }
        public EducationPlan GenerateEducationPlan(RestEducationPlan educationPlan, EducationPlan oldEducationplan)
        {
            System.Diagnostics.Debug.WriteLine("parameters " + new JavaScriptSerializer().Serialize(educationPlan) + ", old: " + new JavaScriptSerializer().Serialize(educationPlan));
            if (educationPlan == null)
            {
                _logger.Error("ArgumentNullException: educationPlan");
                throw new ArgumentNullException("educationPlan");
            }

            _logger.Debug(string.Format(_culture, "GenerateEducationPlan for employee {0}", educationPlan.NameEmployee));

            _planner.StartDate    = educationPlan.InPaymentFrom;
            _planner.EndDate      = educationPlan.EmployableFrom;
            _planner.BlockedDates = educationPlan.BlockedDates;

            var           educationplanData = Mapper.Map <EducationPlanData>(educationPlan);
            CourseProfile profile           = null;

            if (educationPlan.ProfileId != 0)
            {
                _logger.Debug(string.Format(_culture, "ProfileId exists: {0}", educationPlan.ProfileId));
                profile = _profileDataMapper.FindById(educationPlan.ProfileId);
                educationplanData.Profile   = profile.Name;
                educationplanData.ProfileId = educationPlan.ProfileId;
            }

            var educationPlanCourses = educationPlan.Courses.Where(course => !course.Code.StartsWith("OLC"));

            _logger.Debug("Find courses from service");
            IEnumerable <Integration.Course>             courses       = _courseService.FindCourses(educationPlanCourses.Select(course => course.Code));
            List <OpleidingsplanGenerator.Models.Course> coursesToPlan = ConvertCourses(courses, profile, educationPlan.Courses);

            List <OpleidingsplanGenerator.Models.PinnedCourseImplementation> implementationConstraints = new List <OpleidingsplanGenerator.Models.PinnedCourseImplementation>();

            if (educationPlan.ImplementationConstraints != null)
            {
                implementationConstraints = ConvertImplementationConstraints(educationPlan.ImplementationConstraints);
            }

            if (oldEducationplan == null)
            {
                _planner.PlanCoursesWithOlc(coursesToPlan, implementationConstraints);
            }
            else
            {
                _planner.PlanCoursesWithOlcInOldEducationPlan(coursesToPlan, oldEducationplan, implementationConstraints);
            }

            _planner.AddModules(_moduleDataMapper.FindAll());

            OverrideRestCourse(_planner, educationPlan.Courses);

            var output = _educationPlanOutputter.GenerateEducationPlan(educationplanData);

            System.Diagnostics.Debug.WriteLine("parameters " + new JavaScriptSerializer().Serialize(output));

            return(output);
        }
        public long UpdateEducationPlan(RestEducationPlan restEducationPlan)
        {
            var oldEducationplan = _educationPlanDataMapper.FindById(restEducationPlan.EducationPlanId);

            var educationPlan = GenerateEducationPlan(restEducationPlan, oldEducationplan);



            return(_educationPlanDataMapper.Update(educationPlan));
        }
        public EducationPlan PreviewEducationPlan(RestEducationPlan educationPlan)
        {
            EducationPlan oldEducationplan = null;

            if (educationPlan.EducationPlanId != 0)
            {
                oldEducationplan = _educationPlanDataMapper.FindById(educationPlan.EducationPlanId);
            }

            return(GenerateEducationPlan(educationPlan, oldEducationplan));
        }
Exemplo n.º 7
0
        public void GenerateEducationPlan_IntegrationTest_WithPriority()
        {
            var courses = new Collection <RestEducationPlanCourse> {
                new RestEducationPlanCourse
                {
                    Code = "2NETARCH"
                },
                new RestEducationPlanCourse
                {
                    Code       = "ADCSB",
                    Priority   = -1,
                    Commentary = "Force to plan"
                },
            };

            RestEducationPlan restEducationPlan = GetDummyRestEducationPlan(courses);

            restEducationPlan.InPaymentFrom = new DateTime(2017, 3, 5);
            var courseServiceMock = new Mock <ICourseService>(MockBehavior.Strict);

            courseServiceMock.Setup(service => service.FindCourses(new List <string> {
                "2NETARCH", "ADCSB"
            })).Returns(
                new List <Integration.Course>()
            {
                CreateNewIntegrationCourseWithOneCourseImplementation("2NETARCH", 1,
                                                                      new Collection <DateTime> {
                    new DateTime(2017, 3, 6), new DateTime(2017, 3, 7), new DateTime(2017, 3, 8)
                }),
                CreateNewIntegrationCourseWithOneCourseImplementation("ADCSB", 1,
                                                                      new Collection <DateTime> {
                    new DateTime(2017, 3, 6), new DateTime(2017, 3, 7), new DateTime(2017, 3, 8)
                }),
            });
            var dalConfig = DalConfiguration.Configuration;

            IEducationPlanManager manager = new EducationPlanManager(dalConfig.ProfilePath, courseServiceMock.Object, dalConfig.ManagementPropertiesPath, dalConfig.EducationPlanPath, dalConfig.EducationPlanUpdatedPath, dalConfig.ModulePath);

            // Act
            var result = manager.GenerateEducationPlan(restEducationPlan, null);

            // Assert
            courseServiceMock.Verify(outputter => outputter.FindCourses(new List <string> {
                "2NETARCH", "ADCSB"
            }));

            Assert.AreEqual(3, result.PlannedCourses.Count());
            Assert.AreEqual("ADCSB", result.PlannedCourses.ElementAt(0).Code);
            Assert.AreEqual("Force to plan", result.PlannedCourses.ElementAt(0).Commentary);
            Assert.AreEqual("OLC1", result.PlannedCourses.ElementAt(1).Code);
            Assert.AreEqual("OLC2", result.PlannedCourses.ElementAt(2).Code);
            Assert.AreEqual(7, result.NotPlannedCourses.Count());
            Assert.AreEqual("2NETARCH", result.NotPlannedCourses.ElementAt(0).Code);
        }
        public long SaveEducationPlan(RestEducationPlan restEducationPlan)
        {
            var educationPlan = GenerateEducationPlan(restEducationPlan, null);

            return(_educationPlanDataMapper.Insert(educationPlan));
        }
Exemplo n.º 9
0
        public void GenerateEducationPlan_IntegrationTest()
        {
            // Arrange
            var courses = new Collection <RestEducationPlanCourse> {
                new RestEducationPlanCourse {
                    Code = "2NETARCH"
                }
            };

            RestEducationPlan restEducationPlan = GetDummyRestEducationPlan(courses);
            var courseServiceMock = new Mock <ICourseService>(MockBehavior.Strict);

            courseServiceMock.Setup(service => service.FindCourses(new List <string> {
                "2NETARCH"
            })).Returns(
                new List <Integration.Course>()
            {
                CreateNewIntegrationCourseWithTwoCourseImplementations("2NETARCH", 1,
                                                                       new Collection <DateTime> {
                    new DateTime(2017, 1, 2), new DateTime(2017, 1, 3), new DateTime(2017, 1, 4)
                },
                                                                       new Collection <DateTime> {
                    new DateTime(2017, 3, 6), new DateTime(2017, 3, 7), new DateTime(2017, 3, 8)
                })
            });
            var dalConfig = DalConfiguration.Configuration;

            IEducationPlanManager manager = new EducationPlanManager(dalConfig.ProfilePath, courseServiceMock.Object, dalConfig.ManagementPropertiesPath, dalConfig.EducationPlanPath, dalConfig.EducationPlanUpdatedPath, dalConfig.ModulePath);

            // Act
            var result = manager.GenerateEducationPlan(restEducationPlan, null);


            // Assert
            courseServiceMock.Verify(service => service.FindCourses(new List <string> {
                "2NETARCH"
            }));

            Assert.AreEqual(7, result.PlannedCourses.Count());
            Assert.AreEqual(6, result.NotPlannedCourses.Count());

            Assert.AreEqual("OLC1", result.PlannedCourses.ElementAt(0).Code);
            Assert.AreEqual(new DateTime(2016, 12, 5), result.PlannedCourses.ElementAt(0).Date);
            Assert.AreEqual(5, result.PlannedCourses.ElementAt(0).Days);

            Assert.AreEqual("OLC2", result.PlannedCourses.ElementAt(1).Code);
            Assert.AreEqual(new DateTime(2016, 12, 12), result.PlannedCourses.ElementAt(1).Date);
            Assert.AreEqual(5, result.PlannedCourses.ElementAt(1).Days);

            Assert.AreEqual("OLC3", result.PlannedCourses.ElementAt(2).Code);
            Assert.AreEqual(new DateTime(2016, 12, 19), result.PlannedCourses.ElementAt(2).Date);
            Assert.AreEqual(5, result.PlannedCourses.ElementAt(2).Days);

            Assert.AreEqual("OLC4", result.PlannedCourses.ElementAt(3).Code);
            Assert.AreEqual(new DateTime(2016, 12, 26), result.PlannedCourses.ElementAt(3).Date);
            Assert.AreEqual(5, result.PlannedCourses.ElementAt(3).Days);

            Assert.AreEqual("2NETARCH", result.PlannedCourses.ElementAt(4).Code);
            Assert.AreEqual(new DateTime(2017, 1, 2), result.PlannedCourses.ElementAt(4).Date);
            Assert.AreEqual(3, result.PlannedCourses.ElementAt(4).Days);

            Assert.AreEqual("OLC5", result.PlannedCourses.ElementAt(5).Code);
            Assert.AreEqual(new DateTime(2017, 1, 5), result.PlannedCourses.ElementAt(5).Date);
            Assert.AreEqual(2, result.PlannedCourses.ElementAt(5).Days);

            Assert.AreEqual("OLC6", result.PlannedCourses.ElementAt(6).Code);
            Assert.AreEqual(new DateTime(2017, 1, 9), result.PlannedCourses.ElementAt(6).Date);
            Assert.AreEqual(3, result.PlannedCourses.ElementAt(6).Days);
        }
        public void GenerateEducationPlan_Planner_Outputter_Service_DAL_Called()
        {
            // Arrange
            var courses = new Collection <RestEducationPlanCourse> {
                new RestEducationPlanCourse
                {
                    Code = "2NETARCH"
                },
                new RestEducationPlanCourse
                {
                    Code = "ADCSB"
                },
            };
            var moduleDataMapperMock = new Mock <IDataMapper <Module> >(MockBehavior.Strict);

            moduleDataMapperMock.Setup(dataMapper => dataMapper.FindAll()).Returns(GetDummyDataModules());

            var educationPlanConverterMock = new Mock <IEducationPlanConverter>(MockBehavior.Strict);

            var educationPlanDataMapperMock = new Mock <IEducationPlanDataMapper>(MockBehavior.Strict);

            var educationPlanOutputterMock = new Mock <IEducationPlanOutputter>(MockBehavior.Strict);

            educationPlanOutputterMock.Setup(planner => planner.GenerateEducationPlan(It.IsAny <EducationPlanData>())).Returns(GetDummyEducationPlan());

            var plannerMock = new Mock <IPlanner>(MockBehavior.Strict);

            plannerMock.Setup(planner => planner.PlanCoursesWithOlc(It.IsAny <IEnumerable <OpleidingsplanGenerator.Models.Course> >()));
            plannerMock.SetupSet(planner => planner.StartDate    = GetDummyRestEducationPlan(courses).InPaymentFrom).Verifiable();
            plannerMock.SetupSet(planner => planner.EndDate      = GetDummyRestEducationPlan(courses).EmployableFrom).Verifiable();
            plannerMock.SetupSet(planner => planner.BlockedDates = It.IsAny <Collection <DateTime> >()).Verifiable();
            plannerMock.SetupGet(planner => planner.AllCourses).Returns(GetDummyGeneratorCourses());
            plannerMock.Setup(planner => planner.AddModules(It.IsAny <IEnumerable <Module> >()));

            var courseServiceMock = new Mock <ICourseService>(MockBehavior.Strict);

            courseServiceMock.Setup(service => service.FindCourses(new List <string> {
                "2NETARCH", "ADCSB"
            })).Returns(
                new List <Integration.Course>()
            {
                CreateNewIntegrationCourseWithTwoCourseImplementations("2NETARCH", 1,
                                                                       new Collection <DateTime> {
                    new DateTime(2017, 1, 2), new DateTime(2017, 1, 3), new DateTime(2017, 1, 4)
                },
                                                                       new Collection <DateTime> {
                    new DateTime(2017, 3, 6), new DateTime(2017, 3, 7), new DateTime(2017, 3, 8)
                })
            });

            var profileDataMapperMock = new Mock <IDataMapper <CourseProfile> >(MockBehavior.Strict);

            profileDataMapperMock.Setup(dataMapper => dataMapper.FindById(1)).Returns(GetDummyDataProfiles().First());
            var dalConfig = DalConfiguration.Configuration;

            EducationPlanManager manager       = new EducationPlanManager(courseServiceMock.Object, plannerMock.Object, educationPlanOutputterMock.Object, profileDataMapperMock.Object, educationPlanDataMapperMock.Object, educationPlanConverterMock.Object, moduleDataMapperMock.Object);
            RestEducationPlan    educationPlan = GetDummyRestEducationPlan(courses);


            // Act
            var result = manager.GenerateEducationPlan(educationPlan, null);

            // Assert
            educationPlanOutputterMock.Verify(outputter => outputter.GenerateEducationPlan(It.IsAny <EducationPlanData>()));
            plannerMock.Verify(planner => planner.PlanCoursesWithOlc(It.IsAny <IEnumerable <OpleidingsplanGenerator.Models.Course> >()));
            courseServiceMock.Verify(outputter => outputter.FindCourses(new List <string> {
                "2NETARCH", "ADCSB"
            }));
            profileDataMapperMock.Verify(dataMapper => dataMapper.FindById(1));
            plannerMock.VerifySet(planner => planner.StartDate    = GetDummyRestEducationPlan(courses).InPaymentFrom);
            plannerMock.VerifySet(planner => planner.BlockedDates = It.IsAny <Collection <DateTime> >());
            moduleDataMapperMock.Verify(dataMapper => dataMapper.FindAll());
        }
Exemplo n.º 11
0
 public long Post(RestEducationPlan educationPlan)
 {
     return(_educationPlanManager.UpdateEducationPlan(educationPlan));
 }
Exemplo n.º 12
0
 public long Put(RestEducationPlan educationPlan)
 {
     return(_educationPlanManager.SaveEducationPlan(educationPlan));
 }
Exemplo n.º 13
0
 public EducationPlan GenerateEducationPlan(RestEducationPlan educationPlan)
 {
     return(_educationPlanManager.PreviewEducationPlan(educationPlan));
 }