public void WhenGenerateScheduleOfferingViewModel_ThenCategoryFilterListPopulated() { var expected = new[] { "Basic Needs", "Consumer Services", "Criminal Justice and Legal Services", "Education", "Environmental Quality", "Health Care", "Income Support and Employment", "Individual and Family Life", "Mental Health Care and Counseling", "Organizational/Community Services", "Support Groups", "Target Populations", "Test Category," }; ScheduleServiceOfferingListOptionsModel actual = Target.GenerateScheduleOfferingViewModel(User, new[] { 3 }); CollectionAssert.AreEquivalent(expected, actual.CategoryFilterList.ToList()); }
public void WhenGenerateScheduleOfferingViewModel_ThenTypeFilterListPopulated() { var expected = new[] { "Provide College Access", "Mentoring", "Test service typ,e" }; ScheduleServiceOfferingListOptionsModel actual = Target.GenerateScheduleOfferingViewModel(User, new[] { 3 }); CollectionAssert.AreEquivalent(expected, actual.TypeFilterList.ToList()); }
public void GivenValidStudentIds_WhenGenerateScheduleOfferingViewModel_ThenViewModelHasExpectedFilterLists() { var studentIds = new int[] { 1, 2 }; var students = Data.Students.Where(s => studentIds.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>()); ScheduleServiceOfferingListOptionsModel actual = Target.GenerateScheduleOfferingViewModel(User, studentIds); CollectionAssert.AreEqual(Data.Categories.Select(c => c.Name).ToList(), actual.CategoryFilterList.ToList()); CollectionAssert.AreEqual(Data.ServiceTypes.Where(s => s.IsActive).Select(c => c.Name).ToList(), actual.TypeFilterList.ToList()); }
public void GivenValidStudentIds_WhenGenerateScheduleOfferingViewModel_ThenViewModelWithAllStudentIdsIsReturned() { var expected = Data.Students.Select(s => s.Id).ToList(); var students = Data.Students.Where(s => expected.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>()); ScheduleServiceOfferingListOptionsModel actual = Target.GenerateScheduleOfferingViewModel(User, expected); Assert.IsNotNull(actual); CollectionAssert.AreEqual(expected, actual.SelectedStudents.ToList()); }
public void GivenViewModelGenerated_WhenIScheduleServiceOffering_ThenViewResultReturned_AndViewModelSet() { ScheduleServiceOfferingListOptionsModel expected = new ScheduleServiceOfferingListOptionsModel(); var students = new int[] { 1, 2 }; MockLogicManager.Expect(m => m.GenerateScheduleOfferingViewModel(User, students)).Return(expected); Target.TempData["ScheduleOfferingIds"] = students; var result = Target.ScheduleOffering() as ViewResult; result.AssertGetViewModel(expected); }
public void GivenValidStudentIds_WhenGenerateScheduleOfferingViewModel_ThenViewModelHasExpectedFavorites() { int[] studentIds = new int[] { 1, 2 }; var students = Data.Students.Where(s => studentIds.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>()); Data.ServiceOfferings[1].UsersLinkingAsFavorite.Add(User.Identity.User); Data.ServiceOfferings[2].UsersLinkingAsFavorite.Add(User.Identity.User); ScheduleServiceOfferingListOptionsModel actual = Target.GenerateScheduleOfferingViewModel(User, studentIds); CollectionAssert.AreEqual(new ServiceOffering[] { Data.ServiceOfferings[1], Data.ServiceOfferings[2] }, actual.Favorites.ToList()); }
public void GivenValidStudentIds_WhenGenerateScheduleOfferingViewModel_ThenViewModelHasExpectedStudentList() { List <int> expectedStudentList = new List <int> { 1, 2 }; var students = Data.Students.Where(s => expectedStudentList.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is <string>("ScheduleOffering"), Arg <object[]> .Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock <IPermission>()); ScheduleServiceOfferingListOptionsModel actual = Target.GenerateScheduleOfferingViewModel(User, expectedStudentList); CollectionAssert.AreEqual(expectedStudentList, actual.SelectedStudents.ToList()); }
public ScheduleServiceOfferingListOptionsModel GenerateScheduleOfferingViewModel(EducationSecurityPrincipal user, IEnumerable <int> studentIds) { IEnumerable <Student> students = StudentRepository.Items.Include(s => s.School).Where(s => studentIds.Contains(s.Id)); IPermission permission = PermissionFactory.Current.Create("ScheduleOffering", students); permission.GrantAccess(user); ScheduleServiceOfferingListOptionsModel viewModel = new ScheduleServiceOfferingListOptionsModel { SelectedStudents = studentIds }; viewModel.Favorites = LookupHelper.LoadFavorites(ServiceOfferingRepository, user); viewModel.TypeFilterList = ServiceTypeRepository.Items.Where(s => s.IsActive).Select(t => t.Name).ToList(); viewModel.CategoryFilterList = CategoryRepository.Items.Select(c => c.Name).ToList(); return(viewModel); }
public void GivenViewModelIsGenerated_AndAReturnUrl_WhenIScheduleServiceOffering_ThenViewModelHasReturnUrl() { var students = new int[] { 1, 2 }; MockLogicManager.Expect(m => m.GenerateScheduleOfferingViewModel(User, students)).Return(new ScheduleServiceOfferingListOptionsModel()); string expected = "blahlsdkjfsdlfkjsdlkfjs"; Target.TempData["ScheduleOfferingIds"] = students; Target.TempData["ScheduleOfferingReturnUrl"] = expected; ViewResult result = Target.ScheduleOffering() as ViewResult; ScheduleServiceOfferingListOptionsModel actual = result.AssertGetViewModel <ScheduleServiceOfferingListOptionsModel>(); Assert.AreEqual(expected, actual.ReturnUrl); }
public void GivenUserIsDataAdmin_AndUserHasFavorites_AndStudentIdsAreValid_WhenIScheduleOffering_ThenFavoritesAreLoaded() { User.Identity.User.UserRoles.Add(new UserRole { Role = new Role { Name = SecurityRoles.DataAdmin } }); Target.TempData["ScheduleOfferingIds"] = new int[] { 1 }; Target.TempData["ScheduleOfferingReturnUrl"] = "/student/finder"; var result = Target.ScheduleOffering() as ViewResult; ScheduleServiceOfferingListOptionsModel viewModel = result.AssertGetViewModel <ScheduleServiceOfferingListOptionsModel>(); List <ServiceOffering> actual = viewModel.Favorites.ToList(); Assert.IsNotNull(actual); Assert.AreEqual(1, actual.Count); Assert.AreEqual("Big Brothers, Big Sisters", actual[0].Provider.Name); Assert.AreEqual("Provide College Access", actual[0].ServiceType.Name); }
public ActionResult ScheduleOffering() { if (!TempData.ContainsKey("ScheduleOfferingIds")) { var redirectingUrl = Request.QueryString["ReturnUrl"] as string; if (redirectingUrl != null) { return(Redirect(redirectingUrl)); } return(RedirectToAction("Finder", "Student")); } IEnumerable <int> students = (IEnumerable <int>)TempData["ScheduleOfferingIds"]; ScheduleServiceOfferingListOptionsModel viewModel = LogicManager.GenerateScheduleOfferingViewModel((EducationSecurityPrincipal)User, students); viewModel.ReturnUrl = string.Empty; if (TempData.ContainsKey("ScheduleOfferingReturnUrl")) { viewModel.ReturnUrl = (string)TempData["ScheduleOfferingReturnUrl"]; } return(View(viewModel)); }
public ScheduleServiceOfferingListOptionsModel GenerateScheduleOfferingViewModel(EducationSecurityPrincipal user, IEnumerable<int> studentIds) { IEnumerable<Student> students = StudentRepository.Items.Include(s => s.School).Where(s => studentIds.Contains(s.Id)); IPermission permission = PermissionFactory.Current.Create("ScheduleOffering", students); permission.GrantAccess(user); ScheduleServiceOfferingListOptionsModel viewModel = new ScheduleServiceOfferingListOptionsModel { SelectedStudents = studentIds }; viewModel.Favorites = LookupHelper.LoadFavorites(ServiceOfferingRepository, user); viewModel.TypeFilterList = ServiceTypeRepository.Items.Where(s => s.IsActive).Select(t => t.Name).ToList(); viewModel.CategoryFilterList = CategoryRepository.Items.Select(c => c.Name).ToList(); return viewModel; }
public void GivenViewModelGenerated_WhenIScheduleServiceOffering_ThenViewResultReturned_AndViewModelSet() { ScheduleServiceOfferingListOptionsModel expected = new ScheduleServiceOfferingListOptionsModel(); var students = new int[] { 1, 2 }; MockLogicManager.Expect(m => m.GenerateScheduleOfferingViewModel(User, students)).Return(expected); Target.TempData["ScheduleOfferingIds"] = students; var result = Target.ScheduleOffering() as ViewResult; result.AssertGetViewModel(expected); }