Beispiel #1
0
        public void GivenModel_AndServiceTypeSelected_WhenGenerateStudentProfileExport_ThenFileContainsServiceTypeValue()
        {
            StudentProfileExportModel model = new StudentProfileExportModel
            {
                SelectedServiceTypeIds = new List <int> {
                    2
                },
                SelectedSchoolIds = new List <int> {
                    EducationContext.Schools.First().Id
                },
                SelectedGrades = new List <int> {
                    10, 12
                }
            };
            string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx");

            var result = Target.GenerateStudentProfileExport(User, model, @"TestData\StudentProfileExportTemplate.xltx") as MemoryStream;

            File.WriteAllBytes(outputPath, result.ToArray());
            using (var workbook = new XLWorkbook(outputPath))
            {
                IXLWorksheet worksheet = workbook.Worksheet(1);
                Assert.AreEqual("Big Brothers, Big Sisters Provide College Access/One on One Activities", worksheet.Cell("E3").Value);
            }
        }
Beispiel #2
0
        public void GivenModel_AndCustomFieldSelected_WhenGenerateStudentProfileExport_ThenFileContainsCustomFieldValue()
        {
            StudentProfileExportModel model = new StudentProfileExportModel
            {
                SelectedCustomFieldIds = new List <int> {
                    EducationContext.CustomFields.Where(c => c.Name == "Tardies").Single().Id
                },
                SelectedSchoolIds = new List <int> {
                    EducationContext.Schools.First().Id
                },
                SelectedGrades = new List <int> {
                    10, 12
                }
            };
            string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx");

            var result = Target.GenerateStudentProfileExport(User, model, @"TestData\StudentProfileExportTemplate.xltx") as MemoryStream;

            File.WriteAllBytes(outputPath, result.ToArray());
            using (var workbook = new XLWorkbook(outputPath))
            {
                IXLWorksheet worksheet = workbook.Worksheet(1);
                Assert.AreEqual("1200", worksheet.Cell("E3").Value);
            }
        }
Beispiel #3
0
        public void GivenModel_WhenGenerateStudentProfileExport_ThenStreamReturnedContainsExcelFile()
        {
            StudentProfileExportModel model = new StudentProfileExportModel
            {
                SelectedCustomFieldIds = new List <int> {
                    EducationContext.CustomFields.First().Id
                },
                SelectedServiceTypeIds = new List <int> {
                    EducationContext.ServiceTypes.First().Id
                },
                SelectedSchoolIds = new List <int> {
                    EducationContext.Schools.First().Id
                },
                SelectedGrades = new List <int> {
                    10, 12
                }
            };
            string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx");

            var result = Target.GenerateStudentProfileExport(User, model, @"TestData\StudentProfileExportTemplate.xltx") as MemoryStream;

            Assert.IsNotNull(result);
            File.WriteAllBytes(outputPath, result.ToArray());
            using (var workbook = new XLWorkbook(outputPath))
            {
                Assert.IsNotNull(workbook);
            }
        }
Beispiel #4
0
        public void GivenDefaultModel_WhenRetrieveStudentsList_ThenStudentAssignedOfferingsDataIncluded()
        {
            var defaultModel = new StudentProfileExportModel();

            var actual = Target.RetrieveStudentsList(defaultModel);

            Assert.IsTrue(actual.Any(s => s.StudentAssignedOfferings.Where(a => a.ServiceOffering.Program != null && a.ServiceOffering.Provider != null && a.ServiceOffering.ServiceType != null).Count() > 0));
        }
Beispiel #5
0
        public void GivenDefaultModel_WhenRetrieveStudentsList_ThenApprovedProvidersIncluded()
        {
            var defaultModel = new StudentProfileExportModel();

            var actual = Target.RetrieveStudentsList(defaultModel);

            Assert.IsTrue(actual.Any(s => s.ApprovedProviders.Count > 0));
        }
Beispiel #6
0
 public void CheckStudentCount(StudentProfileExportModel model, int studentCountLimit)
 {
     if (StudentRepository.Items.Where(st => (model.SelectedSchoolIds.Count() == 0 ||
                                              model.SelectedSchoolIds.Contains(st.SchoolId)) &&
                                       (model.SelectedGrades.Count() == 0 ||
                                        model.SelectedGrades.Contains(st.Grade))).Count() > studentCountLimit)
     {
         throw new ArgumentOutOfRangeException("Result set to be returned will be higher than the file size limits will allow.");
     }
 }
Beispiel #7
0
        public void GivenTooManyStudents_WhenGenerateStudentProfileExport_ThenPartialViewResultReturned()
        {
            StudentProfileExportModel model = new StudentProfileExportModel();

            MockLogicManager.Expect(m => m.CheckStudentCount(model, 65000)).Throw(new ArgumentOutOfRangeException("blah"));

            var result = Target.StudentProfileExport(model) as PartialViewResult;

            Assert.IsNotNull(result);
        }
