public async Task ExportsController_GetCoursesPartialTest() { AuthenticationHelper.HttpContext = AuthenticationHelper.CreateHttpContext(true); ExportsController controller = new ExportsController(); SetupController(controller); ExportsViewModel defaultExportViewModel = await GetDefaultExportsViewModel(); var defaultResult = await controller.Index(); Assert.IsNotNull(defaultResult, "invalid result"); Assert.IsInstanceOfType(defaultResult, typeof(ViewResult), "Unexpected result type"); ViewResult defaultViewResult = defaultResult as ViewResult; Assert.IsNotNull(defaultViewResult.Model, "Invalid model result"); Assert.IsInstanceOfType(defaultViewResult.Model, typeof(ExportsViewModel), "Unexpected model type"); ExportsViewModel modelResult = defaultViewResult.Model as ExportsViewModel; var schoolIds = modelResult.SchoolsCriteriaSection.FilterCheckboxes.Select(p => p.SchoolId).ToList(); var partialResult = await controller.GetPreviewCoursesJsonString(0); Assert.IsNotNull(partialResult, "Invalid result"); Assert.IsInstanceOfType(partialResult, typeof(JsonResult), "Unexpected result type"); JsonResult partialViewResult = partialResult as JsonResult; Assert.IsNotNull(partialViewResult.Data, "Invalid model"); Assert.IsInstanceOfType(partialViewResult.Data, typeof(ViewModels.DataPreviewPagedJsonModel), "Unexpected model type"); ViewModels.DataPreviewPagedJsonModel apiCriteriaResult = partialViewResult.Data as ViewModels.DataPreviewPagedJsonModel; Assert.IsTrue(apiCriteriaResult.TotalPages > 0, "No data found"); }
public async Task ExportsController_GetSectionsPartialTest() { AuthenticationHelper.HttpContext = AuthenticationHelper.CreateHttpContext(true); ExportsController controller = new ExportsController(); SetupController(controller); ExportsViewModel defaultExportViewModel = await GetDefaultExportsViewModel(); var defaultResult = await controller.Index(); Assert.IsNotNull(defaultResult, "invalid result"); Assert.IsInstanceOfType(defaultResult, typeof(ViewResult), "Unexpected result type"); ViewResult defaultViewResult = defaultResult as ViewResult; Assert.IsNotNull(defaultViewResult.Model, "Invalid model result"); Assert.IsInstanceOfType(defaultViewResult.Model, typeof(ExportsViewModel), "Unexpected model type"); ExportsViewModel modelResult = defaultViewResult.Model as ExportsViewModel; var schoolIds = modelResult.SchoolsCriteriaSection.FilterCheckboxes.Select(p => p.SchoolId).ToList(); var partialResult = await controller.GetSectionsPartial(schoolIds : schoolIds, boxesAlreadyChecked : null, getMore : false); Assert.IsNotNull(partialResult, "Invalid result"); Assert.IsInstanceOfType(partialResult, typeof(PartialViewResult), "Unexpected result type"); PartialViewResult partialViewResult = partialResult as PartialViewResult; Assert.IsNotNull(partialViewResult.Model, "Invalid model"); Assert.IsInstanceOfType(partialViewResult.Model, typeof(ApiCriteriaSection), "Unexpected model type"); ApiCriteriaSection apiCriteriaResult = partialViewResult.Model as ApiCriteriaSection; Assert.IsTrue(apiCriteriaResult.FilterCheckboxes.Count > 0, "No data found"); }
public async Task ExportsController_PreviewTest() { Assert.Inconclusive("Unit test has infinite looping"); AuthenticationHelper.HttpContext = AuthenticationHelper.CreateHttpContext(true); ExportsController exportsController = new ExportsController(); SetupController(exportsController); ExportsViewModel defaultExportsViewModel = await GetDefaultExportsViewModel(); var previewResult = await exportsController.Preview( schoolIds : defaultExportsViewModel.SelectedSchools.Split(',').ToList(), //schoolYears: null, //terms: null, //subjects: null, //courses: defaultExportsViewModel.SelectedCourses.Split(',').ToList(), teachers : null, sections : null, oneRosterVersion : null ); Assert.IsNotNull(previewResult, "Invalid result"); Assert.IsInstanceOfType(previewResult, typeof(PartialViewResult), "Invalid result type"); PartialViewResult partialViewResult = previewResult as PartialViewResult; Assert.IsNotNull(partialViewResult.Model, "Invalid model"); Assert.IsInstanceOfType(partialViewResult.Model, typeof(ExportsViewModel), "Unexpected type for model"); ExportsViewModel partialResultModel = partialViewResult.Model as ExportsViewModel; Assert.IsTrue(partialResultModel.DataPreviewSections.Count > 0, "No Data Preview Sections"); Assert.IsTrue(partialResultModel.JsonPreviews.Orgs.Count() > 0, "No Orgs for JsonPreview"); }
public void TestInitialize() { _reportsServ = new Mock <IReportsV2Service>(); _tenantServ = new Mock <ITenantService>(); _tenantServ.Setup(s => s.GetCurrentTenant()) .Returns(UnitTestExtensions.TestingTenant); _controller = new ExportsController(_reportsServ.Object, _tenantServ.Object); _controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; }
public async Task ExportsController_DownloadCsvTest() { AuthenticationHelper.HttpContext = AuthenticationHelper.CreateHttpContext(true); ExportsController controller = new ExportsController(); SetupController(controller); //ExportsViewModel defaultExportViewModel = await GetDefaultExportsViewModel(); ExportsViewModel defaultExportViewModel = new ExportsViewModel(); var defaultResult = await controller.DownloadCsv(defaultExportViewModel); Assert.IsNotNull(defaultResult, "Invalid Result"); Assert.IsInstanceOfType(defaultResult, typeof(FileContentResult), "Is not a FileResult"); FileContentResult fileResult = defaultResult as FileContentResult; Assert.IsTrue(!string.IsNullOrWhiteSpace(fileResult.FileDownloadName), "Invalid File Name"); Assert.IsTrue(fileResult.FileContents != null && fileResult.FileContents.Count() > 0, "Invalid File Contents"); List <string> lstInvalidFileNames = new List <string>(); using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(fileResult.FileContents)) { System.IO.Compression.ZipArchive zipArchive = new ZipArchive(memStream); string[] validFileNames = { "orgs.csv", "users.csv", "courses.csv", "classes.csv", "enrollments.csv", "academicSessions.csv", "demographics.csv" }; foreach (var singleEntry in zipArchive.Entries) { if (!validFileNames.Contains(singleEntry.Name)) { lstInvalidFileNames.Add(singleEntry.Name); } //For Validation rules check https://docs.google.com/spreadsheets/d/1X-gX06CaeDwDn5-Q-pqVAVahgJRtQqFOx5jj3FtIHKs/edit#gid=0 ValidateFileContents(singleEntry); } memStream.Close(); } if (lstInvalidFileNames.Count > 0) { Assert.Fail("Invalid File Names: " + String.Join(",", lstInvalidFileNames.ToArray())); } //var zipFile = System.IO.Compression.ZipFile }
public async Task ExportsController_IndexTest() { AuthenticationHelper.HttpContext = AuthenticationHelper.CreateHttpContext(true); ExportsController controller = new ExportsController(); SetupController(controller); ExportsViewModel defaultExportViewModel = await GetDefaultExportsViewModel(); var defaultResult = await controller.Index(); Assert.IsNotNull(defaultResult, "invalid result"); Assert.IsInstanceOfType(defaultResult, typeof(ViewResult), "Unexpected result type"); ViewResult defaultViewResult = defaultResult as ViewResult; Assert.IsNotNull(defaultViewResult.Model, "Invalid model result"); Assert.IsInstanceOfType(defaultViewResult.Model, typeof(ExportsViewModel), "Unexpected model type"); ExportsViewModel modelResult = defaultViewResult.Model as ExportsViewModel; Assert.IsTrue(modelResult.SchoolsCriteriaSection.FilterCheckboxes != null && modelResult.SchoolsCriteriaSection.FilterCheckboxes.Count > 0, "No data for Schools Criteria"); }
public async Task ExportsController_SaveTemplate() { AuthenticationHelper.HttpContext = AuthenticationHelper.CreateHttpContext(true); ExportsController controller = new ExportsController(); SetupController(controller); //ExportsViewModel defaultExportViewModel = await GetDefaultExportsViewModel(); DateTime currentTime = DateTime.UtcNow; ExportsViewModel defaultExportViewModel = await GetDefaultExportsViewModel(); defaultExportViewModel.NewTemplateName = string.Format("[UNIT TEST TEMPLATE]-{0}", currentTime); defaultExportViewModel.NewTemplateVendorName = string.Format("[UNIT TEST VENDOR]-{0}", currentTime); var result = controller.SaveTemplate(defaultExportViewModel); Assert.IsNotNull(result, "Invalid result"); if (result is RedirectToRouteResult) { RedirectToRouteResult redirecResult = result as RedirectToRouteResult; Assert.IsTrue(redirecResult.RouteValues["action"].ToString() == "Index" && redirecResult.RouteValues["controller"].ToString() == "Templates"); } else { Assert.Fail("Unexpected result"); } var templateToDelete = AuthenticationHelper.DB.Templates.Where(p => p.VendorName == defaultExportViewModel.NewTemplateVendorName && p.TemplateName == defaultExportViewModel.NewTemplateName).FirstOrDefault(); if (templateToDelete != null) { AuthenticationHelper.DB.Templates.Remove(templateToDelete); if ( AuthenticationHelper.DB.SaveChanges() == 0) { Assert.Fail("Unable to delete template: " + defaultExportViewModel.NewTemplateName); } } }