public void IndexModeTest(bool isAdmin, string mode, int batchSizeForImport) { // Assign A.CallTo(() => fakeReportAuditRepository.GetAllAuditRecords()).Returns(GetAuditRecords()); A.CallTo(() => fakeImportSkillsFrameworkDataService.ImportFrameworkSkills()).Returns(new FrameworkSkillsImportResponse()); var skillsFrameworkDataImportController = GetSkillsFrameworkDataImportController(isAdmin, batchSizeForImport); // Act var indexMethodCall = skillsFrameworkDataImportController.WithCallTo(c => c.Index(mode)); // Assert if (isAdmin) { indexMethodCall .ShouldRenderView("ImportResults") .WithModel <SkillsFrameworkResultsViewModel>(vm => { vm.FirstParagraph.Should().BeEquivalentTo(skillsFrameworkDataImportController.FirstParagraph); vm.IsAdmin.Should().Be(fakeWebAppContext.IsUserAdministrator); vm.NotAllowedMessage.Should().BeEquivalentTo(skillsFrameworkDataImportController.NotAllowedMessage); vm.PageTitle.Should().BeEquivalentTo(skillsFrameworkDataImportController.PageTitle); vm.AuditRecords.Should().BeEquivalentTo(fakeReportAuditRepository.GetAllAuditRecords()); }) .AndNoModelErrors(); switch (mode?.ToUpperInvariant().Trim()) { case "IMPORTSKILLS": A.CallTo(() => fakeImportSkillsFrameworkDataService.ImportFrameworkSkills()).MustHaveHappened(); break; case "UPDATESOCOCCUPATIONALCODES": A.CallTo(() => fakeImportSkillsFrameworkDataService.UpdateSocCodesOccupationalCode()).MustHaveHappened(); break; case "RESETSOCIMPORTALLSTATUS": A.CallTo(() => fakeImportSkillsFrameworkDataService.ResetAllSocStatus()).MustHaveHappened(); break; case "RESETSOCIMPORTSTARTEDSTATUS": A.CallTo(() => fakeImportSkillsFrameworkDataService.ResetStartedSocStatus()).MustHaveHappened(); break; case "EXPORTNEWONETMAPPINGS": A.CallTo(() => fakeImportSkillsFrameworkDataService.ExportNewONetMappings()).MustHaveHappened(); break; default: A.CallTo(() => fakeImportSkillsFrameworkDataService.UpdateSocCodesOccupationalCode()).MustNotHaveHappened(); A.CallTo(() => fakeImportSkillsFrameworkDataService.ImportFrameworkSkills()).MustNotHaveHappened(); break; } A.CallTo(() => fakeWebAppContext.IsUserAdministrator).MustHaveHappened(); A.CallTo(() => fakeReportAuditRepository.GetAllAuditRecords()).MustHaveHappened(); A.CallTo(() => fakeImportSkillsFrameworkDataService.GetSocMappingStatus()).MustHaveHappened(); A.CallTo(() => fakeImportSkillsFrameworkDataService.GetNextBatchOfSOCsToImport(10)).MustHaveHappened(); } else { indexMethodCall .ShouldRenderView("ImportResults") .WithModel <SkillsFrameworkResultsViewModel>(vm => { vm.FirstParagraph.Should().BeEquivalentTo(skillsFrameworkDataImportController.FirstParagraph); vm.IsAdmin.Should().Be(fakeWebAppContext.IsUserAdministrator); vm.NotAllowedMessage.Should().BeEquivalentTo(skillsFrameworkDataImportController.NotAllowedMessage); vm.PageTitle.Should().BeEquivalentTo(skillsFrameworkDataImportController.PageTitle); vm.OtherMessage.Should().BeEquivalentTo(skillsFrameworkDataImportController.NotAllowedMessage); vm.AuditRecords.Should().BeEquivalentTo(fakeReportAuditRepository.GetAllAuditRecords()); }).AndNoModelErrors(); } }
public ActionResult Index(string importMode) { var importResult = new SkillsFrameworkResultsViewModel { PageTitle = PageTitle, FirstParagraph = FirstParagraph, NotAllowedMessage = NotAllowedMessage, IsAdmin = webAppContext.IsUserAdministrator, SocMappingStatus = importSkillsFrameworkDataService.GetSocMappingStatus(), NextBatchOfSOCsToImport = importSkillsFrameworkDataService.GetNextBatchOfSOCsToImport(BatchSizeForImport) }; var otherMessage = string.Empty; if (webAppContext.IsUserAdministrator) { try { switch (importMode?.ToUpperInvariant().Trim()) { case "IMPORTSKILLS": importSkillsFrameworkDataService.ImportFrameworkSkills(); importResult.ActionCompleted = "Imported Onet Skills"; break; case "UPDATESOCOCCUPATIONALCODES": importSkillsFrameworkDataService.UpdateSocCodesOccupationalCode(); importResult.ActionCompleted = "Updated SOC with Onet Occupational Codes"; break; case "RESETSOCIMPORTALLSTATUS": importSkillsFrameworkDataService.ResetAllSocStatus(); importResult.ActionCompleted = "Import status for all SOCs has been reset "; break; case "RESETSOCIMPORTSTARTEDSTATUS": importSkillsFrameworkDataService.ResetStartedSocStatus(); importResult.ActionCompleted = "Import status for Started SOCs has been reset "; break; case "EXPORTNEWONETMAPPINGS": importSkillsFrameworkDataService.ExportNewONetMappings(); importResult.ActionCompleted = "New SOC to ONet mappings exported"; break; default: importResult.ActionCompleted = "Action unknown - no process was run."; break; } } catch (Exception ex) { otherMessage = $"{ex.Message} <br /> {ex.InnerException} <br /> {ex.StackTrace}"; } } else { otherMessage = NotAllowedMessage; } importResult.AuditRecords = reportAuditRepository.GetAllAuditRecords(); importResult.OtherMessage = otherMessage; return(View("ImportResults", importResult)); }