Beispiel #8
0
        public void GivenDataExtractModelWithSelectedServiceTypes_WhenRetreiveStudentsList_ThenStudentAssignedOfferingsIncluded()
        {
            StudentProfileExportModel model = new StudentProfileExportModel {
                SelectedServiceTypeIds = EducationContext.ServiceTypes.Select(t => t.Id)
            };

            var result = Target.RetrieveStudentsList(model);

            Assert.IsTrue(result.First().StudentAssignedOfferings.Count() > 0);
        }
Beispiel #9
0
        public void GivenDataExtractModelWithSelectedCustomFields_WhenRetrieveStudentsList_ThenCustomFieldsIncluded()
        {
            StudentProfileExportModel model = new StudentProfileExportModel {
                SelectedCustomFieldIds = EducationContext.CustomFields.Select(f => f.Id)
            };

            var result = Target.RetrieveStudentsList(model);

            Assert.IsTrue(result.Any(r => r.CustomFieldValues.Count > 0));
        }
Beispiel #10
0
        public void GivenModel_WhenGenerateStudentProfileExport_ThenFileResultReturned()
        {
            StudentProfileExportModel model = new StudentProfileExportModel();
            string templatePath             = Path.Combine(UploadTemplateFolderPath, DataFileController.TemplateFile);

            MockLogicManager.Expect(m => m.GenerateStudentProfileExport(User, model, templatePath)).Return(new MemoryStream());

            var result = Target.StudentProfileExport(model) as FileStreamResult;

            Assert.IsNotNull(result);
        }
Beispiel #11
0
        public void GivenModel_WhenGenerateStudentProfileExport_ThenFileResultUsesValidContentType()
        {
            StudentProfileExportModel model = new StudentProfileExportModel();
            string templatePath             = Path.Combine(UploadTemplateFolderPath, DataFileController.TemplateFile);
            Stream expected = new MemoryStream();

            MockLogicManager.Expect(m => m.GenerateStudentProfileExport(User, model, templatePath)).Return(expected);

            var result = Target.StudentProfileExport(model) as FileStreamResult;

            Assert.AreEqual(ExcelWriter.ContentType, result.ContentType);
        }
Beispiel #12
0
        public IEnumerable <Student> RetrieveStudentsList(StudentProfileExportModel model)
        {
            IQueryable <Student> students = StudentRepository.Items.
                                            Include(s => s.School).
                                            Include(s => s.ApprovedProviders).
                                            Include("CustomFieldValues.CustomDataOrigin").
                                            Include("StudentAssignedOfferings.ServiceOffering.ServiceType").
                                            Include("StudentAssignedOfferings.ServiceOffering.Provider").
                                            Include("StudentAssignedOfferings.ServiceOffering.Program");

            return(students.Where(st => (!model.SelectedSchoolIds.Any() || model.SelectedSchoolIds.Contains(st.SchoolId))
                                  &&
                                  (!model.SelectedGrades.Any() || model.SelectedGrades.Contains(st.Grade))));
        }
        public ActionResult StudentProfileExport(StudentProfileExportModel model)
        {
            try
            {
                LogicManager.CheckStudentCount(model, 65000);
            }
            catch (ArgumentOutOfRangeException)
            {
                ModelState.AddModelError("RowCount", "Export will generate more than the maximum amount of records");
                return(PartialView(model));
            }
            MemoryStream stream = LogicManager.GenerateStudentProfileExport((EducationSecurityPrincipal)User, model, TemplatePath) as MemoryStream;

            stream.Position = 0;
            return(File(stream, ExcelWriter.ContentType));
        }
Beispiel #14
0
        public void GivenModel_AndAllFieldsSelected_AndAllSchoolsSelected_WhenGenerateStudentProfileExport_ThenFileContainsServiceTypeValue()
        {
            StudentProfileExportModel model = new StudentProfileExportModel
            {
                SelectedServiceTypeIds = EducationContext.ServiceTypes.Select(t => t.Id).ToList(),
                SelectedSchoolIds      = EducationContext.Schools.Select(s => s.Id).ToList(),
                SelectedCustomFieldIds = EducationContext.CustomFields.Select(f => f.Id).ToList(),
                BirthDateIncluded      = true,
                ParentNameIncluded     = true
            };
            string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx");

            var result = Target.GenerateStudentProfileExport(User, model, @"TestData\StudentProfileExportTemplate.xltx") as MemoryStream;

            File.WriteAllBytes(outputPath, result.ToArray());
            using (var workbook = new XLWorkbook(outputPath))
            {
                Assert.IsNotNull(workbook);
            }
        }
Beispiel #15
0
        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);
        }