public void GivenModelWithSelectedCustomFields_AndSelectedServiceTypes_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; List <object> expected = new List <object> { student.School.Name, student.Grade, student.FullName, student.StudentSISId, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value }; var offering = student.StudentAssignedOfferings.First().ServiceOffering; List <object> expectedServices = new List <object> { offering.Name }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = new List <CustomField> { TestData.CustomFields[0], TestData.CustomFields[2] }, SelectedServiceTypes = new List <ServiceType> { offering.ServiceType } }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock <IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); var actualServices = actual.ElementAt(6) as List <string>; CollectionAssert.AreEqual(expected.ToList(), actual.Take(6).ToList()); CollectionAssert.AreEqual(expectedServices, actualServices); }
public void GivenModelWithBirthDateIncluded_AndParentNameIncluded_AndSelectedCustomFields_AndSelectedServiceTypes_AndPermissionGrantsCustomFieldOnly_WhenMapData_ThenResultContainsOnlyDirectoryLevelData() { Student student = TestData.Students[0]; List <object> expected = new List <object> { student.School.Name, student.Grade, student.FullName, null, null, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value }; var model = new StudentProfileExportFieldDescriptor { BirthDateIncluded = true, ParentNameIncluded = true, SelectedCustomFields = new List <CustomField> { TestData.CustomFields[0], TestData.CustomFields[2] }, SelectedServiceTypes = new List <ServiceType> { TestData.ServiceTypes[1] } }; IViewStudentDetailPermission permission = MockRepository.GenerateMock <IViewStudentDetailPermission>(); permission.Expect(p => p.CustomFieldOnly).Return(true); PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(permission); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public IEnumerable<string> MapColumnHeadings(StudentProfileExportFieldDescriptor fieldConfiguration) { List<string> columnHeadings = new List<string>(_RequiredColumnHeadings); MapStandardFieldHeadings(fieldConfiguration, columnHeadings); columnHeadings.AddRange(fieldConfiguration.SelectedCustomFields.Select(f => f.Name)); columnHeadings.AddRange(fieldConfiguration.SelectedServiceTypes.Select(t => t.Name)); return columnHeadings; }
public IEnumerable <string> MapColumnHeadings(StudentProfileExportFieldDescriptor fieldConfiguration) { List <string> columnHeadings = new List <string>(_RequiredColumnHeadings); MapStandardFieldHeadings(fieldConfiguration, columnHeadings); columnHeadings.AddRange(fieldConfiguration.SelectedCustomFields.Select(f => f.Name)); columnHeadings.AddRange(fieldConfiguration.SelectedServiceTypes.Select(t => t.Name)); return(columnHeadings); }
public void GivenModelWithBirthDateIncluded_WhenMapColumnHeadings_ThenExpectedStringsReturned() { List<string> expected = new List<String> { "School Description", "Grade", "Student Name", "Student ID", "Birth Date", TestData.CustomFields[0].Name, TestData.ServiceTypes[0].Name }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = new List<CustomField> { TestData.CustomFields[0] }, SelectedServiceTypes = new List<ServiceType> { TestData.ServiceTypes[0] } }; model.BirthDateIncluded = true; var actual = Target.MapColumnHeadings(model); CollectionAssert.AreEqual(expected, actual.ToList()); }
private static void MapStandardFieldHeadings(StudentProfileExportFieldDescriptor fieldConfiguration, List <string> columnHeadings) { if (fieldConfiguration.BirthDateIncluded) { columnHeadings.Add("Birth Date"); } if (fieldConfiguration.ParentNameIncluded) { columnHeadings.Add("Parent Name"); } }
private static void MapStandardData(StudentProfileExportFieldDescriptor fieldConfiguration, Student data, List <object> dataList, bool directoryLevelOnly) { if (fieldConfiguration.BirthDateIncluded) { dataList.Add(directoryLevelOnly ? null : data.DateOfBirth); } if (fieldConfiguration.ParentNameIncluded) { dataList.Add(directoryLevelOnly ? null : data.Parents); } }
public void GivenModelWithBirthDateIncluded_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; List<object> expected = new List<object> { student.School.Name, student.Grade, student.FullName, student.StudentSISId, student.DateOfBirth }; var model = new StudentProfileExportFieldDescriptor { BirthDateIncluded = true }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock<IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenNoSelectedCustomFields_AndNoSelectedServiceTypes_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; List <object> expected = new List <object> { student.School.Name, student.Grade, student.FullName, student.StudentSISId }; var model = new StudentProfileExportFieldDescriptor(); PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock <IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenModelWithSelectedCustomFields_AndStudentDoesntHaveAllTheCustomFields_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; List <object> expected = new List <object> { student.School.Name, student.Grade, student.FullName, student.StudentSISId, "1200", "1201", "1202", "", "", "", "" }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = TestData.CustomFields.OfType <PublicField>() }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock <IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenModel_WhenMapColumnHeadings_ThenExpectedStringsReturned() { List <string> expected = new List <String> { "School Description", "Grade", "Student Name", "Student ID", TestData.CustomFields[0].Name, TestData.ServiceTypes[0].Name }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = new List <CustomField> { TestData.CustomFields[0] }, SelectedServiceTypes = new List <ServiceType> { TestData.ServiceTypes[0] } }; var actual = Target.MapColumnHeadings(model); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenSelectedCustomFields_WhenMapData_ThenUserHasNewPrivateHealthDataViewEvents() { Student student = TestData.Students[0]; List <object> expected = new List <object> { student.School.Name, student.Grade, student.FullName, student.Id, null, null, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = TestData.CustomFields }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock <IViewStudentDetailPermission>()); MockUserAuditor.Expect(m => m.CreatePrivateHealthInfoViewEvent(User.Identity.User, student.CustomFieldValues.ToList())).Return(new PrivateHealthDataViewEvent()); var actual = Target.MapData(model, student, User, MockUserAuditor); Assert.AreEqual(1, User.Identity.User.PrivateHealthDataViewEvents.Count()); }
public void GivenModelWithBirthDateIncluded_AndParentNameIncluded_AndSelectedCustomFields_AndSelectedServiceTypes_AndPermissionGrantsCustomFieldOnly_WhenMapData_ThenResultContainsOnlyDirectoryLevelData() { Student student = TestData.Students[0]; List<object> expected = new List<object> { student.School.Name, student.Grade, student.FullName, null, null, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value }; var model = new StudentProfileExportFieldDescriptor { BirthDateIncluded = true, ParentNameIncluded = true, SelectedCustomFields = new List<CustomField> { TestData.CustomFields[0], TestData.CustomFields[2] }, SelectedServiceTypes = new List<ServiceType> { TestData.ServiceTypes[1] } }; IViewStudentDetailPermission permission = MockRepository.GenerateMock<IViewStudentDetailPermission>(); permission.Expect(p => p.CustomFieldOnly).Return(true); PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(permission); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenSelectedServiceHasProgramName_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; var offering = student.StudentAssignedOfferings.First().ServiceOffering; List <object> expected = new List <object> { offering.Name }; var model = new StudentProfileExportFieldDescriptor { SelectedServiceTypes = new List <ServiceType> { offering.ServiceType } }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock <IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); var services = actual.ElementAt(4) as List <string>; CollectionAssert.AreEqual(expected, services); }
public void GivenPermissionDoesNotGrantAccess_WhenMapData_ThenOnlyDirectoryLevelInformationReturned() { Student student = TestData.Students[0]; List <object> expected = new List <object> { student.School.Name, student.Grade, student.FullName }; var model = new StudentProfileExportFieldDescriptor { SelectedServiceTypes = new List <ServiceType> { TestData.ServiceTypes[1] } }; IViewStudentDetailPermission permission = MockRepository.GenerateMock <IViewStudentDetailPermission>(); permission.Expect(p => p.GrantAccess(User)).Throw(new EntityAccessUnauthorizedException()); PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(permission); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenModelWithSelectedServiceTypes_AndSomeStudentAssignedOfferingsInactive_WhenMapData_ThenOnlyActiveStudentAssignedOfferingsReturned() { Student student = TestData.Students[0]; student.StudentAssignedOfferings.Clear(); student.StudentAssignedOfferings.Add(new StudentAssignedOffering { StudentId = 1, ServiceOfferingId = 1, ServiceOffering = TestData.ServiceOfferings[0], IsActive = false }); var model = new StudentProfileExportFieldDescriptor { SelectedServiceTypes = new List <ServiceType> { TestData.ServiceTypes[1] } }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock <IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); var services = actual.ElementAt(4) as List <string>; Assert.AreEqual(0, services.Count()); }
public IEnumerable <object> MapData(StudentProfileExportFieldDescriptor fieldConfiguration, Student data, EducationSecurityPrincipal user, IUserAuditor auditor) { if (data == null) { throw new ArgumentNullException("data"); } if (user == null) { throw new ArgumentNullException("user"); } if (auditor == null) { throw new ArgumentNullException("auditor"); } List <object> dataList = new List <object> { data.School.Name, data.Grade, data.FullName }; IViewStudentDetailPermission permission = (IViewStudentDetailPermission)PermissionFactory.Current.Create("StudentProfileExportMapData", data); if (permission.TryGrantAccess(user)) { if (!permission.CustomFieldOnly) { dataList.Add(data.StudentSISId); } MapStandardData(fieldConfiguration, data, dataList, permission.CustomFieldOnly); dataList.AddRange(fieldConfiguration.SelectedCustomFields.Select(f => FindLatestValue(data, f)).Select(v => v == null ? string.Empty : v.Value)); var fields = fieldConfiguration.SelectedCustomFields.Select(f => FindLatestValue(data, f)); if (fields.Where(f => f != null).ToList().Count() > 0) { user.Identity.User.PrivateHealthDataViewEvents.Add(auditor.CreatePrivateHealthInfoViewEvent(user.Identity.User, fields.Where(f => f != null).ToList())); } if (!permission.CustomFieldOnly) { dataList.AddRange(fieldConfiguration.SelectedServiceTypes.Select(serviceType => FindServicesOfferingNames(data, serviceType))); } } return(dataList); }
public IEnumerable<object> MapData(StudentProfileExportFieldDescriptor fieldConfiguration, Student data, EducationSecurityPrincipal user, IUserAuditor auditor) { if (data == null) { throw new ArgumentNullException("data"); } if (user == null) { throw new ArgumentNullException("user"); } if (auditor == null) { throw new ArgumentNullException("auditor"); } List<object> dataList = new List<object> { data.School.Name, data.Grade, data.FullName }; IViewStudentDetailPermission permission = (IViewStudentDetailPermission)PermissionFactory.Current.Create("StudentProfileExportMapData", data); if(permission.TryGrantAccess(user)) { if (!permission.CustomFieldOnly) { dataList.Add(data.StudentSISId); } MapStandardData(fieldConfiguration, data, dataList, permission.CustomFieldOnly); dataList.AddRange(fieldConfiguration.SelectedCustomFields.Select(f => FindLatestValue(data, f)).Select(v => v == null ? string.Empty : v.Value)); var fields = fieldConfiguration.SelectedCustomFields.Select(f => FindLatestValue(data, f)); if (fields.Where(f => f != null).ToList().Count() > 0) { user.Identity.User.PrivateHealthDataViewEvents.Add(auditor.CreatePrivateHealthInfoViewEvent(user.Identity.User, fields.Where(f => f != null).ToList())); } if (!permission.CustomFieldOnly) { dataList.AddRange(fieldConfiguration.SelectedServiceTypes.Select(serviceType => FindServicesOfferingNames(data, serviceType))); } } return dataList; }
public void GivenModelWithSelectedCustomFields_AndSelectedServiceTypes_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; List<object> expected = new List<object> { student.School.Name, student.Grade, student.FullName, student.StudentSISId, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value }; var offering = student.StudentAssignedOfferings.First().ServiceOffering; List<object> expectedServices = new List<object> { offering.Name }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = new List<CustomField> { TestData.CustomFields[0], TestData.CustomFields[2] }, SelectedServiceTypes = new List<ServiceType> { offering.ServiceType } }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock<IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); var actualServices = actual.ElementAt(6) as List<string>; CollectionAssert.AreEqual(expected.ToList(), actual.Take(6).ToList()); CollectionAssert.AreEqual(expectedServices, actualServices); }
public void GivenModelWithSelectedCustomFields_AndStudentDoesntHaveAllTheCustomFields_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; List<object> expected = new List<object> { student.School.Name, student.Grade, student.FullName, student.StudentSISId, "1200", "1201", "1202", "", "", "", "" }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = TestData.CustomFields.OfType<PublicField>() }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock<IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenModelWithSelectedServiceTypes_AndSomeStudentAssignedOfferingsInactive_WhenMapData_ThenOnlyActiveStudentAssignedOfferingsReturned() { Student student = TestData.Students[0]; student.StudentAssignedOfferings.Clear(); student.StudentAssignedOfferings.Add(new StudentAssignedOffering { StudentId = 1, ServiceOfferingId = 1, ServiceOffering = TestData.ServiceOfferings[0], IsActive = false }); var model = new StudentProfileExportFieldDescriptor { SelectedServiceTypes = new List<ServiceType> { TestData.ServiceTypes[1] } }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock<IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); var services = actual.ElementAt(4) as List<string>; Assert.AreEqual(0, services.Count()); }
public void GivenPermissionDoesNotGrantAccess_WhenMapData_ThenOnlyDirectoryLevelInformationReturned() { Student student = TestData.Students[0]; List<object> expected = new List<object> { student.School.Name, student.Grade, student.FullName }; var model = new StudentProfileExportFieldDescriptor { SelectedServiceTypes = new List<ServiceType> { TestData.ServiceTypes[1] } }; IViewStudentDetailPermission permission = MockRepository.GenerateMock<IViewStudentDetailPermission>(); permission.Expect(p => p.GrantAccess(User)).Throw(new EntityAccessUnauthorizedException()); PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(permission); var actual = Target.MapData(model, student, User, MockUserAuditor); CollectionAssert.AreEqual(expected, actual.ToList()); }
public void GivenSelectedServiceHasProgramName_WhenMapData_ThenExpectedObjectsReturned() { Student student = TestData.Students[0]; var offering = student.StudentAssignedOfferings.First().ServiceOffering; List<object> expected = new List<object> { offering.Name }; var model = new StudentProfileExportFieldDescriptor { SelectedServiceTypes = new List<ServiceType> { offering.ServiceType } }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock<IViewStudentDetailPermission>()); var actual = Target.MapData(model, student, User, MockUserAuditor); var services = actual.ElementAt(4) as List<string>; CollectionAssert.AreEqual(expected, services); }
public Stream GenerateStudentProfileExport(EducationSecurityPrincipal user, StudentProfileExportModel model, string templatePath) { var students = RetrieveStudentsList(model); var configuration = new StudentProfileExportFieldDescriptor { BirthDateIncluded = model.BirthDateIncluded, ParentNameIncluded = model.ParentNameIncluded, SelectedServiceTypes = ServiceTypeRepository.Items.Where(t => model.SelectedServiceTypeIds.Contains(t.Id)).ToList() }; List<CustomField> displayFields = new List<CustomField>(); foreach (var field in CustomFieldRepository.Items.Where(f => model.SelectedCustomFieldIds.Contains(f.Id))) { IPermission permission = PermissionFactory.Current.Create("StudentProfileExportCustomFieldData", field); if (permission.TryGrantAccess(user)) { displayFields.Add(field); } } configuration.SelectedCustomFields = displayFields; byte[] templateData = File.ReadAllBytes(templatePath); MemoryStream stream = new MemoryStream(); stream.Write(templateData, 0, (int)templateData.Length); using (IExportFile export = ExportFileFactory.Current.Create(typeof(StudentProfileExportFile))) { var mapper = export.GenerateMapper(); List<IEnumerable<object>> data = new List<IEnumerable<object>>(); foreach (var student in students) { data.Add(mapper.MapData(configuration, student, user, Auditor)); } export.Create(stream); export.SetupColumnHeaders(mapper.MapColumnHeadings(configuration)); export.FillData(data); export.SetupFooter(CloudConfigurationManager.GetSetting("StudentProfileExportFooter")); RepositoryContainer.Save(); } return stream; }
public void WhenConstruct_ThenSelectedServiceTypesNotNull() { var target = new StudentProfileExportFieldDescriptor(); Assert.IsNotNull(target.SelectedServiceTypes); }
public void GivenSelectedCustomFields_WhenMapData_ThenUserHasNewPrivateHealthDataViewEvents() { Student student = TestData.Students[0]; List<object> expected = new List<object> { student.School.Name, student.Grade, student.FullName, student.Id, null, null, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value }; var model = new StudentProfileExportFieldDescriptor { SelectedCustomFields = TestData.CustomFields }; PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(MockRepository.GenerateMock<IViewStudentDetailPermission>()); MockUserAuditor.Expect(m => m.CreatePrivateHealthInfoViewEvent(User.Identity.User, student.CustomFieldValues.ToList())).Return(new PrivateHealthDataViewEvent()); var actual = Target.MapData(model, student, User, MockUserAuditor); Assert.AreEqual(1, User.Identity.User.PrivateHealthDataViewEvents.Count()); }
private static void MapStandardData(StudentProfileExportFieldDescriptor fieldConfiguration, Student data, List<object> dataList, bool directoryLevelOnly) { if (fieldConfiguration.BirthDateIncluded) { dataList.Add(directoryLevelOnly ? null : data.DateOfBirth); } if (fieldConfiguration.ParentNameIncluded) { dataList.Add(directoryLevelOnly ? null : data.Parents); } }
private static void MapStandardFieldHeadings(StudentProfileExportFieldDescriptor fieldConfiguration, List<string> columnHeadings) { if (fieldConfiguration.BirthDateIncluded) { columnHeadings.Add("Birth Date"); } if (fieldConfiguration.ParentNameIncluded) { columnHeadings.Add("Parent Name"); } }
private bool AssertDescriptorMatches(StudentProfileExportModel expectedState, StudentProfileExportFieldDescriptor actualState) { Assert.AreEqual(expectedState.BirthDateIncluded, actualState.BirthDateIncluded); Assert.AreEqual(expectedState.ParentNameIncluded, actualState.ParentNameIncluded); CollectionAssert.AreEqual(Repositories.MockCustomFieldRepository.Items.Where(c => expectedState.SelectedCustomFieldIds.Contains(c.Id)).ToList(), actualState.SelectedCustomFields.ToList()); CollectionAssert.AreEqual(Repositories.MockServiceTypeRepository.Items.Where(c => expectedState.SelectedServiceTypeIds.Contains(c.Id)).ToList(), actualState.SelectedServiceTypes.ToList()); return true; }
public void WhenConstruct_ThenSelectedCustomFieldsNotNull() { var target = new StudentProfileExportFieldDescriptor(); Assert.IsNotNull(target.SelectedCustomFields); }