public void Create(EducationSecurityPrincipal user, ServiceOfferingScheduleModel viewModel)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     if (!ServiceOfferingRepository.Items.Any(s => s.Id == viewModel.ServiceOfferingId && s.IsActive))
     {
         throw new EntityNotFoundException("Selected Service Offering was not found.");
     }
     ServiceOffering offering = ServiceOfferingRepository.Items.Single(s => s.Id == viewModel.ServiceOfferingId && s.IsActive);
     IEnumerable<Student> students = StudentRepository.Items.Include(s => s.School).Where(s => viewModel.SelectedStudents.Contains(s.Id));
     IPermission permission = PermissionFactory.Current.Create("ScheduleOffering", students, offering);
     permission.GrantAccess(user);
     User userEntity = user.Identity.User;
     List<int> studentIds = viewModel.SelectedStudents.ToList();
     foreach (int studentId in studentIds)
     {
         var studentAssignedOffering = new StudentAssignedOffering
         {
             StudentId = studentId,
             CreatingUserId = userEntity.Id,
             IsActive = true
         };
         viewModel.CopyTo(studentAssignedOffering);
         StudentAssignedOfferingRepository.Add(studentAssignedOffering);
     }
     RepositoryContainer.Save();
 }
        public void Create(EducationSecurityPrincipal user, ServiceOfferingScheduleModel viewModel)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (!ServiceOfferingRepository.Items.Any(s => s.Id == viewModel.ServiceOfferingId && s.IsActive))
            {
                throw new EntityNotFoundException("Selected Service Offering was not found.");
            }
            ServiceOffering       offering   = ServiceOfferingRepository.Items.Single(s => s.Id == viewModel.ServiceOfferingId && s.IsActive);
            IEnumerable <Student> students   = StudentRepository.Items.Include(s => s.School).Where(s => viewModel.SelectedStudents.Contains(s.Id));
            IPermission           permission = PermissionFactory.Current.Create("ScheduleOffering", students, offering);

            permission.GrantAccess(user);
            User       userEntity = user.Identity.User;
            List <int> studentIds = viewModel.SelectedStudents.ToList();

            foreach (int studentId in studentIds)
            {
                var studentAssignedOffering = new StudentAssignedOffering
                {
                    StudentId      = studentId,
                    CreatingUserId = userEntity.Id,
                    IsActive       = true
                };
                viewModel.CopyTo(studentAssignedOffering);
                StudentAssignedOfferingRepository.Add(studentAssignedOffering);
            }
            RepositoryContainer.Save();
        }
Example #3
0
        public void GivenValidServiceOfferingId_WhenGenerateCreateViewModel_ThenViewModelHasServiceOfferingId()
        {
            int expected = 2;

            ServiceOfferingScheduleModel actual = Target.GenerateCreateViewModel(expected);

            Assert.AreEqual(expected, actual.ServiceOfferingId);
        }
Example #4
0
        public void GivenInvalidServiceOfferingSelected_WhenCreate_ThenThrowException()
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel {
                ServiceOfferingId = 1987897
            };

            Target.ExpectException <EntityNotFoundException>(() => Target.Create(User, viewModel));
        }
        public void GivenViewModelGenerated_WhenCreateScheduledOffering_ThenPartailViewResultReturned_AndViewModelSet()
        {
            ServiceOfferingScheduleModel expected = new ServiceOfferingScheduleModel();
            MockLogicManager.Expect(m => m.GenerateCreateViewModel(1)).Return(expected);

            PartialViewResult result = Target.CreateScheduledOffering(1) as PartialViewResult;

            result.AssertGetViewModel(expected);
        }
Example #6
0
        public void GivenViewModelGenerated_WhenCreateScheduledOffering_ThenPartailViewResultReturned_AndViewModelSet()
        {
            ServiceOfferingScheduleModel expected = new ServiceOfferingScheduleModel();

            MockLogicManager.Expect(m => m.GenerateCreateViewModel(1)).Return(expected);

            PartialViewResult result = Target.CreateScheduledOffering(1) as PartialViewResult;

            result.AssertGetViewModel(expected);
        }
Example #7
0
        public void GivenValidStudentIds_WhenCreate_ThenSucceed()
        {
            List <int> studentIds = new List <int> {
                2, 4
            };
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel {
                SelectedStudents = studentIds, ServiceOfferingId = 2
            };
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));

            PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>());

            Target.Create(User, viewModel);
        }
Example #8
0
        public void GivenInactiveServiceOfferingSelected_WhenCreate_ThenThrowException()
        {
            int inactiveId = Data.ServiceOfferings.First(s => !s.IsActive).Id;
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel {
                SelectedStudents = new List <int> {
                    2, 4
                }, ServiceOfferingId = inactiveId
            };
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));

            PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>());

            Target.ExpectException <EntityNotFoundException>(() => Target.Create(User, viewModel));
        }
Example #9
0
        public void GivenValidStudentIds_WhenCreate_ThenAttemptGrantAccess()
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel {
                SelectedStudents = new List <int> {
                    2, 4
                }, ServiceOfferingId = 2
            };
            var         students   = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));
            IPermission permission = MockRepository.GenerateMock <IPermission>();

            PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(permission);

            Target.Create(User, viewModel);

            permission.AssertWasCalled(p => p.GrantAccess(User));
        }
Example #10
0
        private List <StudentAssignedOffering> CreateAndEnsureCorrectStudentAssignmentCountAdded(List <int> studentIds)
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel {
                SelectedStudents = studentIds, ServiceOfferingId = 2
            };
            List <StudentAssignedOffering> added = new List <StudentAssignedOffering>();
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));

            PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>());
            Repositories.MockStudentAssignedOfferingRepository.Expect(m => m.Add(null)).IgnoreArguments().Do(new Action <StudentAssignedOffering>(a => added.Add(a)));

            Target.Create(User, viewModel);

            Assert.AreEqual(studentIds.Count, added.Count);
            return(added);
        }
Example #11
0
        public void GivenValidStudentIds_WhenCreate_ThenNewStudentAssignedOfferingIsActive()
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel {
                SelectedStudents = new List <int> {
                    2, 4
                }, ServiceOfferingId = 2
            };
            List <StudentAssignedOffering> studentsAdded = new List <StudentAssignedOffering>();
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));

            PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>());
            Repositories.MockStudentAssignedOfferingRepository.Expect(m => m.Add(null)).IgnoreArguments().Do(new Action <StudentAssignedOffering>(s => studentsAdded.Add(s)));

            Target.Create(User, viewModel);

            Assert.IsTrue(studentsAdded.All(s => s.IsActive == true));
            Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save());
            Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save());
        }
Example #12
0
        public ActionResult CreateScheduledOffering(int id)
        {
            ServiceOfferingScheduleModel viewModel = LogicManager.GenerateCreateViewModel(id);

            return(PartialView(viewModel));
        }
        public void GivenInvalidServiceOfferingSelected_WhenCreate_ThenThrowException()
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel { ServiceOfferingId = 1987897 };

            Target.ExpectException<EntityNotFoundException>(() => Target.Create(User, viewModel));
        }
        public void GivenValidStudentIds_WhenCreate_ThenAttemptGrantAccess()
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel { SelectedStudents = new List<int> { 2, 4 }, ServiceOfferingId = 2 };
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));
            IPermission permission = MockRepository.GenerateMock<IPermission>();
            PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("ScheduleOffering"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(permission);

            Target.Create(User, viewModel);

            permission.AssertWasCalled(p => p.GrantAccess(User));
        }
 public ActionResult CreateScheduledOffering(ServiceOfferingScheduleModel viewModel)
 {
     LogicManager.Create((EducationSecurityPrincipal)User, viewModel);
     return Json(true);
 }
        public void GivenValidStudentIds_WhenCreate_ThenServiceOfferingAssignmentsAdded()
        {
            List<int> studentIds = new List<int> { 2, 4 };
            List<Student> expectedStudents = Data.Students.Where(s => studentIds.Contains(s.Id)).ToList();
            int expectedServiceOfferingId = 2;
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel { SelectedStudents = studentIds, ServiceOfferingId = expectedServiceOfferingId };
            List<StudentAssignedOffering> studentsAdded = new List<StudentAssignedOffering>();
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));
            PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("ScheduleOffering"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock<IPermission>());
            Repositories.MockStudentAssignedOfferingRepository.Expect(m => m.Add(null)).IgnoreArguments().Do(new Action<StudentAssignedOffering>(s => studentsAdded.Add(s)));

            Target.Create(User, viewModel);

            Assert.IsTrue(studentsAdded.All(a => a.ServiceOfferingId == expectedServiceOfferingId));
            CollectionAssert.AreEqual(expectedStudents.Select(s => s.Id).ToList(), studentsAdded.Select(a => a.StudentId).ToList());
            Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save());
        }
        public void GivenInactiveServiceOfferingSelected_WhenCreate_ThenThrowException()
        {
            int inactiveId = Data.ServiceOfferings.First(s => !s.IsActive).Id;
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel { SelectedStudents = new List<int> { 2, 4 }, ServiceOfferingId = inactiveId };
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));
            PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("ScheduleOffering"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock<IPermission>());

            Target.ExpectException<EntityNotFoundException>(() => Target.Create(User, viewModel));
        }
        private List<StudentAssignedOffering> CreateAndEnsureCorrectStudentAssignmentCountAdded(List<int> studentIds)
        {
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel { SelectedStudents = studentIds, ServiceOfferingId = 2 };
            List<StudentAssignedOffering> added = new List<StudentAssignedOffering>();
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));
            PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("ScheduleOffering"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock<IPermission>());
            Repositories.MockStudentAssignedOfferingRepository.Expect(m => m.Add(null)).IgnoreArguments().Do(new Action<StudentAssignedOffering>(a => added.Add(a)));

            Target.Create(User, viewModel);

            Assert.AreEqual(studentIds.Count, added.Count);
            return added;
        }
        public void GivenValidStudentIds_WhenCreate_ThenSucceed()
        {
            List<int> studentIds = new List<int> { 2, 4 };
            ServiceOfferingScheduleModel viewModel = new ServiceOfferingScheduleModel { SelectedStudents = studentIds, ServiceOfferingId = 2 };
            var students = Data.Students.Where(s => viewModel.SelectedStudents.Contains(s.Id));
            PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("ScheduleOffering"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock<IPermission>());

            Target.Create(User, viewModel);
        }
 public void InitializeTest()
 {
     Target = new ServiceOfferingScheduleModel();
 }
Example #21
0
 public ActionResult CreateScheduledOffering(ServiceOfferingScheduleModel viewModel)
 {
     LogicManager.Create((EducationSecurityPrincipal)User, viewModel);
     return(Json(true));
 }