From 7736af11ce45556b92b170aea38fdba148ec4bd6 Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 17:46:04 +0100 Subject: [PATCH 1/8] ReSharper cleanup: whitespace, indentation, redundant parentheses. --- .../Program.cs | 428 +++++++++--------- .../Constants/QuestionPages.cs | 3 +- .../Entities/AccessibilityStatementPage.cs | 2 +- .../Entities/AdvicePage.cs | 2 +- .../Entities/CookiesPage.cs | 2 +- .../Entities/DateQuestionPage.cs | 2 +- .../Entities/DetailsPage.cs | 2 +- .../Entities/DropdownQuestionPage.cs | 2 +- .../Entities/QualificationListPage.cs | 2 +- .../Entities/RadioQuestionPage.cs | 2 +- .../Services/ContentfulContentService.cs | 4 +- .../Content/MockContentfulFilterService.cs | 41 +- .../Content/MockContentfulService.cs | 62 +-- .../AccessibilityStatementController.cs | 2 +- .../Controllers/AdviceController.cs | 2 +- .../ConfirmQualificationController.cs | 12 +- .../Controllers/HomeController.cs | 4 +- .../QualificationDetailsController.cs | 6 +- .../Controllers/QuestionsController.cs | 92 ++-- .../AccessibilityStatementPageModel.cs | 2 +- .../Models/Content/AdvicePageModel.cs | 2 +- .../Models/Content/CookiesPageModel.cs | 7 +- .../Content/QualificationDetailsModel.cs | 2 +- .../Models/Content/QualificationListModel.cs | 4 +- .../QuestionModels/BaseQuestionModel.cs | 2 +- .../QuestionModels/DateQuestionModel.cs | 24 +- .../QuestionModels/DropdownQuestionModel.cs | 4 +- .../QuestionModels/RadioQuestionModel.cs | 5 +- .../Models/UserJourneyModel.cs | 8 +- .../Security/SecureHeaderConfiguration.cs | 14 +- .../CookiesPreferenceService.cs | 3 +- .../ICookiesPreferenceService.cs | 2 +- .../IUserJourneyCookieService.cs | 2 +- .../UserJourneyCookieService.cs | 5 +- .../Views/AccessibilityStatement/Index.cshtml | 2 +- .../Views/Advice/Advice.cshtml | 2 +- .../Views/Challenge/EntryForm.cshtml | 2 +- .../Views/ConfirmQualification/index.cshtml | 2 +- .../Views/CookiesPreference/Index.cshtml | 90 ++-- .../Views/QualificationDetails/Get.cshtml | 4 +- .../Views/QualificationDetails/Index.cshtml | 2 +- .../Views/Questions/Date.cshtml | 18 +- .../Views/Questions/Dropdown.cshtml | 20 +- .../Views/Questions/Radio.cshtml | 2 +- .../Views/Shared/_Header.cshtml | 3 +- .../Controllers/AdviceControllerTests.cs | 8 +- .../ConfirmQualificationControllerTests.cs | 403 +++++++++-------- .../Controllers/CookiesControllerTests.cs | 40 +- .../Controllers/HomeControllerTests.cs | 6 +- .../QualificationDetailsControllerTests.cs | 48 +- .../Controllers/QuestionsControllerTests.cs | 246 +++++----- .../Extensions/MockLoggerExtensions.cs | 2 +- .../Mocks/MockContentfulFilterServiceTests.cs | 17 +- .../Mocks/MockContentfulServiceTests.cs | 2 +- .../Services/UserJourneyCookieServiceTests.cs | 10 +- .../Setup/MockContentfulSetupTests.cs | 4 +- 56 files changed, 882 insertions(+), 809 deletions(-) diff --git a/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs b/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs index 0ae43a9f..8ddc4ad8 100644 --- a/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs +++ b/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs @@ -12,129 +12,139 @@ namespace Dfe.EarlyYearsQualification.ContentUpload; [ExcludeFromCodeCoverage] public class Program { - private const string Locale = "en-US"; - private const string SpaceId = ""; - private const string ManagementApiKey = ""; + private const string Locale = "en-US"; + private const string SpaceId = ""; + private const string ManagementApiKey = ""; - public static async Task Main(string[] args) - { - var client = new ContentfulManagementClient(new HttpClient(), new ContentfulOptions + public static async Task Main(string[] args) { - ManagementApiKey = ManagementApiKey, - SpaceId = SpaceId, - MaxNumberOfRateLimitRetries = 10, - }); + var client = new ContentfulManagementClient(new HttpClient(), + new ContentfulOptions + { + ManagementApiKey = ManagementApiKey, + SpaceId = SpaceId, + MaxNumberOfRateLimitRetries = 10 + }); - await SetUpContentModels(client); + await SetUpContentModels(client); - await PopulateContentfulWithQualifications(client); - } + await PopulateContentfulWithQualifications(client); + } - private static async Task PopulateContentfulWithQualifications(ContentfulManagementClient client) - { - // Check existing entries and identify those to update, and those to create. - var currentEntries = await client.GetEntriesForLocale(new QueryBuilder>().ContentTypeIs("Qualification").Limit(1000), Locale); + private static async Task PopulateContentfulWithQualifications(ContentfulManagementClient client) + { + // Check existing entries and identify those to update, and those to create. + var currentEntries = + await + client.GetEntriesForLocale(new QueryBuilder>().ContentTypeIs("Qualification").Limit(1000), + Locale); - var qualificationsToAddOrUpdate = GetQualificationsToAddOrUpdate(); + var qualificationsToAddOrUpdate = GetQualificationsToAddOrUpdate(); - foreach (var qualification in qualificationsToAddOrUpdate) - { - var entryToAddOrUpdate = BuildEntryFromQualification(qualification); - var existingEntry = currentEntries.FirstOrDefault(x => x.SystemProperties.Id == qualification.QualificationId); + foreach (var qualification in qualificationsToAddOrUpdate) + { + var entryToAddOrUpdate = BuildEntryFromQualification(qualification); + var existingEntry = + currentEntries.FirstOrDefault(x => x.SystemProperties.Id == qualification.QualificationId); - if (existingEntry != null) - { - // Update existing entry - entryToAddOrUpdate.SystemProperties.Version = existingEntry.SystemProperties.Version!.Value; - } + if (existingEntry != null) + { + // Update existing entry + entryToAddOrUpdate.SystemProperties.Version = existingEntry.SystemProperties.Version!.Value; + } - // Create new entry - var entryToPublish = await client.CreateOrUpdateEntry(entryToAddOrUpdate, contentTypeId: "Qualification", version: entryToAddOrUpdate.SystemProperties.Version); + // Create new entry + var entryToPublish = await client.CreateOrUpdateEntry(entryToAddOrUpdate, contentTypeId: "Qualification", + version: entryToAddOrUpdate.SystemProperties.Version); - await client.PublishEntry(entryToPublish.SystemProperties.Id, entryToPublish.SystemProperties.Version!.Value); + await client.PublishEntry(entryToPublish.SystemProperties.Id, + entryToPublish.SystemProperties.Version!.Value); + } } - } - private static async Task SetUpContentModels(ContentfulManagementClient client) + private static async Task SetUpContentModels(ContentfulManagementClient client) { // Check current version of model var currentModels = await client.GetContentTypes(); var currentModel = currentModels.FirstOrDefault(x => x.SystemProperties.Id == "Qualification"); - var version = currentModel != null && currentModel.SystemProperties.Version != null ? currentModel.SystemProperties.Version!.Value : 1; + var version = currentModel != null && currentModel.SystemProperties.Version != null + ? currentModel.SystemProperties.Version!.Value + : 1; var contentType = new ContentType - { - SystemProperties = new SystemProperties - { - Id = "Qualification", - }, - Name = "Qualification", - Description = "Model for storing all the early years qualifications", - DisplayField = "qualificationName", - Fields = - [ - new Field() - { - Name = "Qualification ID", - Id = "qualificationId", - Type = "Symbol", - Required = true, - Validations = new List() { - new UniqueValidator() - } - }, - new Field() - { - Name = "Qualification Name", - Id = "qualificationName", - Type = "Symbol", - Required = true, - }, - new Field() - { - Name = "Qualification Level", - Id = "qualificationLevel", - Type = "Integer", - Required = true, - }, - new Field() - { - Name = "Awarding Organisation Title", - Id = "awardingOrganisationTitle", - Type = "Symbol", - Required = true, - }, - new Field() - { - Name = "From Which Year", - Id = "fromWhichYear", - Type = "Symbol", - }, - new Field() - { - Name = "To Which Year", - Id = "toWhichYear", - Type = "Symbol", - }, - new Field() - { - Name = "Qualification Number", - Id = "qualificationNumber", - Type = "Symbol", - }, - new Field() - { - Name = "Additional Requirements", - Id = "additionalRequirements", - Type = "Text", - }, - ] - }; + { + SystemProperties = new SystemProperties + { + Id = "Qualification" + }, + Name = "Qualification", + Description = "Model for storing all the early years qualifications", + DisplayField = "qualificationName", + Fields = + [ + new Field + { + Name = "Qualification ID", + Id = "qualificationId", + Type = "Symbol", + Required = true, + Validations = new List + { + new UniqueValidator() + } + }, + new Field + { + Name = "Qualification Name", + Id = "qualificationName", + Type = "Symbol", + Required = true + }, + new Field + { + Name = "Qualification Level", + Id = "qualificationLevel", + Type = "Integer", + Required = true + }, + new Field + { + Name = "Awarding Organisation Title", + Id = "awardingOrganisationTitle", + Type = "Symbol", + Required = true + }, + new Field + { + Name = "From Which Year", + Id = "fromWhichYear", + Type = "Symbol" + }, + new Field + { + Name = "To Which Year", + Id = "toWhichYear", + Type = "Symbol" + }, + new Field + { + Name = "Qualification Number", + Id = "qualificationNumber", + Type = "Symbol" + }, + new Field + { + Name = "Additional Requirements", + Id = "additionalRequirements", + Type = "Text" + } + ] + }; var typeToActivate = await client.CreateOrUpdateContentType(contentType, version: version); - await client.ActivateContentType("Qualification", version: typeToActivate.SystemProperties.Version!.Value); + await client.ActivateContentType("Qualification", typeToActivate.SystemProperties.Version!.Value); Thread.Sleep(2000); // Allows the API time to activate the content type await SetHelpText(client, typeToActivate); @@ -143,130 +153,138 @@ private static async Task SetUpContentModels(ContentfulManagementClient client) private static async Task SetHelpText(ContentfulManagementClient client, ContentType typeToActivate) { var editorInterface = await client.GetEditorInterface("Qualification"); - SetHelpTextForField(editorInterface, "qualificationId", "The unique identifier used to reference the qualification"); + SetHelpTextForField(editorInterface, "qualificationId", + "The unique identifier used to reference the qualification"); SetHelpTextForField(editorInterface, "qualificationName", "The name of the qualification"); - SetHelpTextForField(editorInterface, "qualificationLevel", "The level of the qualification", SystemWidgetIds.NumberEditor); + SetHelpTextForField(editorInterface, "qualificationLevel", "The level of the qualification", + SystemWidgetIds.NumberEditor); SetHelpTextForField(editorInterface, "awardingOrganisationTitle", "The name of the awarding organisation"); - SetHelpTextForField(editorInterface, "fromWhichYear", "The date from which the qualification is considered full and relevant"); - SetHelpTextForField(editorInterface, "toWhichYear", "The date on which the qualification stops being considered full and relevant"); + SetHelpTextForField(editorInterface, "fromWhichYear", + "The date from which the qualification is considered full and relevant"); + SetHelpTextForField(editorInterface, "toWhichYear", + "The date on which the qualification stops being considered full and relevant"); SetHelpTextForField(editorInterface, "qualificationNumber", "The number of the qualification"); - SetHelpTextForField(editorInterface, "additionalRequirements", "The additional requirements for the qualification", SystemWidgetIds.MultipleLine); + SetHelpTextForField(editorInterface, "additionalRequirements", + "The additional requirements for the qualification", SystemWidgetIds.MultipleLine); - await client.UpdateEditorInterface(editorInterface, "Qualification", typeToActivate.SystemProperties.Version!.Value); + await client.UpdateEditorInterface(editorInterface, "Qualification", + typeToActivate.SystemProperties.Version!.Value); } - private static void SetHelpTextForField(EditorInterface editorInterface, string fieldId, string helpText, string widgetId = SystemWidgetIds.SingleLine) + private static void SetHelpTextForField(EditorInterface editorInterface, string fieldId, string helpText, + string widgetId = SystemWidgetIds.SingleLine) { - editorInterface.Controls.First(x => x.FieldId == fieldId).Settings = new EditorInterfaceControlSettings() { HelpText = helpText }; + editorInterface.Controls.First(x => x.FieldId == fieldId).Settings = + new EditorInterfaceControlSettings { HelpText = helpText }; editorInterface.Controls.First(x => x.FieldId == fieldId).WidgetId = widgetId; } private static Entry BuildEntryFromQualification(Qualification qualification) - { - var entry = new Entry { - SystemProperties = new SystemProperties - { - Id = qualification.QualificationId, - Version = 1 - }, - - Fields = new - { - qualificationId = new Dictionary() - { - { Locale, qualification.QualificationId} - }, - - qualificationName = new Dictionary() - { - { Locale, qualification.QualificationName } - }, - - awardingOrganisationTitle = new Dictionary() - { - { Locale, qualification.AwardingOrganisationTitle } - }, - - qualificationLevel = new Dictionary() - { - { Locale, qualification.QualificationLevel } - }, - - fromWhichYear = new Dictionary() - { - { Locale, qualification.FromWhichYear ?? "" } - }, + var entry = new Entry + { + SystemProperties = new SystemProperties + { + Id = qualification.QualificationId, + Version = 1 + }, + + Fields = new + { + qualificationId = new Dictionary + { + { Locale, qualification.QualificationId } + }, + + qualificationName = new Dictionary + { + { Locale, qualification.QualificationName } + }, + + awardingOrganisationTitle = new Dictionary + { + { Locale, qualification.AwardingOrganisationTitle } + }, + + qualificationLevel = new Dictionary + { + { Locale, qualification.QualificationLevel } + }, + + fromWhichYear = new Dictionary + { + { Locale, qualification.FromWhichYear ?? "" } + }, + + toWhichYear = new Dictionary + { + { Locale, qualification.ToWhichYear ?? "" } + }, + + qualificationNumber = new Dictionary + { + { Locale, qualification.QualificationNumber ?? "" } + }, + + additionalRequirements = new Dictionary + { + { Locale, qualification.AdditionalRequirements ?? "" } + } + } + }; + + return entry; + } - toWhichYear = new Dictionary() - { - { Locale, qualification.ToWhichYear ?? "" } - }, + private static List GetQualificationsToAddOrUpdate() + { + var lines = ReadCsvFile(@"./csv/ey-quals-full-2024-updated.csv"); - qualificationNumber = new Dictionary() - { - { Locale, qualification.QualificationNumber ?? "" } - }, + var listObjResult = new List(); - additionalRequirements = new Dictionary() + foreach (var t in lines) { - { Locale, qualification.AdditionalRequirements ?? "" } - }, - } - }; - - return entry; - } - - private static List GetQualificationsToAddOrUpdate() - { - var lines = ReadCsvFile(@"./csv/ey-quals-full-2024-updated.csv"); - - var listObjResult = new List(); - - foreach (var t in lines) - { - var qualificationId = t[0]; - var qualificationName = t[4]; - var awardingOrganisationTitle = t[5]; - var qualificationLevel = int.Parse(t[1]); - var fromWhichYear = t[2]; - var toWhichYear = t[3]; - var qualificationNumber = t[6]; - var additionalRequirements = t[7]; - - listObjResult.Add(new Qualification( - qualificationId, - qualificationName, - awardingOrganisationTitle, - qualificationLevel, - fromWhichYear, - toWhichYear, - qualificationNumber, - additionalRequirements - )); + var qualificationId = t[0]; + var qualificationName = t[4]; + var awardingOrganisationTitle = t[5]; + var qualificationLevel = int.Parse(t[1]); + var fromWhichYear = t[2]; + var toWhichYear = t[3]; + var qualificationNumber = t[6]; + var additionalRequirements = t[7]; + + listObjResult.Add(new Qualification( + qualificationId, + qualificationName, + awardingOrganisationTitle, + qualificationLevel, + fromWhichYear, + toWhichYear, + qualificationNumber, + additionalRequirements + )); + } + + return listObjResult; } - return listObjResult; - } + private static List ReadCsvFile(string filePath) + { + var result = new List(); + using var csvParser = new TextFieldParser(filePath); + csvParser.SetDelimiters([","]); + csvParser.HasFieldsEnclosedInQuotes = true; - private static List ReadCsvFile(string filePath) - { - var result = new List(); - using var csvParser = new TextFieldParser(filePath); - csvParser.SetDelimiters([","]); - csvParser.HasFieldsEnclosedInQuotes = true; + // Skip the row with the column names + csvParser.ReadLine(); - // Skip the row with the column names - csvParser.ReadLine(); + while (!csvParser.EndOfData) + { + // Read current line fields, pointer moves to the next line. + var fields = csvParser.ReadFields()!; + result.Add(fields); + } - while (!csvParser.EndOfData) - { - // Read current line fields, pointer moves to the next line. - var fields = csvParser.ReadFields()!; - result.Add(fields); + return result; } - - return result; - } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Constants/QuestionPages.cs b/src/Dfe.EarlyYearsQualification.Content/Constants/QuestionPages.cs index 9078d65c..99a32667 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Constants/QuestionPages.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Constants/QuestionPages.cs @@ -2,7 +2,6 @@ namespace Dfe.EarlyYearsQualification.Content.Constants; public static class QuestionPages { - //// Radio Button Pages /// @@ -21,7 +20,7 @@ public static class QuestionPages /// Entry ID for the "When was the qualification started" question page. /// public const string WhenWasTheQualificationStarted = "2o331MBr0R6nsZNBem4yvk"; - + //// Dropdown Pages /// diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/AccessibilityStatementPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/AccessibilityStatementPage.cs index c8780868..ac0b5b5e 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/AccessibilityStatementPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/AccessibilityStatementPage.cs @@ -7,6 +7,6 @@ public class AccessibilityStatementPage public string Heading { get; init; } = string.Empty; public Document? Body { get; init; } - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/AdvicePage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/AdvicePage.cs index b3ec73a3..25081149 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/AdvicePage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/AdvicePage.cs @@ -7,6 +7,6 @@ public class AdvicePage public string Heading { get; init; } = string.Empty; public Document? Body { get; init; } - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/CookiesPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/CookiesPage.cs index 8fa77294..9d077a22 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/CookiesPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/CookiesPage.cs @@ -17,6 +17,6 @@ public class CookiesPage public Document? SuccessBannerContent { get; init; } public string ErrorText { get; init; } = string.Empty; - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/DateQuestionPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/DateQuestionPage.cs index 1cf882d0..a67cd442 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/DateQuestionPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/DateQuestionPage.cs @@ -13,6 +13,6 @@ public class DateQuestionPage public string MonthLabel { get; init; } = string.Empty; public string YearLabel { get; init; } = string.Empty; - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/DetailsPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/DetailsPage.cs index cd8981a3..6223ab17 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/DetailsPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/DetailsPage.cs @@ -27,6 +27,6 @@ public class DetailsPage public string FurtherInfoHeading { get; init; } = string.Empty; public Document? FurtherInfoText { get; init; } - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs index 5a290e0d..08e93658 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs @@ -13,6 +13,6 @@ public class DropdownQuestionPage public string NotInListText { get; init; } = string.Empty; public string DefaultText { get; init; } = string.Empty; - + public NavigationLink? BackButton { get; set; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs index 4dba54c3..ec7563e0 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs @@ -3,6 +3,6 @@ namespace Dfe.EarlyYearsQualification.Content.Entities; public class QualificationListPage { public string Header { get; set; } = string.Empty; - + public NavigationLink? BackButton { get; set; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/RadioQuestionPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/RadioQuestionPage.cs index cf4afb5d..b353a6bd 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/RadioQuestionPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/RadioQuestionPage.cs @@ -15,6 +15,6 @@ public class RadioQuestionPage public string AdditionalInformationHeader { get; init; } = string.Empty; public Document? AdditionalInformationBody { get; init; } - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs b/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs index 052da64d..373cc47a 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs @@ -20,7 +20,7 @@ private readonly Dictionary _contentTypes { typeof(Qualification), ContentTypes.Qualification }, { typeof(DetailsPage), ContentTypes.DetailsPage }, { typeof(AdvicePage), ContentTypes.AdvicePage }, - { typeof(RadioQuestionPage), ContentTypes.RadioQuestionPage}, + { typeof(RadioQuestionPage), ContentTypes.RadioQuestionPage }, { typeof(AccessibilityStatementPage), ContentTypes.AccessibilityStatementPage }, { typeof(NavigationLinks), ContentTypes.NavigationLinks }, { typeof(CookiesPage), ContentTypes.CookiesPage }, @@ -29,7 +29,7 @@ private readonly Dictionary _contentTypes { typeof(DateQuestionPage), ContentTypes.DateQuestionPage }, { typeof(DropdownQuestionPage), ContentTypes.DropdownQuestionPage }, { typeof(QualificationListPage), ContentTypes.QualificationListPage }, - { typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage}, + { typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage } }; public async Task GetStartPage() diff --git a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulFilterService.cs b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulFilterService.cs index 9b3b4ed4..5540d53b 100644 --- a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulFilterService.cs +++ b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulFilterService.cs @@ -7,31 +7,32 @@ public class MockContentfulFilterService : IContentFilterService { public Task> GetFilteredQualifications(int? level, int? startDateMonth, int? startDateYear) { - var qualifications = new List - { - CreateQualification("EYQ-100", "CACHE", 2, null, "Aug-19"), - CreateQualification("EYQ-101", "NCFE", 2, "Sep-14", "Aug-19"), - CreateQualification("EYQ-102", "Pearson", 3, "Sep-14", "Aug-19"), - CreateQualification("EYQ-103", "NCFE", 3, "Sep-14", "Aug-19"), - CreateQualification("EYQ-104", "City & Guilds", 4, "Sep-14", "Aug-19"), - CreateQualification("EYQ-105", "Montessori Centre International", 4, "Sep-14", "Aug-19"), - CreateQualification("EYQ-106", "Various Awarding Organisations", 5, "Sep-14", "Aug-19"), - CreateQualification("EYQ-107", "Edexcel (now Pearson Education Ltd)", 5, "Sep-14", "Aug-19"), - CreateQualification("EYQ-108", "Kent Sussex Montessori Centre", 6, "Sep-14", "Aug-19"), - CreateQualification("EYQ-109", "NNEB National Nursery Examination Board", 6, "Sep-14", "Aug-19"), - CreateQualification("EYQ-110", "Various Awarding Organisations", 7, "Sep-14", "Aug-19"), - CreateQualification("EYQ-111", "City & Guilds", 7, "Sep-14", "Aug-19"), - CreateQualification("EYQ-112", "Pearson", 8, "Sep-14", "Aug-19"), - CreateQualification("EYQ-113", "CACHE", 8, "Sep-14", "Aug-19") - }; + var qualifications = + new List + { + CreateQualification("EYQ-100", "CACHE", 2, null, "Aug-19"), + CreateQualification("EYQ-101", "NCFE", 2, "Sep-14", "Aug-19"), + CreateQualification("EYQ-102", "Pearson", 3, "Sep-14", "Aug-19"), + CreateQualification("EYQ-103", "NCFE", 3, "Sep-14", "Aug-19"), + CreateQualification("EYQ-104", "City & Guilds", 4, "Sep-14", "Aug-19"), + CreateQualification("EYQ-105", "Montessori Centre International", 4, "Sep-14", "Aug-19"), + CreateQualification("EYQ-106", "Various Awarding Organisations", 5, "Sep-14", "Aug-19"), + CreateQualification("EYQ-107", "Edexcel (now Pearson Education Ltd)", 5, "Sep-14", "Aug-19"), + CreateQualification("EYQ-108", "Kent Sussex Montessori Centre", 6, "Sep-14", "Aug-19"), + CreateQualification("EYQ-109", "NNEB National Nursery Examination Board", 6, "Sep-14", "Aug-19"), + CreateQualification("EYQ-110", "Various Awarding Organisations", 7, "Sep-14", "Aug-19"), + CreateQualification("EYQ-111", "City & Guilds", 7, "Sep-14", "Aug-19"), + CreateQualification("EYQ-112", "Pearson", 8, "Sep-14", "Aug-19"), + CreateQualification("EYQ-113", "CACHE", 8, "Sep-14", "Aug-19") + }; return Task.FromResult(qualifications.Where(x => x.QualificationLevel == level).ToList()); } - private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level, string? startDate, string endDate) + private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level, + string? startDate, string endDate) { - return new Qualification( - qualificationId, + return new Qualification(qualificationId, $"{qualificationId}-test", awardingOrganisation, level, diff --git a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs index 2374f505..1afab3fa 100644 --- a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs +++ b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs @@ -218,37 +218,37 @@ public Task> GetQualifications() public async Task GetConfirmQualificationPage() { return await Task.FromResult(new ConfirmQualificationPage - { - QualificationLabel = "Test qualification label", - BackButton = new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }, - ErrorText = "Test error text", - ButtonText = "Test button text", - LevelLabel = "Test level label", - DateAddedLabel = "Test date added label", - Heading = "Test heading", - Options = - [ - new Option - { - Label = "yes", - Value = "yes" - }, - new Option - { - Label = "no", - Value = "no" - } - ], - RadioHeading = "Test radio heading", - AwardingOrganisationLabel = "Test awarding organisation label", - ErrorBannerHeading = "Test error banner heading", - ErrorBannerLink = "Test error banner link" - }); + { + QualificationLabel = "Test qualification label", + BackButton = new NavigationLink + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }, + ErrorText = "Test error text", + ButtonText = "Test button text", + LevelLabel = "Test level label", + DateAddedLabel = "Test date added label", + Heading = "Test heading", + Options = + [ + new Option + { + Label = "yes", + Value = "yes" + }, + new Option + { + Label = "no", + Value = "no" + } + ], + RadioHeading = "Test radio heading", + AwardingOrganisationLabel = "Test awarding organisation label", + ErrorBannerHeading = "Test error banner heading", + ErrorBannerLink = "Test error banner link" + }); } public async Task GetStartPage() diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/AccessibilityStatementController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/AccessibilityStatementController.cs index 1031d529..9788c7af 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/AccessibilityStatementController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/AccessibilityStatementController.cs @@ -36,7 +36,7 @@ private async Task Map(AccessibilityStatementPa { Heading = content.Heading, BodyContent = await renderer.ToHtml(content.Body), - BackButton = content.BackButton, + BackButton = content.BackButton }; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs index 57e8818d..d07a461b 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs @@ -17,7 +17,7 @@ public async Task QualificationOutsideTheUnitedKingdom() { return await GetView(AdvicePages.QualificationsAchievedOutsideTheUk); } - + [HttpGet("level-2-qualifications-started-between-1-sept-2014-&-31-aug-2019")] public async Task QualificationsStartedBetweenSept2014AndAug2019() { diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs index dfea8c82..5ec8664b 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs @@ -21,7 +21,7 @@ public async Task Index(string qualificationId) { return BadRequest(); } - + var content = await contentService.GetConfirmQualificationPage(); if (content is null) @@ -79,10 +79,12 @@ public async Task Confirm(ConfirmQualificationPageModel model) return View("Index", model); } - - return model.ConfirmQualificationAnswer == "yes" ? RedirectToAction("Index", "QualificationDetails", new { qualificationId = model.QualificationId }) : RedirectToAction("Get", "QualificationDetails"); + + return model.ConfirmQualificationAnswer == "yes" + ? RedirectToAction("Index", "QualificationDetails", new { qualificationId = model.QualificationId }) + : RedirectToAction("Get", "QualificationDetails"); } - + private static ConfirmQualificationPageModel Map(ConfirmQualificationPage content, Qualification qualification) { return new ConfirmQualificationPageModel @@ -104,7 +106,7 @@ private static ConfirmQualificationPageModel Map(ConfirmQualificationPage conten QualificationId = qualification.QualificationId, QualificationAwardingOrganisation = qualification.AwardingOrganisationTitle, QualificationDateAdded = qualification.FromWhichYear!, - BackButton = content.BackButton, + BackButton = content.BackButton }; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/HomeController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/HomeController.cs index e0647c1f..878edef4 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/HomeController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/HomeController.cs @@ -27,9 +27,9 @@ public async Task Index() } var model = await Map(startPageContent); - + userJourneyCookieService.ResetUserJourneyCookie(); - + return View(model); } diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs index 10091c0e..e6e0c6a7 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs @@ -27,11 +27,11 @@ public async Task Get() logger.LogError("No content for the qualification list page"); return RedirectToAction("Index", "Error"); } - + var filterParams = userJourneyCookieService.GetUserJourneyModelFromCookie(); var model = MapList(listPageContent, filterParams); - + return View(model); } @@ -66,7 +66,7 @@ public async Task Index(string qualificationId) private QualificationListModel MapList(QualificationListPage content, UserJourneyModel? filters) { - return new QualificationListModel() + return new QualificationListModel { BackButton = content.BackButton, Filters = filters, diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs index 5227f151..c4d8b282 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs @@ -26,8 +26,8 @@ public class QuestionsController( public async Task WhereWasTheQualificationAwarded() { return await GetRadioView(QuestionPages.WhereWasTheQualificationAwarded, - nameof(this.WhereWasTheQualificationAwarded), - Questions); + nameof(this.WhereWasTheQualificationAwarded), + Questions); } [HttpPost("where-was-the-qualification-awarded")] @@ -38,7 +38,8 @@ public async Task WhereWasTheQualificationAwarded(RadioQuestionMo var questionPage = await contentService.GetRadioQuestionPage(QuestionPages.WhereWasTheQualificationAwarded); if (questionPage is not null) { - model = await MapRadioModel(model, questionPage, nameof(this.WhereWasTheQualificationAwarded), Questions); + model = await MapRadioModel(model, questionPage, nameof(this.WhereWasTheQualificationAwarded), + Questions); model.HasErrors = true; } @@ -49,7 +50,7 @@ public async Task WhereWasTheQualificationAwarded(RadioQuestionMo { return RedirectToAction("QualificationOutsideTheUnitedKingdom", "Advice"); } - + userJourneyCookieService.SetWhereWasQualificationAwarded(model.Option!); return RedirectToAction(nameof(this.WhenWasTheQualificationStarted)); @@ -67,7 +68,7 @@ public async Task WhenWasTheQualificationStarted() } var model = MapDateModel(new DateQuestionModel(), questionPage, nameof(this.WhenWasTheQualificationStarted), - Questions); + Questions); return View("Date", model); } @@ -85,8 +86,9 @@ public async Task WhenWasTheQualificationStarted(DateQuestionMode return View("Date", model); } - - userJourneyCookieService.SetWhenWasQualificationAwarded(model.SelectedMonth.ToString() + '/' + model.SelectedYear); + + userJourneyCookieService.SetWhenWasQualificationAwarded(model.SelectedMonth.ToString() + '/' + + model.SelectedYear); return RedirectToAction(nameof(this.WhatLevelIsTheQualification)); } @@ -95,7 +97,7 @@ public async Task WhenWasTheQualificationStarted(DateQuestionMode public async Task WhatLevelIsTheQualification() { return await GetRadioView(QuestionPages.WhatLevelIsTheQualification, nameof(this.WhatLevelIsTheQualification), - Questions); + Questions); } [HttpPost("what-level-is-the-qualification")] @@ -112,12 +114,12 @@ public async Task WhatLevelIsTheQualification(RadioQuestionModel return View("Radio", model); } - + userJourneyCookieService.SetLevelOfQualification(model.Option!); return RedirectToAction(nameof(this.WhatIsTheAwardingOrganisation)); } - + [HttpGet("what-is-the-awarding-organisation")] public async Task WhatIsTheAwardingOrganisation() { @@ -130,39 +132,42 @@ public async Task WhatIsTheAwardingOrganisation() var qualifications = await GetFilteredQualifications(); - var model = MapDropdownModel(new DropdownQuestionModel(), questionPage, qualifications, nameof(this.WhatIsTheAwardingOrganisation), - Questions); - + var model = MapDropdownModel(new DropdownQuestionModel(), questionPage, qualifications, + nameof(this.WhatIsTheAwardingOrganisation), + Questions); + return View("Dropdown", model); } - + [HttpPost("what-is-the-awarding-organisation")] public async Task WhatIsTheAwardingOrganisation(DropdownQuestionModel model) { if (!ModelState.IsValid || (string.IsNullOrEmpty(model.SelectedValue) && !model.NotInTheList)) { - var questionPage = await contentService.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation); + var questionPage = + await contentService.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation); if (questionPage is not null) { var qualifications = await GetFilteredQualifications(); - - model = MapDropdownModel(model, questionPage, qualifications, nameof(this.WhatIsTheAwardingOrganisation), + + model = MapDropdownModel(model, questionPage, qualifications, + nameof(this.WhatIsTheAwardingOrganisation), Questions); model.HasErrors = true; } return View("Dropdown", model); } - + userJourneyCookieService.SetAwardingOrganisation(model.NotInTheList ? string.Empty : model.SelectedValue); - + return RedirectToAction("Get", "QualificationDetails"); } - + private async Task> GetFilteredQualifications() { var cookie = userJourneyCookieService.GetUserJourneyModelFromCookie(); - + int? level = null; if (int.TryParse(cookie.LevelOfQualification, out var parsedLevel)) { @@ -172,14 +177,14 @@ private async Task> GetFilteredQualifications() int? startDateMonth = null; int? startDateYear = null; var qualificationAwardedDateSplit = cookie.WhenWasQualificationAwarded.Split('/'); - if (qualificationAwardedDateSplit.Length == 2 - && int.TryParse(qualificationAwardedDateSplit[0], out var parsedStartMonth) + if (qualificationAwardedDateSplit.Length == 2 + && int.TryParse(qualificationAwardedDateSplit[0], out var parsedStartMonth) && int.TryParse(qualificationAwardedDateSplit[1], out var parsedStartYear)) { startDateMonth = parsedStartMonth; startDateYear = parsedStartYear; } - + return await contentFilterService.GetFilteredQualifications(level, startDateMonth, startDateYear); } @@ -197,8 +202,9 @@ private async Task GetRadioView(string questionPageId, string act return View("Radio", model); } - private async Task MapRadioModel(RadioQuestionModel model, RadioQuestionPage question, string actionName, - string controllerName) + private async Task MapRadioModel(RadioQuestionModel model, RadioQuestionPage question, + string actionName, + string controllerName) { model.Question = question.Question; model.Options = question.Options.Select(x => new OptionModel { Label = x.Label, Value = x.Value }).ToList(); @@ -213,7 +219,7 @@ private async Task MapRadioModel(RadioQuestionModel model, R } private static DateQuestionModel MapDateModel(DateQuestionModel model, DateQuestionPage question, string actionName, - string controllerName) + string controllerName) { model.Question = question.Question; model.CtaButtonText = question.CtaButtonText; @@ -227,16 +233,18 @@ private static DateQuestionModel MapDateModel(DateQuestionModel model, DateQuest return model; } - private static DropdownQuestionModel MapDropdownModel(DropdownQuestionModel model, DropdownQuestionPage question, List qualifications, string actionName, + private static DropdownQuestionModel MapDropdownModel(DropdownQuestionModel model, DropdownQuestionPage question, + List qualifications, string actionName, string controllerName) { - var awardingOrganisationExclusions = new [] { "All Higher Education Institutes", "Various Awarding Organisations" }; + var awardingOrganisationExclusions = + new[] { "All Higher Education Institutes", "Various Awarding Organisations" }; var uniqueAwardingOrganisations = qualifications.Select(x => x.AwardingOrganisationTitle) .Distinct() .Where(x => !awardingOrganisationExclusions.Any(x.Contains)) .Order() .ToList(); - + model.ActionName = actionName; model.ControllerName = controllerName; model.CtaButtonText = question.CtaButtonText; @@ -245,22 +253,22 @@ private static DropdownQuestionModel MapDropdownModel(DropdownQuestionModel mode model.DropdownHeading = question.DropdownHeading; model.NotInListText = question.NotInListText; model.BackButton = question.BackButton; - + model.Values.Add(new SelectListItem { Text = question.DefaultText, Value = "" }); - - foreach (var awardingOrg in uniqueAwardingOrganisations) - { - model.Values.Add(new SelectListItem - { - Value = awardingOrg, - Text = awardingOrg - }); - } - - return model; + + foreach (var awardingOrg in uniqueAwardingOrganisations) + { + model.Values.Add(new SelectListItem + { + Value = awardingOrg, + Text = awardingOrg + }); + } + + return model; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/AccessibilityStatementPageModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/AccessibilityStatementPageModel.cs index dc3fb0e5..afbc86ed 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/AccessibilityStatementPageModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/AccessibilityStatementPageModel.cs @@ -7,6 +7,6 @@ public class AccessibilityStatementPageModel public string Heading { get; init; } = string.Empty; public string BodyContent { get; init; } = string.Empty; - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/AdvicePageModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/AdvicePageModel.cs index 527d40c9..53ca805e 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/AdvicePageModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/AdvicePageModel.cs @@ -7,6 +7,6 @@ public class AdvicePageModel public string Heading { get; init; } = string.Empty; public string BodyContent { get; init; } = string.Empty; - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/CookiesPageModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/CookiesPageModel.cs index 083aa0b9..66ccc7c3 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/CookiesPageModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/CookiesPageModel.cs @@ -13,13 +13,16 @@ public class CookiesPageModel public string ButtonText { get; init; } = string.Empty; - public string CookiesAnswer => "CookiesAnswer"; + public string CookiesAnswer + { + get { return "CookiesAnswer"; } + } public string SuccessBannerHeading { get; init; } = string.Empty; public string SuccessBannerContent { get; init; } = string.Empty; public string ErrorText { get; init; } = string.Empty; - + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs index 971bbef2..de0acc79 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs @@ -17,6 +17,6 @@ public class QualificationDetailsModel public string BookmarkUrl { get; init; } = string.Empty; public NavigationLink? BackButton { get; set; } - + public DetailsPageModel? Content { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs index 48d8fb87..e7dad2aa 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs @@ -5,8 +5,8 @@ namespace Dfe.EarlyYearsQualification.Web.Models.Content; public class QualificationListModel { public string Header { get; set; } = string.Empty; - + public UserJourneyModel? Filters { get; set; } - + public NavigationLink? BackButton { get; set; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/BaseQuestionModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/BaseQuestionModel.cs index 93ade914..f7ffd476 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/BaseQuestionModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/BaseQuestionModel.cs @@ -15,6 +15,6 @@ public abstract class BaseQuestionModel public string ErrorMessage { get; set; } = string.Empty; public bool HasErrors { get; set; } - + public NavigationLink? BackButton { get; set; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs index 1fd43a07..afa32feb 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs @@ -4,23 +4,23 @@ namespace Dfe.EarlyYearsQualification.Web.Models.Content.QuestionModels; public class DateQuestionModel : BaseQuestionModel { - public string QuestionHint { get; set; } = string.Empty; + public string QuestionHint { get; set; } = string.Empty; - public string MonthLabel { get; set; } = string.Empty; + public string MonthLabel { get; set; } = string.Empty; - public string YearLabel { get; set; } = string.Empty; + public string YearLabel { get; set; } = string.Empty; - [Required] public int SelectedMonth { get; init; } + [Required] public int SelectedMonth { get; init; } - [Required] public int SelectedYear { get; init; } + [Required] public int SelectedYear { get; init; } - public bool IsModelValid() - { - if (SelectedMonth < 1 || SelectedMonth > 12) + public bool IsModelValid() { - return false; - } + if (SelectedMonth < 1 || SelectedMonth > 12) + { + return false; + } - return SelectedYear > 1900 && SelectedYear <= DateTime.UtcNow.Year; - } + return SelectedYear > 1900 && SelectedYear <= DateTime.UtcNow.Year; + } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DropdownQuestionModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DropdownQuestionModel.cs index 180e5ae7..73978380 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DropdownQuestionModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DropdownQuestionModel.cs @@ -11,10 +11,10 @@ public class DropdownQuestionModel : BaseQuestionModel public string DropdownHeading { get; set; } = string.Empty; public string NotInListText { get; set; } = string.Empty; - + public string DropdownId { get; init; } = "awarding-organisation-select"; public string CheckboxId { get; init; } = "awarding-organisation-not-in-list"; - + public bool NotInTheList { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/RadioQuestionModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/RadioQuestionModel.cs index 7e7918c8..ce2ca754 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/RadioQuestionModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/RadioQuestionModel.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using Dfe.EarlyYearsQualification.Content.Entities; namespace Dfe.EarlyYearsQualification.Web.Models.Content.QuestionModels; @@ -9,9 +8,9 @@ public class RadioQuestionModel : BaseQuestionModel [Required] public string? Option { get; init; } = string.Empty; - public string AdditionalInformationHeader {get; set;} = string.Empty; + public string AdditionalInformationHeader { get; set; } = string.Empty; - public string AdditionalInformationBody {get; set;} = string.Empty; + public string AdditionalInformationBody { get; set; } = string.Empty; } public class OptionModel diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/UserJourneyModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/UserJourneyModel.cs index 9a9a9c3d..13d23509 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/UserJourneyModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/UserJourneyModel.cs @@ -2,8 +2,8 @@ namespace Dfe.EarlyYearsQualification.Web.Models; public class UserJourneyModel { - public string WhereWasQualificationAwarded { get; set; } = string.Empty; - public string WhenWasQualificationAwarded { get; set; } = string.Empty; - public string LevelOfQualification { get; set; } = string.Empty; - public string WhatIsTheAwardingOrganisation { get; set; } = string.Empty; + public string WhereWasQualificationAwarded { get; set; } = string.Empty; + public string WhenWasQualificationAwarded { get; set; } = string.Empty; + public string LevelOfQualification { get; set; } = string.Empty; + public string WhatIsTheAwardingOrganisation { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Security/SecureHeaderConfiguration.cs b/src/Dfe.EarlyYearsQualification.Web/Security/SecureHeaderConfiguration.cs index c6fc5756..77841c6b 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Security/SecureHeaderConfiguration.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Security/SecureHeaderConfiguration.cs @@ -46,13 +46,13 @@ public static SecureHeadersMiddlewareConfiguration CustomConfiguration() CommandType = CspCommandType.Directive, DirectiveOrUri = "sha256-GUQ5ad8JK5KmEWmROf3LZd9ge94daqNvd8xy9YS1iDw=" }; - + var govukAllMinifiedElement = new ContentSecurityPolicyElement - { - CommandType = CspCommandType.Directive, - DirectiveOrUri = "sha256-l5MP+9OapFXGxjKMNj/89ExAW2TvAFFoADrbsmtSJXo=" - }; - + { + CommandType = CspCommandType.Directive, + DirectiveOrUri = "sha256-l5MP+9OapFXGxjKMNj/89ExAW2TvAFFoADrbsmtSJXo=" + }; + var dropdownPageCheckbox = new ContentSecurityPolicyElement { CommandType = CspCommandType.Directive, @@ -71,7 +71,7 @@ public static SecureHeadersMiddlewareConfiguration CustomConfiguration() configuration.ContentSecurityPolicyConfiguration.ScriptSrc.Add(govukAllMinifiedElement); configuration.ContentSecurityPolicyConfiguration.FrameAncestors.Add(contentfulCspElement); configuration.ContentSecurityPolicyConfiguration.ScriptSrc.Add(dropdownPageCheckbox); - + return configuration; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/CookiesPreferenceService.cs b/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/CookiesPreferenceService.cs index 596a31c0..2021c1d8 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/CookiesPreferenceService.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/CookiesPreferenceService.cs @@ -9,7 +9,8 @@ public void SetVisibility(bool visibility) { var currentCookie = GetCookie(); DeleteCookie(); - CreateCookie(CookieKeyNames.CookiesPreferenceKey, currentCookie.HasApproved, visibility, currentCookie.IsRejected); + CreateCookie(CookieKeyNames.CookiesPreferenceKey, currentCookie.HasApproved, visibility, + currentCookie.IsRejected); } public void RejectCookies() diff --git a/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/ICookiesPreferenceService.cs b/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/ICookiesPreferenceService.cs index ff592772..27855f77 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/ICookiesPreferenceService.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Services/CookiesPreferenceService/ICookiesPreferenceService.cs @@ -9,4 +9,4 @@ public interface ICookiesPreferenceService public void SetVisibility(bool visibility); public void RejectCookies(); -} +} \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/IUserJourneyCookieService.cs b/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/IUserJourneyCookieService.cs index fe04f9e0..69a01146 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/IUserJourneyCookieService.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/IUserJourneyCookieService.cs @@ -10,4 +10,4 @@ public interface IUserJourneyCookieService public void SetAwardingOrganisation(string awardingOrganisation); public UserJourneyModel GetUserJourneyModelFromCookie(); public void ResetUserJourneyCookie(); -} +} \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs b/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs index 3e4bf33e..a20ee2b7 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs @@ -4,7 +4,8 @@ namespace Dfe.EarlyYearsQualification.Web.Services.UserJourneyCookieService; -public class UserJourneyCookieService(IHttpContextAccessor context, ILogger logger) : IUserJourneyCookieService +public class UserJourneyCookieService(IHttpContextAccessor context, ILogger logger) + : IUserJourneyCookieService { private readonly CookieOptions _options = new() { @@ -45,7 +46,7 @@ public void SetAwardingOrganisation(string awardingOrganisation) var model = GetUserJourneyModelFromCookie(); model.WhatIsTheAwardingOrganisation = awardingOrganisation; - + SetJourneyCookie(model); } diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/AccessibilityStatement/Index.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/AccessibilityStatement/Index.cshtml index 1dc5d10e..203e683d 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/AccessibilityStatement/Index.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/AccessibilityStatement/Index.cshtml @@ -5,7 +5,7 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Advice/Advice.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Advice/Advice.cshtml index f08c9888..e8c4176a 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Advice/Advice.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Advice/Advice.cshtml @@ -5,7 +5,7 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Challenge/EntryForm.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Challenge/EntryForm.cshtml index 95844598..52d56746 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Challenge/EntryForm.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Challenge/EntryForm.cshtml @@ -18,7 +18,7 @@ @using (Html.BeginForm("Post", "Challenge", new { }, FormMethod.Post)) { - + } diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/ConfirmQualification/index.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/ConfirmQualification/index.cshtml index 115eead4..c35bad77 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/ConfirmQualification/index.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/ConfirmQualification/index.cshtml @@ -5,7 +5,7 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/CookiesPreference/Index.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/CookiesPreference/Index.cshtml index dd20780e..a36b476e 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/CookiesPreference/Index.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/CookiesPreference/Index.cshtml @@ -22,54 +22,54 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
-
- @{ - bool userPreferenceSet = TempData["UserPreferenceRecorded"] as bool? ?? false; - if (userPreferenceSet) - { - +
+ @{ + var userPreferenceSet = TempData["UserPreferenceRecorded"] as bool? ?? false; + if (userPreferenceSet) + { + + } } - } -

@Model.Heading

-
@Html.Raw(Model.BodyContent)
-
-
-
- - @foreach (var option in Model.Options) - { -
- @Html.RadioButtonFor(x => x.CookiesAnswer, option.Value, new { @class = "govuk-radios__input", id = option.Value }) - -
- } -
-
-
- -
-
-
+

@Model.Heading

+
@Html.Raw(Model.BodyContent)
+
+
+
+ + @foreach (var option in Model.Options) + { +
+ @Html.RadioButtonFor(x => x.CookiesAnswer, option.Value, new { @class = "govuk-radios__input", id = option.Value }) + +
+ } +
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Get.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Get.cshtml index 2b30d1be..dcdb9f72 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Get.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Get.cshtml @@ -6,7 +6,7 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
@@ -35,7 +35,7 @@
  • @Model.Filters!.WhatIsTheAwardingOrganisation
  • } - +

    Change my search

    diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Index.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Index.cshtml index b121c986..6ee1f82b 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Index.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/QualificationDetails/Index.cshtml @@ -5,7 +5,7 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
    diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Date.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Date.cshtml index 5bd380cb..a0bc8c79 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Date.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Date.cshtml @@ -5,13 +5,13 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
    -
    - @using (Html.BeginForm(Model.ActionName, Model.ControllerName, FormMethod.Post)) +
    + @using (Html.BeginForm(Model.ActionName, Model.ControllerName, FormMethod.Post)) {
    @@ -22,23 +22,23 @@
    @Model.QuestionHint
    @if (Model.HasErrors) - { -

    + { +

    Error: @Model.ErrorMessage -

    - } +

    + }
    - @Html.TextBoxFor(x => x.SelectedMonth, "{0:#.#}", new { id = "date-started-month", @class = "govuk-input govuk-date-input__input govuk-input--width-2", maxlength = "2", name="date-started-month", type="text", inputmode="numeric", Value = ""}) + @Html.TextBoxFor(x => x.SelectedMonth, "{0:#.#}", new { id = "date-started-month", @class = "govuk-input govuk-date-input__input govuk-input--width-2", maxlength = "2", name = "date-started-month", type = "text", inputmode = "numeric", Value = "" })
    - @Html.TextBoxFor(x => x.SelectedYear, "{0:#.#}", new { id = "date-started-year", @class = "govuk-input govuk-date-input__input govuk-input--width-4", maxlength = "4", name="date-started-month", type="text", inputmode="numeric", Value = ""}) + @Html.TextBoxFor(x => x.SelectedYear, "{0:#.#}", new { id = "date-started-year", @class = "govuk-input govuk-date-input__input govuk-input--width-4", maxlength = "4", name = "date-started-month", type = "text", inputmode = "numeric", Value = "" })
    diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Dropdown.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Dropdown.cshtml index 62baaf4d..303f76f0 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Dropdown.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Dropdown.cshtml @@ -16,13 +16,13 @@ @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
    -
    - @using (Html.BeginForm(Model.ActionName, Model.ControllerName, FormMethod.Post)) +
    + @using (Html.BeginForm(Model.ActionName, Model.ControllerName, FormMethod.Post)) {
    @@ -37,20 +37,20 @@ Error: @Model.ErrorMessage

    } - +
    - +

    @Html.Label(Model.DropdownId, Model.DropdownHeading, new { @class = "govuk-label govuk-fieldset__legend--m" })

    - +
    @Html.DropDownListFor(x => x.SelectedValue, Model.Values, new { @class = Model.HasErrors ? "govuk-select govuk-select--error" : "govuk-select", id = Model.DropdownId })
    - +
    - @Html.CheckBoxFor(x => x.NotInTheList, new { @class = "govuk-checkboxes__input", id=Model.CheckboxId, name="awarding-organisation" }) + @Html.CheckBoxFor(x => x.NotInTheList, new { @class = "govuk-checkboxes__input", id = Model.CheckboxId, name = "awarding-organisation" }) @Html.Label(Model.CheckboxId, Model.NotInListText, new { @class = "govuk-label govuk-checkboxes__label" })
    @@ -60,7 +60,7 @@ @Model.CtaButtonText
    - } -
    + } +
    \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Radio.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Radio.cshtml index 2376b5e2..1c9f615c 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Radio.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Questions/Radio.cshtml @@ -5,7 +5,7 @@ } @{ - await Html.RenderPartialAsync("Partials/BackButton", @Model.BackButton); + await Html.RenderPartialAsync("Partials/BackButton", Model.BackButton); }
    diff --git a/src/Dfe.EarlyYearsQualification.Web/Views/Shared/_Header.cshtml b/src/Dfe.EarlyYearsQualification.Web/Views/Shared/_Header.cshtml index 1e666cde..8def25c7 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Views/Shared/_Header.cshtml +++ b/src/Dfe.EarlyYearsQualification.Web/Views/Shared/_Header.cshtml @@ -11,8 +11,7 @@ viewBox="0 0 148 30" height="30" width="148" - aria-label="GOV.UK" - > + aria-label="GOV.UK"> GOV.UK diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs index d377c346..39307f51 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs @@ -72,9 +72,10 @@ public async Task QualificationOutsideTheUnitedKingdom_ContentServiceReturnsAdvi mockHtmlRenderer.Verify(x => x.ToHtml(It.IsAny()), Times.Once); } - + [TestMethod] - public async Task QualificationsStartedBetweenSept2014AndAug2019_ContentServiceReturnsNoAdvicePage_RedirectsToErrorPage() + public async Task + QualificationsStartedBetweenSept2014AndAug2019_ContentServiceReturnsNoAdvicePage_RedirectsToErrorPage() { var mockLogger = new Mock>(); var mockContentService = new Mock(); @@ -99,7 +100,8 @@ public async Task QualificationsStartedBetweenSept2014AndAug2019_ContentServiceR } [TestMethod] - public async Task QualificationsStartedBetweenSept2014AndAug2019_ContentServiceReturnsAdvicePage_ReturnsAdvicePageModel() + public async Task + QualificationsStartedBetweenSept2014AndAug2019_ContentServiceReturnsAdvicePage_ReturnsAdvicePageModel() { var mockLogger = new Mock>(); var mockContentService = new Mock(); diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/ConfirmQualificationControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/ConfirmQualificationControllerTests.cs index 5457e20d..878eaf9f 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/ConfirmQualificationControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/ConfirmQualificationControllerTests.cs @@ -4,7 +4,6 @@ using Dfe.EarlyYearsQualification.Web.Controllers; using Dfe.EarlyYearsQualification.Web.Models.Content; using FluentAssertions; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Moq; @@ -37,11 +36,11 @@ public async Task Index_ContentServiceCantFindPageDetails_LogsAndReturnsErrorPag var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(default(ConfirmQualificationPage?)); - + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); - + var result = await controller.Index("Some ID"); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; @@ -59,44 +58,44 @@ public async Task Index_CantFindQualification_LogsAndReturnsError() var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(new ConfirmQualificationPage - { - QualificationLabel = "Test qualification label", - BackButton = new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }, - ErrorText = "Test error text", - ButtonText = "Test button text", - LevelLabel = "Test level label", - DateAddedLabel = "Test date added label", - Heading = "Test heading", - Options = - [ - new Option - { - Label = "yes", - Value = "yes" - }, - new Option - { - Label = "no", - Value = "no" - } - ], - RadioHeading = "Test radio heading", - AwardingOrganisationLabel = "Test awarding organisation label", - ErrorBannerHeading = "Test error banner heading", - ErrorBannerLink = "Test error banner link" - }); + { + QualificationLabel = "Test qualification label", + BackButton = new NavigationLink + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }, + ErrorText = "Test error text", + ButtonText = "Test button text", + LevelLabel = "Test level label", + DateAddedLabel = "Test date added label", + Heading = "Test heading", + Options = + [ + new Option + { + Label = "yes", + Value = "yes" + }, + new Option + { + Label = "no", + Value = "no" + } + ], + RadioHeading = "Test radio heading", + AwardingOrganisationLabel = "Test awarding organisation label", + ErrorBannerHeading = "Test error banner heading", + ErrorBannerLink = "Test error banner link" + }); mockContentService.Setup(x => x.GetQualificationById("Some ID")).ReturnsAsync(default(Qualification?)); - + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); - + var result = await controller.Index("Some ID"); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; @@ -114,45 +113,46 @@ public async Task Index_PageDetailsAndQualificationFound_MapsModelAndReturnsView var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(new ConfirmQualificationPage - { - QualificationLabel = "Test qualification label", - BackButton = new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }, - ErrorText = "Test error text", - ButtonText = "Test button text", - LevelLabel = "Test level label", - DateAddedLabel = "Test date added label", - Heading = "Test heading", - Options = - [ - new Option - { - Label = "yes", - Value = "yes" - }, - new Option - { - Label = "no", - Value = "no" - } - ], - RadioHeading = "Test radio heading", - AwardingOrganisationLabel = "Test awarding organisation label", - ErrorBannerHeading = "Test error banner heading", - ErrorBannerLink = "Test error banner link" - }); - - mockContentService.Setup(x => x.GetQualificationById("Some ID")).ReturnsAsync(new Qualification("Some ID", "Qualification Name", "NCFE", 2, "2014", "2019", - "ABC/547/900", "additional requirements")); - + { + QualificationLabel = "Test qualification label", + BackButton = new NavigationLink + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }, + ErrorText = "Test error text", + ButtonText = "Test button text", + LevelLabel = "Test level label", + DateAddedLabel = "Test date added label", + Heading = "Test heading", + Options = + [ + new Option + { + Label = "yes", + Value = "yes" + }, + new Option + { + Label = "no", + Value = "no" + } + ], + RadioHeading = "Test radio heading", + AwardingOrganisationLabel = "Test awarding organisation label", + ErrorBannerHeading = "Test error banner heading", + ErrorBannerLink = "Test error banner link" + }); + + mockContentService.Setup(x => x.GetQualificationById("Some ID")).ReturnsAsync(new Qualification("Some ID", + "Qualification Name", "NCFE", 2, "2014", "2019", + "ABC/547/900", "additional requirements")); + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); - + var result = await controller.Index("Some ID"); - + result.Should().NotBeNull(); var resultType = result as ViewResult; @@ -162,11 +162,11 @@ public async Task Index_PageDetailsAndQualificationFound_MapsModelAndReturnsView model.Should().NotBeNull(); model!.BackButton.Should().BeEquivalentTo(new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }); + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }); model.HasErrors.Should().BeFalse(); model.Options.Should().BeEquivalentTo([ new Option @@ -205,13 +205,13 @@ public async Task Post_InvalidModel_CantGetPageContent_LogsAndReturnsError() var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(default(ConfirmQualificationPage?)); - + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); controller.ModelState.AddModelError("test", "error"); - + var result = await controller.Confirm(new ConfirmQualificationPageModel()); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; @@ -229,44 +229,44 @@ public async Task Post_InvalidModel_NoQualificationId_LogsAndReturnsError() var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(new ConfirmQualificationPage - { - QualificationLabel = "Test qualification label", - BackButton = new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }, - ErrorText = "Test error text", - ButtonText = "Test button text", - LevelLabel = "Test level label", - DateAddedLabel = "Test date added label", - Heading = "Test heading", - Options = - [ - new Option - { - Label = "yes", - Value = "yes" - }, - new Option - { - Label = "no", - Value = "no" - } - ], - RadioHeading = "Test radio heading", - AwardingOrganisationLabel = "Test awarding organisation label", - ErrorBannerHeading = "Test error banner heading", - ErrorBannerLink = "Test error banner link" - }); - + { + QualificationLabel = "Test qualification label", + BackButton = new NavigationLink + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }, + ErrorText = "Test error text", + ButtonText = "Test button text", + LevelLabel = "Test level label", + DateAddedLabel = "Test date added label", + Heading = "Test heading", + Options = + [ + new Option + { + Label = "yes", + Value = "yes" + }, + new Option + { + Label = "no", + Value = "no" + } + ], + RadioHeading = "Test radio heading", + AwardingOrganisationLabel = "Test awarding organisation label", + ErrorBannerHeading = "Test error banner heading", + ErrorBannerLink = "Test error banner link" + }); + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); controller.ModelState.AddModelError("test", "error"); - + var result = await controller.Confirm(new ConfirmQualificationPageModel()); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; @@ -284,49 +284,49 @@ public async Task Post_InvalidModel_CantFindQualificationId_LogsAndReturnsError( var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(new ConfirmQualificationPage - { - QualificationLabel = "Test qualification label", - BackButton = new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }, - ErrorText = "Test error text", - ButtonText = "Test button text", - LevelLabel = "Test level label", - DateAddedLabel = "Test date added label", - Heading = "Test heading", - Options = - [ - new Option - { - Label = "yes", - Value = "yes" - }, - new Option - { - Label = "no", - Value = "no" - } - ], - RadioHeading = "Test radio heading", - AwardingOrganisationLabel = "Test awarding organisation label", - ErrorBannerHeading = "Test error banner heading", - ErrorBannerLink = "Test error banner link" - }); + { + QualificationLabel = "Test qualification label", + BackButton = new NavigationLink + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }, + ErrorText = "Test error text", + ButtonText = "Test button text", + LevelLabel = "Test level label", + DateAddedLabel = "Test date added label", + Heading = "Test heading", + Options = + [ + new Option + { + Label = "yes", + Value = "yes" + }, + new Option + { + Label = "no", + Value = "no" + } + ], + RadioHeading = "Test radio heading", + AwardingOrganisationLabel = "Test awarding organisation label", + ErrorBannerHeading = "Test error banner heading", + ErrorBannerLink = "Test error banner link" + }); mockContentService.Setup(x => x.GetQualificationById("Some ID")).ReturnsAsync(default(Qualification?)); - + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); - + controller.ModelState.AddModelError("test", "error"); - - var result = await controller.Confirm(new ConfirmQualificationPageModel() + + var result = await controller.Confirm(new ConfirmQualificationPageModel { QualificationId = "Some ID" }); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; @@ -344,50 +344,51 @@ public async Task Post_InvalidModel_BuildsModelWithHasErrorsAndReturns() var mockContentService = new Mock(); mockContentService.Setup(x => x.GetConfirmQualificationPage()).ReturnsAsync(new ConfirmQualificationPage - { - QualificationLabel = "Test qualification label", - BackButton = new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }, - ErrorText = "Test error text", - ButtonText = "Test button text", - LevelLabel = "Test level label", - DateAddedLabel = "Test date added label", - Heading = "Test heading", - Options = - [ - new Option - { - Label = "yes", - Value = "yes" - }, - new Option - { - Label = "no", - Value = "no" - } - ], - RadioHeading = "Test radio heading", - AwardingOrganisationLabel = "Test awarding organisation label", - ErrorBannerHeading = "Test error banner heading", - ErrorBannerLink = "Test error banner link" - }); - - mockContentService.Setup(x => x.GetQualificationById("Some ID")).ReturnsAsync(new Qualification("Some ID", "Qualification Name", "NCFE", 2, "2014", "2019", - "ABC/547/900", "additional requirements")); - + { + QualificationLabel = "Test qualification label", + BackButton = new NavigationLink + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }, + ErrorText = "Test error text", + ButtonText = "Test button text", + LevelLabel = "Test level label", + DateAddedLabel = "Test date added label", + Heading = "Test heading", + Options = + [ + new Option + { + Label = "yes", + Value = "yes" + }, + new Option + { + Label = "no", + Value = "no" + } + ], + RadioHeading = "Test radio heading", + AwardingOrganisationLabel = "Test awarding organisation label", + ErrorBannerHeading = "Test error banner heading", + ErrorBannerLink = "Test error banner link" + }); + + mockContentService.Setup(x => x.GetQualificationById("Some ID")).ReturnsAsync(new Qualification("Some ID", + "Qualification Name", "NCFE", 2, "2014", "2019", + "ABC/547/900", "additional requirements")); + var controller = new ConfirmQualificationController(mockLogger.Object, mockContentService.Object); - + controller.ModelState.AddModelError("test", "error"); - - var result = await controller.Confirm(new ConfirmQualificationPageModel() + + var result = await controller.Confirm(new ConfirmQualificationPageModel { - QualificationId = "Some ID", + QualificationId = "Some ID" }); - + result.Should().NotBeNull(); var resultType = result as ViewResult; @@ -397,11 +398,11 @@ public async Task Post_InvalidModel_BuildsModelWithHasErrorsAndReturns() model.Should().NotBeNull(); model!.BackButton.Should().BeEquivalentTo(new NavigationLink - { - DisplayText = "Test back button", - OpenInNewTab = false, - Href = "/qualifications" - }); + { + DisplayText = "Test back button", + OpenInNewTab = false, + Href = "/qualifications" + }); model.HasErrors.Should().BeTrue(); model.Options.Should().BeEquivalentTo([ new Option @@ -446,7 +447,7 @@ public async Task Post_ValidModel_PassedYes_RedirectsToQualificaitonDetailsActio QualificationId = "TEST-123", ConfirmQualificationAnswer = "yes" }); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; @@ -455,7 +456,7 @@ public async Task Post_ValidModel_PassedYes_RedirectsToQualificaitonDetailsActio actionResult.ControllerName.Should().Be("QualificationDetails"); actionResult.RouteValues.Should().ContainSingle("qualificationId", "TEST-123"); } - + [TestMethod] public async Task Post_ValidModel_PassedAnythingButYes_RedirectsBackToTheQualificationDetailsAction() { @@ -469,7 +470,7 @@ public async Task Post_ValidModel_PassedAnythingButYes_RedirectsBackToTheQualifi QualificationId = "TEST-123", ConfirmQualificationAnswer = "not yes" }); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/CookiesControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/CookiesControllerTests.cs index 4ee480ba..8fe44f0c 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/CookiesControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/CookiesControllerTests.cs @@ -30,8 +30,8 @@ public async Task Index_NoContent_NavigatesToErrorPageAsync() var mockUrlChecker = new Mock(); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); mockContentService.Setup(x => x.GetCookiesPage()).ReturnsAsync((CookiesPage?)default); @@ -82,8 +82,8 @@ public async Task Index_ContentFound_ReturnsCorrectModel() .ReturnsAsync("Test success banner content"); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = await controller.Index(); @@ -130,8 +130,8 @@ public void Accept_EndpointCalled_CallsToSetPreferenceAndChecksUrl() mockUrlChecker.Setup(x => x.IsLocalUrl("some URL")).Returns(true); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = controller.Accept("some URL"); @@ -157,8 +157,8 @@ public void Accept_EndpointCalledWithBadUrl_CallsToSetPreferenceAndRedirectsToCo mockUrlChecker.Setup(x => x.IsLocalUrl("some URL")).Returns(false); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = controller.Accept("some URL"); @@ -184,8 +184,8 @@ public void Reject_EndpointCalled_CallsToRejectAndChecksUrl() mockUrlChecker.Setup(x => x.IsLocalUrl("some URL")).Returns(true); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = controller.Reject("some URL"); @@ -211,8 +211,8 @@ public void Reject_EndpointCalledWithBadUrl_CallsToRejectAndRedirectsToCookiePag mockUrlChecker.Setup(x => x.IsLocalUrl("some URL")).Returns(false); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = controller.Reject("some URL"); @@ -238,8 +238,8 @@ public void HideBanner_EndpointCalled_CallsToSetVisibilityAndChecksUrl() mockUrlChecker.Setup(x => x.IsLocalUrl("some URL")).Returns(true); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = controller.HideBanner("some URL"); @@ -265,8 +265,8 @@ public void HideBanner_EndpointCalledWithBadUrl_CallsToRejectAndRedirectsToCooki mockUrlChecker.Setup(x => x.IsLocalUrl("some URL")).Returns(false); var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object); + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object); var result = controller.HideBanner("some URL"); @@ -294,8 +294,8 @@ public void CookiePreference_Accept_CallsToSetPreferenceAndRedirects() ["UserPreferenceRecorded"] = false }; var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object) + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object) { TempData = tempData }; @@ -327,8 +327,8 @@ public void CookiePreference_Reject_CallsToSetPreferenceAndRedirects() ["UserPreferenceRecorded"] = false }; var controller = new CookiesPreferenceController(mockLogger.Object, mockContentService.Object, - mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, - mockCookieService.Object, mockUrlChecker.Object) + mockHtmlTableRenderer.Object, mockSuccessBannerRenderer.Object, + mockCookieService.Object, mockUrlChecker.Object) { TempData = tempData }; diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/HomeControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/HomeControllerTests.cs index 0261ce67..371fe050 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/HomeControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/HomeControllerTests.cs @@ -24,7 +24,7 @@ public async Task Index_ContentServiceReturnsNoContent_RedirectsToErrorPage() var mockSideRenderer = new Mock(); var mockContentService = new Mock(); var mockUserJourneyCookieService = new Mock(); - + var controller = new HomeController(mockLogger.Object, mockContentService.Object, mockHtmlRenderer.Object, mockSideRenderer.Object, mockUserJourneyCookieService.Object); @@ -50,7 +50,7 @@ public async Task Index_ContentServiceReturnsContent_ReturnsStartPageModel() var mockSideRenderer = new Mock(); var mockContentService = new Mock(); var mockUserJourneyCookieService = new Mock(); - + var controller = new HomeController(mockLogger.Object, mockContentService.Object, mockHtmlRenderer.Object, mockSideRenderer.Object, mockUserJourneyCookieService.Object); @@ -92,7 +92,7 @@ public async Task Index_ContentServiceReturnsContent_ReturnsStartPageModel() model.PreCtaButtonContent.Should().Be(preCtaContentText); model.RightHandSideContent.Should().Be(sideContentText); model.RightHandSideContentHeader.Should().Be(startPageResult.RightHandSideContentHeader); - + mockUserJourneyCookieService.Verify(x => x.ResetUserJourneyCookie(), Times.Once); } } \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QualificationDetailsControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QualificationDetailsControllerTests.cs index a7a22bff..af43be91 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QualificationDetailsControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QualificationDetailsControllerTests.cs @@ -23,9 +23,10 @@ public async Task Index_PassInNullQualificationId_ReturnsBadRequest() var mockContentService = new Mock(); var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); - + var controller = - new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object) + new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object) { ControllerContext = new ControllerContext { @@ -50,9 +51,10 @@ public async Task Index_ContentServiceReturnsNullDetailsPage_RedirectsToHomeErro var mockContentService = new Mock(); var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); - + var controller = - new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object) + new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object) { ControllerContext = new ControllerContext { @@ -82,9 +84,10 @@ public async Task Index_ContentServiceReturnsNoQualification_RedirectsToErrorPag var mockContentService = new Mock(); var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); - + var controller = - new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object) + new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object) { ControllerContext = new ControllerContext { @@ -114,9 +117,10 @@ public async Task Index_ContentServiceReturnsQualification_ReturnsQualificationD var mockContentService = new Mock(); var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); - + var controller = - new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object) + new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object) { ControllerContext = new ControllerContext { @@ -159,17 +163,18 @@ public async Task Get_ReturnsView() mockContentService.Setup(x => x.GetQualificationListPage()).ReturnsAsync(new QualificationListPage { - BackButton = new NavigationLink - { - DisplayText = "TEST", - Href = "/", - OpenInNewTab = false - }, - Header = "TEST" + BackButton = new NavigationLink + { + DisplayText = "TEST", + Href = "/", + OpenInNewTab = false + }, + Header = "TEST" }); - + var controller = - new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object) + new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object) { ControllerContext = new ControllerContext { @@ -192,18 +197,19 @@ public async Task Get_NoContent_LogsAndRedirectsToError() var mockUserJourneyCookieService = new Mock(); mockContentService.Setup(x => x.GetQualificationListPage()).ReturnsAsync(default(QualificationListPage)); - + var controller = - new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object) + new QualificationDetailsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; - + var result = await controller.Get(); - + result.Should().BeOfType(); var actionResult = (RedirectToActionResult)result; diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs index 9c12a1c4..7bcefa89 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/QuestionsControllerTests.cs @@ -28,11 +28,12 @@ public async Task WhereWasTheQualificationAwarded_ContentServiceReturnsNoQuestio var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + mockContentService.Setup(x => x.GetRadioQuestionPage(QuestionPages.WhereWasTheQualificationAwarded)) .ReturnsAsync((RadioQuestionPage?)default).Verifiable(); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhereWasTheQualificationAwarded(); @@ -57,7 +58,7 @@ public async Task WhereWasTheQualificationAwarded_ContentServiceReturnsQuestionP var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + var questionPage = new RadioQuestionPage { Question = "Test question", @@ -67,7 +68,8 @@ public async Task WhereWasTheQualificationAwarded_ContentServiceReturnsQuestionP mockContentService.Setup(x => x.GetRadioQuestionPage(QuestionPages.WhereWasTheQualificationAwarded)) .ReturnsAsync(questionPage); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhereWasTheQualificationAwarded(); @@ -95,8 +97,9 @@ public async Task Post_WhereWasTheQualificationAwarded_InvalidModel_ReturnsQuest var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); controller.ModelState.AddModelError("option", "test error"); var result = await controller.WhereWasTheQualificationAwarded(new RadioQuestionModel()); @@ -107,7 +110,7 @@ public async Task Post_WhereWasTheQualificationAwarded_InvalidModel_ReturnsQuest resultType.Should().NotBeNull(); resultType!.ViewName.Should().Be("Radio"); - + mockUserJourneyCookieService.Verify(x => x.SetWhereWasQualificationAwarded(It.IsAny()), Times.Never); } @@ -119,8 +122,9 @@ public async Task Post_WhereWasTheQualificationAwarded_PassInOutsideUk_Redirects var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhereWasTheQualificationAwarded(new RadioQuestionModel @@ -133,7 +137,7 @@ await controller.WhereWasTheQualificationAwarded(new RadioQuestionModel resultType!.ActionName.Should().Be("QualificationOutsideTheUnitedKingdom"); resultType.ControllerName.Should().Be("Advice"); - + mockUserJourneyCookieService.Verify(x => x.SetWhereWasQualificationAwarded(It.IsAny()), Times.Never); } @@ -145,8 +149,9 @@ public async Task Post_WhereWasTheQualificationAwarded_PassInEngland_RedirectsTo var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhereWasTheQualificationAwarded(new RadioQuestionModel { Option = Options.England }); @@ -157,7 +162,7 @@ public async Task Post_WhereWasTheQualificationAwarded_PassInEngland_RedirectsTo resultType.Should().NotBeNull(); resultType!.ActionName.Should().Be("WhenWasTheQualificationStarted"); - + mockUserJourneyCookieService.Verify(x => x.SetWhereWasQualificationAwarded(Options.England), Times.Once); } @@ -169,7 +174,7 @@ public async Task WhenWasTheQualificationStarted_ReturnsView() var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + var questionPage = new DateQuestionPage { Question = "Test question", @@ -182,7 +187,8 @@ public async Task WhenWasTheQualificationStarted_ReturnsView() mockContentService.Setup(x => x.GetDateQuestionPage(QuestionPages.WhenWasTheQualificationStarted)) .ReturnsAsync(questionPage); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhenWasTheQualificationStarted(); @@ -213,11 +219,12 @@ public async Task WhenWasTheQualificationStarted_CantFindContentfulPage_ReturnsE var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + mockContentService.Setup(x => x.GetDateQuestionPage(QuestionPages.WhenWasTheQualificationStarted)) .ReturnsAsync((DateQuestionPage?)default).Verifiable(); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhenWasTheQualificationStarted(); @@ -239,8 +246,9 @@ public async Task Post_WhenWasTheQualificationStarted_InvalidModel_ReturnsDateQu var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); controller.ModelState.AddModelError("option", "test error"); var result = await controller.WhenWasTheQualificationStarted(new DateQuestionModel()); @@ -251,7 +259,7 @@ public async Task Post_WhenWasTheQualificationStarted_InvalidModel_ReturnsDateQu resultType.Should().NotBeNull(); resultType!.ViewName.Should().Be("Date"); - + mockUserJourneyCookieService.Verify(x => x.SetWhenWasQualificationAwarded(It.IsAny()), Times.Never); } @@ -268,7 +276,7 @@ public async Task Post_WhenWasTheQualificationStarted_PassedInvalidValues_Return var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + var questionPage = new DateQuestionPage { Question = "Test question", @@ -281,7 +289,8 @@ public async Task Post_WhenWasTheQualificationStarted_PassedInvalidValues_Return mockContentService.Setup(x => x.GetDateQuestionPage(QuestionPages.WhenWasTheQualificationStarted)) .ReturnsAsync(questionPage); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhenWasTheQualificationStarted(new DateQuestionModel { @@ -294,7 +303,7 @@ public async Task Post_WhenWasTheQualificationStarted_PassedInvalidValues_Return var model = resultType!.Model as DateQuestionModel; model.Should().NotBeNull(); - + model!.Question.Should().Be(questionPage.Question); model.CtaButtonText.Should().Be(questionPage.CtaButtonText); model.HasErrors.Should().BeTrue(); @@ -302,7 +311,7 @@ public async Task Post_WhenWasTheQualificationStarted_PassedInvalidValues_Return model.MonthLabel.Should().Be(questionPage.MonthLabel); model.YearLabel.Should().Be(questionPage.YearLabel); model.QuestionHint.Should().Be(questionPage.QuestionHint); - + mockUserJourneyCookieService.Verify(x => x.SetWhenWasQualificationAwarded(It.IsAny()), Times.Never); } @@ -314,7 +323,7 @@ public async Task Post_WhenWasTheQualificationStarted_YearProvidedIsNextYear_Ret var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + var questionPage = new DateQuestionPage { Question = "Test question", @@ -327,7 +336,8 @@ public async Task Post_WhenWasTheQualificationStarted_YearProvidedIsNextYear_Ret mockContentService.Setup(x => x.GetDateQuestionPage(QuestionPages.WhenWasTheQualificationStarted)) .ReturnsAsync(questionPage); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhenWasTheQualificationStarted(new DateQuestionModel { @@ -340,7 +350,7 @@ public async Task Post_WhenWasTheQualificationStarted_YearProvidedIsNextYear_Ret var model = resultType!.Model as DateQuestionModel; model.Should().NotBeNull(); - + model!.Question.Should().Be(questionPage.Question); model.CtaButtonText.Should().Be(questionPage.CtaButtonText); model.HasErrors.Should().BeTrue(); @@ -348,7 +358,7 @@ public async Task Post_WhenWasTheQualificationStarted_YearProvidedIsNextYear_Ret model.MonthLabel.Should().Be(questionPage.MonthLabel); model.YearLabel.Should().Be(questionPage.YearLabel); model.QuestionHint.Should().Be(questionPage.QuestionHint); - + mockUserJourneyCookieService.Verify(x => x.SetWhenWasQualificationAwarded(It.IsAny()), Times.Never); } @@ -360,8 +370,9 @@ public async Task Post_WhenWasTheQualificationStarted_ValidModel_ReturnsRedirect var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhenWasTheQualificationStarted(new DateQuestionModel { @@ -375,7 +386,7 @@ public async Task Post_WhenWasTheQualificationStarted_ValidModel_ReturnsRedirect resultType.Should().NotBeNull(); resultType!.ActionName.Should().Be("WhatLevelIsTheQualification"); - + mockUserJourneyCookieService.Verify(x => x.SetWhenWasQualificationAwarded("12/2024"), Times.Once); } @@ -387,11 +398,12 @@ public async Task WhatLevelIsTheQualification_ContentServiceReturnsNoQuestionPag var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + mockContentService.Setup(x => x.GetRadioQuestionPage(QuestionPages.WhatLevelIsTheQualification)) .ReturnsAsync((RadioQuestionPage?)default).Verifiable(); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatLevelIsTheQualification(); @@ -416,7 +428,7 @@ public async Task WhatLevelIsTheQualification_ContentServiceReturnsQuestionPage_ var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + var questionPage = new RadioQuestionPage { Question = "Test question", @@ -430,7 +442,8 @@ public async Task WhatLevelIsTheQualification_ContentServiceReturnsQuestionPage_ mockRenderer.Setup(x => x.ToHtml(It.IsAny())).ReturnsAsync("Test html body"); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatLevelIsTheQualification(); @@ -462,8 +475,9 @@ public async Task Post_WhatLevelIsTheQualification_InvalidModel_ReturnsQuestionP var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); controller.ModelState.AddModelError("option", "test error"); var result = await controller.WhatLevelIsTheQualification(new RadioQuestionModel()); @@ -474,7 +488,7 @@ public async Task Post_WhatLevelIsTheQualification_InvalidModel_ReturnsQuestionP resultType.Should().NotBeNull(); resultType!.ViewName.Should().Be("Radio"); - + mockUserJourneyCookieService.Verify(x => x.SetLevelOfQualification(It.IsAny()), Times.Never); } @@ -486,8 +500,9 @@ public async Task Post_WhatLevelIsTheQualification_ReturnsRedirectResponse() var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatLevelIsTheQualification(new RadioQuestionModel { @@ -500,10 +515,10 @@ public async Task Post_WhatLevelIsTheQualification_ReturnsRedirectResponse() resultType.Should().NotBeNull(); resultType!.ActionName.Should().Be("WhatIsTheAwardingOrganisation"); - + mockUserJourneyCookieService.Verify(x => x.SetLevelOfQualification("2"), Times.Once); } - + [TestMethod] public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsNoQuestionPage_RedirectsToErrorPage() { @@ -512,11 +527,12 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsNoQuestionP var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync((DropdownQuestionPage?)default).Verifiable(); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatIsTheAwardingOrganisation(); @@ -541,7 +557,7 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQuestionPag var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - + var questionPage = new DropdownQuestionPage { Question = "Test question", @@ -551,15 +567,17 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQuestionPag NotInListText = "Test not in the list text", DefaultText = "Test default text" }; - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync(questionPage); mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel()); - mockContentFilterService.Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync([]); + mockContentFilterService + .Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync([]); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatIsTheAwardingOrganisation(); @@ -581,9 +599,10 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQuestionPag model.Values[0].Value.Should().BeEmpty(); model.NotInListText.Should().Be(questionPage.NotInListText); } - + [TestMethod] - public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualifications_OrdersAwardingOrganisationsInModel() + public async Task + WhatIsTheAwardingOrganisation_ContentServiceReturnsQualifications_OrdersAwardingOrganisationsInModel() { var mockLogger = new Mock>(); var mockContentService = new Mock(); @@ -595,7 +614,7 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificati { DefaultText = "Test default text" }; - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync(questionPage); @@ -605,24 +624,26 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificati "D awarding organisation", 123, null, null, null, null), new("2", "TEST", - "E awarding organisation", 123, null, - null, null, null), + "E awarding organisation", 123, null, + null, null, null), new("3", "TEST", - "A awarding organisation", 123, null, - null, null, null), + "A awarding organisation", 123, null, + null, null, null), new("4", "TEST", - "C awarding organisation", 123, null, - null, null, null), + "C awarding organisation", 123, null, + null, null, null), new("5", "TEST", - "B awarding organisation", 123, null, - null, null, null) + "B awarding organisation", 123, null, + null, null, null) }; - + mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel()); - mockContentFilterService.Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(listOfQualifications); + mockContentFilterService + .Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(listOfQualifications); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatIsTheAwardingOrganisation(); @@ -646,9 +667,10 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificati model.Values[4].Text.Should().Be("D awarding organisation"); model.Values[5].Text.Should().Be("E awarding organisation"); } - + [TestMethod] - public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificationsWithVariousOrHigherEducation_FiltersThemOutOfResponse() + public async Task + WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificationsWithVariousOrHigherEducation_FiltersThemOutOfResponse() { var mockLogger = new Mock>(); var mockContentService = new Mock(); @@ -660,7 +682,7 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificati { DefaultText = "Test default text" }; - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync(questionPage); @@ -670,21 +692,23 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificati "D awarding organisation", 123, null, null, null, null), new("2", "TEST", - "E awarding organisation", 123, null, - null, null, null), + "E awarding organisation", 123, null, + null, null, null), new("3", "TEST", - "Various Awarding Organisations", 123, null, - null, null, null), + "Various Awarding Organisations", 123, null, + null, null, null), new("4", "TEST", - "All Higher Education Institutes", 123, null, - null, null, null) + "All Higher Education Institutes", 123, null, + null, null, null) }; - + mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel()); - mockContentFilterService.Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(listOfQualifications); + mockContentFilterService + .Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(listOfQualifications); - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var result = await controller.WhatIsTheAwardingOrganisation(); @@ -702,7 +726,7 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQualificati model.Values[1].Text.Should().Be("D awarding organisation"); model.Values[2].Text.Should().Be("E awarding organisation"); } - + [TestMethod] public async Task Post_WhatIsTheAwardingOrganisation_InvalidModel_ReturnsQuestionPage() { @@ -711,8 +735,9 @@ public async Task Post_WhatIsTheAwardingOrganisation_InvalidModel_ReturnsQuestio var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var questionPage = new DropdownQuestionPage { @@ -723,13 +748,15 @@ public async Task Post_WhatIsTheAwardingOrganisation_InvalidModel_ReturnsQuestio NotInListText = "Test not in the list text", DefaultText = "Test default text" }; - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync(questionPage); mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel()); - mockContentFilterService.Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync([]); - + mockContentFilterService + .Setup(x => x.GetFilteredQualifications(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync([]); + controller.ModelState.AddModelError("option", "test error"); var result = await controller.WhatIsTheAwardingOrganisation(new DropdownQuestionModel()); @@ -739,15 +766,15 @@ public async Task Post_WhatIsTheAwardingOrganisation_InvalidModel_ReturnsQuestio resultType.Should().NotBeNull(); resultType!.ViewName.Should().Be("Dropdown"); - + var model = resultType.Model as DropdownQuestionModel; model.Should().NotBeNull(); model!.HasErrors.Should().BeTrue(); - + mockUserJourneyCookieService.Verify(x => x.SetAwardingOrganisation(It.IsAny()), Times.Never); } - + [TestMethod] public async Task Post_WhatIsTheAwardingOrganisation_NoValueSelectedAndNotInListNotSelected_ReturnsQuestionPage() { @@ -756,9 +783,10 @@ public async Task Post_WhatIsTheAwardingOrganisation_NoValueSelectedAndNotInList var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); - + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); + var result = await controller.WhatIsTheAwardingOrganisation(new DropdownQuestionModel { SelectedValue = string.Empty, @@ -769,22 +797,24 @@ public async Task Post_WhatIsTheAwardingOrganisation_NoValueSelectedAndNotInList var resultType = result as ViewResult; resultType.Should().NotBeNull(); - + resultType!.ViewName.Should().Be("Dropdown"); - + mockUserJourneyCookieService.Verify(x => x.SetAwardingOrganisation(It.IsAny()), Times.Never); } - + [TestMethod] - public async Task Post_WhatIsTheAwardingOrganisation_AwardingOrgPassedIn_SetsJourneyCookieAndRedirectsToTheQualificationListPage() + public async Task + Post_WhatIsTheAwardingOrganisation_AwardingOrgPassedIn_SetsJourneyCookieAndRedirectsToTheQualificationListPage() { var mockLogger = new Mock>(); var mockContentService = new Mock(); var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var questionPage = new DropdownQuestionPage { @@ -795,12 +825,12 @@ public async Task Post_WhatIsTheAwardingOrganisation_AwardingOrgPassedIn_SetsJou NotInListText = "Test not in the list text", DefaultText = "Test default text" }; - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync(questionPage); - + mockContentService.Setup(x => x.GetQualifications()).ReturnsAsync([]); - + var result = await controller.WhatIsTheAwardingOrganisation(new DropdownQuestionModel { SelectedValue = "Some Awarding Organisation", @@ -815,20 +845,22 @@ public async Task Post_WhatIsTheAwardingOrganisation_AwardingOrgPassedIn_SetsJou resultType!.ActionName.Should().Be("Get"); resultType.ControllerName.Should().Be("QualificationDetails"); - + mockUserJourneyCookieService.Verify(x => x.SetAwardingOrganisation("Some Awarding Organisation"), Times.Once); } - + [TestMethod] - public async Task Post_WhatIsTheAwardingOrganisation_NotInTheListPassedIn_DoesNotSetsJourneyCookieAndRedirectsToTheQualificationListPage() + public async Task + Post_WhatIsTheAwardingOrganisation_NotInTheListPassedIn_DoesNotSetsJourneyCookieAndRedirectsToTheQualificationListPage() { var mockLogger = new Mock>(); var mockContentService = new Mock(); var mockRenderer = new Mock(); var mockUserJourneyCookieService = new Mock(); var mockContentFilterService = new Mock(); - - var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object); + + var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, + mockUserJourneyCookieService.Object, mockContentFilterService.Object); var questionPage = new DropdownQuestionPage { @@ -839,12 +871,12 @@ public async Task Post_WhatIsTheAwardingOrganisation_NotInTheListPassedIn_DoesNo NotInListText = "Test not in the list text", DefaultText = "Test default text" }; - + mockContentService.Setup(x => x.GetDropdownQuestionPage(QuestionPages.WhatIsTheAwardingOrganisation)) .ReturnsAsync(questionPage); - + mockContentService.Setup(x => x.GetQualifications()).ReturnsAsync([]); - + var result = await controller.WhatIsTheAwardingOrganisation(new DropdownQuestionModel { SelectedValue = "", @@ -859,7 +891,7 @@ public async Task Post_WhatIsTheAwardingOrganisation_NotInTheListPassedIn_DoesNo resultType!.ActionName.Should().Be("Get"); resultType.ControllerName.Should().Be("QualificationDetails"); - + mockUserJourneyCookieService.Verify(x => x.SetAwardingOrganisation(string.Empty), Times.Once); } } \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Extensions/MockLoggerExtensions.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Extensions/MockLoggerExtensions.cs index 43f0b5c7..4f0fb2a4 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Extensions/MockLoggerExtensions.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Extensions/MockLoggerExtensions.cs @@ -17,7 +17,7 @@ public static void VerifyWarning(this Mock> mockLogger, string exp public static void VerifyCritical(this Mock> mockLogger, string expectedMessage) { - Verify(mockLogger, LogLevel.Critical, expectedMessage, Times.Once); + Verify(mockLogger, LogLevel.Critical, expectedMessage, Times.Once); } private static void Verify(Mock> mockLogger, diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs index 9a51be98..6572bf86 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs @@ -7,14 +7,15 @@ namespace Dfe.EarlyYearsQualification.UnitTests.Mocks; public class MockContentfulFilterServiceTests { [TestMethod] - [DataRow(2, new [] { "EYQ-100", "EYQ-101" })] - [DataRow(3, new [] { "EYQ-102", "EYQ-103" })] - [DataRow(4, new [] { "EYQ-104", "EYQ-105" })] - [DataRow(5, new [] { "EYQ-106", "EYQ-107" })] - [DataRow(6, new [] { "EYQ-108", "EYQ-109" })] - [DataRow(7, new [] { "EYQ-110", "EYQ-111" })] - [DataRow(8, new [] { "EYQ-112", "EYQ-113" })] - public async Task GetFilteredQualifications_PassInLevel_ReturnsQualifications(int level, string[] expectedQualifications) + [DataRow(2, new[] { "EYQ-100", "EYQ-101" })] + [DataRow(3, new[] { "EYQ-102", "EYQ-103" })] + [DataRow(4, new[] { "EYQ-104", "EYQ-105" })] + [DataRow(5, new[] { "EYQ-106", "EYQ-107" })] + [DataRow(6, new[] { "EYQ-108", "EYQ-109" })] + [DataRow(7, new[] { "EYQ-110", "EYQ-111" })] + [DataRow(8, new[] { "EYQ-112", "EYQ-113" })] + public async Task GetFilteredQualifications_PassInLevel_ReturnsQualifications( + int level, string[] expectedQualifications) { var mockContentFilterService = new MockContentfulFilterService(); var results = await mockContentFilterService.GetFilteredQualifications(level, null, null); diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs index e69ae833..6a1e9445 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs @@ -50,7 +50,7 @@ public async Task GetAdvicePage_Level2SeptAndAug_ReturnsExpectedDetails() public async Task GetAdvicePage_UnknownEntryId_ReturnsException() { var contentfulService = new MockContentfulService(); - + var page = await contentfulService.GetAdvicePage("Invalid entry Id"); page.Should().BeNull(); diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs index 7d1ef514..3cec549c 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs @@ -212,11 +212,11 @@ private static void CheckSerializedModelWasSet(Mock mockCo http.HttpContext!.Response.Cookies.Append(CookieKeyNames.UserJourneyKey, serializedModelToCheck, It.Is( - options => - options.Secure - && options.HttpOnly - && options.Expires > in364Days - && options.Expires < inOneYear) + options => + options.Secure + && options.HttpOnly + && options.Expires > in364Days + && options.Expires < inOneYear) ), Times.Once); } diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Setup/MockContentfulSetupTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Setup/MockContentfulSetupTests.cs index b3e79a7b..f73fa6ab 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Setup/MockContentfulSetupTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Setup/MockContentfulSetupTests.cs @@ -33,12 +33,12 @@ public void MockContentfulSetup_AddsMockContentfulSingletons() _ = ServiceCollectionExtensions.AddMockContentfulServices(services.Object); serviceList.Count.Should().Be(2); - + var service = serviceList.First(); service.ImplementationType.Should().Be(typeof(MockContentfulService)); service.ServiceType.Should().Be(typeof(IContentService)); service.Lifetime.Should().Be(ServiceLifetime.Singleton); - + var filterService = serviceList[1]; filterService.ImplementationType.Should().Be(typeof(MockContentfulFilterService)); filterService.ServiceType.Should().Be(typeof(IContentFilterService)); From e2ef277cfab974779339dc4225e1afc9185d4b51 Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:00:37 +0100 Subject: [PATCH 2/8] ReSharper suggestions and simplifications. --- .../Program.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs b/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs index 8ddc4ad8..2e9deebb 100644 --- a/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs +++ b/content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs @@ -10,12 +10,14 @@ namespace Dfe.EarlyYearsQualification.ContentUpload; [ExcludeFromCodeCoverage] -public class Program +public static class Program { private const string Locale = "en-US"; private const string SpaceId = ""; private const string ManagementApiKey = ""; + // ReSharper disable once UnusedParameter.Global + // ...args standard for Program.Main() public static async Task Main(string[] args) { var client = new ContentfulManagementClient(new HttpClient(), @@ -69,9 +71,7 @@ private static async Task SetUpContentModels(ContentfulManagementClient client) var currentModel = currentModels.FirstOrDefault(x => x.SystemProperties.Id == "Qualification"); - var version = currentModel != null && currentModel.SystemProperties.Version != null - ? currentModel.SystemProperties.Version!.Value - : 1; + var version = currentModel?.SystemProperties.Version ?? 1; var contentType = new ContentType { @@ -90,10 +90,7 @@ private static async Task SetUpContentModels(ContentfulManagementClient client) Id = "qualificationId", Type = "Symbol", Required = true, - Validations = new List - { - new UniqueValidator() - } + Validations = [new UniqueValidator()] }, new Field { @@ -238,7 +235,7 @@ private static Entry BuildEntryFromQualification(Qualification qualific private static List GetQualificationsToAddOrUpdate() { - var lines = ReadCsvFile(@"./csv/ey-quals-full-2024-updated.csv"); + var lines = ReadCsvFile("./csv/ey-quals-full-2024-updated.csv"); var listObjResult = new List(); From d14a9be83ef71ecc87d6e0b18867cd9cd6a6c696 Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:03:42 +0100 Subject: [PATCH 3/8] Setters can be init. No need to initialise bool to its default value. --- .../Entities/DropdownQuestionPage.cs | 2 +- .../Entities/QualificationListPage.cs | 4 ++-- .../Models/Content/ConfirmQualificationPageModel.cs | 2 +- .../Models/Content/QualificationDetailsModel.cs | 2 +- .../Models/Content/QualificationListModel.cs | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs index 08e93658..b0a548b7 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/DropdownQuestionPage.cs @@ -14,5 +14,5 @@ public class DropdownQuestionPage public string DefaultText { get; init; } = string.Empty; - public NavigationLink? BackButton { get; set; } + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs b/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs index ec7563e0..8c7b5b3d 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Entities/QualificationListPage.cs @@ -2,7 +2,7 @@ namespace Dfe.EarlyYearsQualification.Content.Entities; public class QualificationListPage { - public string Header { get; set; } = string.Empty; + public string Header { get; init; } = string.Empty; - public NavigationLink? BackButton { get; set; } + public NavigationLink? BackButton { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/ConfirmQualificationPageModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/ConfirmQualificationPageModel.cs index 641c8a15..74a593bb 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/ConfirmQualificationPageModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/ConfirmQualificationPageModel.cs @@ -13,7 +13,7 @@ public class ConfirmQualificationPageModel public string DateAddedLabel { get; init; } = string.Empty; public string RadioHeading { get; init; } = string.Empty; public List Options { get; init; } = []; - public bool HasErrors { get; set; } = false; + public bool HasErrors { get; set; } public string ErrorBannerHeading { get; init; } = string.Empty; public string ErrorBannerLink { get; init; } = string.Empty; public string ErrorText { get; init; } = string.Empty; diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs index de0acc79..938f2155 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationDetailsModel.cs @@ -16,7 +16,7 @@ public class QualificationDetailsModel public string BookmarkUrl { get; init; } = string.Empty; - public NavigationLink? BackButton { get; set; } + public NavigationLink? BackButton { get; init; } public DetailsPageModel? Content { get; init; } } \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs index e7dad2aa..28acd14d 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QualificationListModel.cs @@ -4,9 +4,9 @@ namespace Dfe.EarlyYearsQualification.Web.Models.Content; public class QualificationListModel { - public string Header { get; set; } = string.Empty; + public string Header { get; init; } = string.Empty; - public UserJourneyModel? Filters { get; set; } + public UserJourneyModel? Filters { get; init; } - public NavigationLink? BackButton { get; set; } + public NavigationLink? BackButton { get; init; } } \ No newline at end of file From 5a259b84935f2ac521dae5f78aee43ff680c6b63 Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:04:54 +0100 Subject: [PATCH 4/8] Avoid future warnings --- .../Services/ContentfulContentFilterService.cs | 2 ++ .../Mocks/MockContentfulFilterServiceTests.cs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentFilterService.cs b/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentFilterService.cs index b84a1fb3..d968f18a 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentFilterService.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentFilterService.cs @@ -94,6 +94,8 @@ private List FilterQualificationsByDate(int startDateMonth, int s } else if (qualificationStartDate is null && qualificationEndDate is not null + // ReSharper disable once MergeSequentialChecks + // ...this more clearly reveals intention && enteredStartDate <= qualificationEndDate) { // if qualification start date is null, check entered start date is <= ToWhichYear & add to results diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs index 6572bf86..a042f0c9 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulFilterServiceTests.cs @@ -7,6 +7,9 @@ namespace Dfe.EarlyYearsQualification.UnitTests.Mocks; public class MockContentfulFilterServiceTests { [TestMethod] +#pragma warning disable CA1861 + // An attribute argument must be a constant expression, 'typeof()' expression or array creation + // expression of an attribute parameter type [DataRow(2, new[] { "EYQ-100", "EYQ-101" })] [DataRow(3, new[] { "EYQ-102", "EYQ-103" })] [DataRow(4, new[] { "EYQ-104", "EYQ-105" })] @@ -14,6 +17,7 @@ public class MockContentfulFilterServiceTests [DataRow(6, new[] { "EYQ-108", "EYQ-109" })] [DataRow(7, new[] { "EYQ-110", "EYQ-111" })] [DataRow(8, new[] { "EYQ-112", "EYQ-113" })] +#pragma warning restore CA1861 public async Task GetFilteredQualifications_PassInLevel_ReturnsQualifications( int level, string[] expectedQualifications) { From a1387568b99234524e24ec72128c2053726bb4d4 Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:07:19 +0100 Subject: [PATCH 5/8] Invert if to reduce nesting (actually, mostly don't). --- .../Services/ContentfulContentService.cs | 12 ++++ .../ConfirmQualificationController.cs | 65 ++++++++++--------- .../Controllers/QuestionsController.cs | 2 + 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs b/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs index 373cc47a..2eb740f9 100644 --- a/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs +++ b/src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs @@ -35,6 +35,8 @@ private readonly Dictionary _contentTypes public async Task GetStartPage() { var startPageEntries = await GetEntriesByType(); + + // ReSharper disable once InvertIf if (startPageEntries is null || !startPageEntries.Any()) { logger.LogWarning("No start page entry returned"); @@ -60,6 +62,8 @@ private readonly Dictionary _contentTypes public async Task GetAccessibilityStatementPage() { var accessibilityStatementEntities = await GetEntriesByType(); + + // ReSharper disable once InvertIf if (accessibilityStatementEntities is null || !accessibilityStatementEntities.Any()) { logger.LogWarning("No accessibility statement page entry returned"); @@ -116,6 +120,8 @@ public async Task> GetNavigationLinks() public async Task GetAdvicePage(string entryId) { var advicePage = await GetEntryById(entryId); + + // ReSharper disable once InvertIf if (advicePage is null) { logger.LogWarning("Advice page with {EntryID} could not be found", entryId); @@ -143,6 +149,8 @@ public async Task> GetNavigationLinks() public async Task GetPhaseBannerContent() { var phaseBannerEntities = await GetEntriesByType(); + + // ReSharper disable once InvertIf if (phaseBannerEntities is null || !phaseBannerEntities.Any()) { logger.LogWarning("No phase banner entry returned"); @@ -155,6 +163,8 @@ public async Task> GetNavigationLinks() public async Task GetCookiesBannerContent() { var cookiesBannerEntry = await GetEntriesByType(); + + // ReSharper disable once InvertIf if (cookiesBannerEntry is null || !cookiesBannerEntry.Any()) { logger.LogWarning("No cookies banner entry returned"); @@ -173,6 +183,8 @@ public async Task> GetQualifications() public async Task GetConfirmQualificationPage() { var confirmQualificationEntities = await GetEntriesByType(); + + // ReSharper disable once InvertIf if (confirmQualificationEntities is null || !confirmQualificationEntities.Any()) { logger.LogWarning("No confirm qualification page entry returned"); diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs index 5ec8664b..f1dab374 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/ConfirmQualificationController.cs @@ -48,41 +48,42 @@ public async Task Index(string qualificationId) [HttpPost] public async Task Confirm(ConfirmQualificationPageModel model) { - if (!ModelState.IsValid) + if (ModelState.IsValid) { - var content = await contentService.GetConfirmQualificationPage(); - - if (content is null) - { - logger.LogError("No content for the cookies page"); - return RedirectToAction("Index", "Error"); - } - - if (string.IsNullOrEmpty(model.QualificationId)) - { - logger.LogError("No qualification id provided"); - return RedirectToAction("Index", "Error"); - } - - var qualification = await contentService.GetQualificationById(model.QualificationId); - if (qualification is null) - { - var loggedQualificationId = model.QualificationId.Replace(Environment.NewLine, ""); - logger.LogError("Could not find details for qualification with ID: {QualificationId}", - loggedQualificationId); - - return RedirectToAction("Index", "Error"); - } - - model = Map(content, qualification); - model.HasErrors = true; - - return View("Index", model); + return model.ConfirmQualificationAnswer == "yes" + ? RedirectToAction("Index", "QualificationDetails", + new { qualificationId = model.QualificationId }) + : RedirectToAction("Get", "QualificationDetails"); } - return model.ConfirmQualificationAnswer == "yes" - ? RedirectToAction("Index", "QualificationDetails", new { qualificationId = model.QualificationId }) - : RedirectToAction("Get", "QualificationDetails"); + var content = await contentService.GetConfirmQualificationPage(); + + if (content is null) + { + logger.LogError("No content for the cookies page"); + return RedirectToAction("Index", "Error"); + } + + if (string.IsNullOrEmpty(model.QualificationId)) + { + logger.LogError("No qualification id provided"); + return RedirectToAction("Index", "Error"); + } + + var qualification = await contentService.GetQualificationById(model.QualificationId); + if (qualification is null) + { + var loggedQualificationId = model.QualificationId.Replace(Environment.NewLine, ""); + logger.LogError("Could not find details for qualification with ID: {QualificationId}", + loggedQualificationId); + + return RedirectToAction("Index", "Error"); + } + + model = Map(content, qualification); + model.HasErrors = true; + + return View("Index", model); } private static ConfirmQualificationPageModel Map(ConfirmQualificationPage content, Qualification qualification) diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs index c4d8b282..1a7953f7 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs @@ -36,6 +36,8 @@ public async Task WhereWasTheQualificationAwarded(RadioQuestionMo if (!ModelState.IsValid) { var questionPage = await contentService.GetRadioQuestionPage(QuestionPages.WhereWasTheQualificationAwarded); + + // ReSharper disable once InvertIf if (questionPage is not null) { model = await MapRadioModel(model, questionPage, nameof(this.WhereWasTheQualificationAwarded), From 34a52e20d20b7a79c5a1b632e5ba94a68e4fd3fc Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:08:20 +0100 Subject: [PATCH 6/8] This private method can be static. --- .../Controllers/QualificationDetailsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs index e6e0c6a7..80b04f61 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/QualificationDetailsController.cs @@ -64,7 +64,7 @@ public async Task Index(string qualificationId) return View(model); } - private QualificationListModel MapList(QualificationListPage content, UserJourneyModel? filters) + private static QualificationListModel MapList(QualificationListPage content, UserJourneyModel? filters) { return new QualificationListModel { From f42666878e919661f8149e11099f4a3a5a7f0daf Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:09:32 +0100 Subject: [PATCH 7/8] ReSharper suggest merging into pattern --- .../Models/Content/QuestionModels/DateQuestionModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs index afa32feb..d1e75db1 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Models/Content/QuestionModels/DateQuestionModel.cs @@ -16,7 +16,7 @@ public class DateQuestionModel : BaseQuestionModel public bool IsModelValid() { - if (SelectedMonth < 1 || SelectedMonth > 12) + if (SelectedMonth is < 1 or > 12) { return false; } From f6550ae843feae24a6b38aecee681cc8eabb05e7 Mon Sep 17 00:00:00 2001 From: RobertGHippo Date: Wed, 3 Jul 2024 18:10:43 +0100 Subject: [PATCH 8/8] Doesn't need comment as a switch case statement. --- .../ChallengeResourceFilterAttribute.cs | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Dfe.EarlyYearsQualification.Web/Filters/ChallengeResourceFilterAttribute.cs b/src/Dfe.EarlyYearsQualification.Web/Filters/ChallengeResourceFilterAttribute.cs index 9acdf910..04f2d453 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Filters/ChallengeResourceFilterAttribute.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Filters/ChallengeResourceFilterAttribute.cs @@ -73,20 +73,16 @@ public void OnResourceExecuting(ResourceExecutingContext context) var cookieIsPresent = context.HttpContext.Request.Cookies.ContainsKey(AuthSecretCookieName); - if (cookieIsPresent && ConfiguredKeys.Contains(context.HttpContext.Request.Cookies[AuthSecretCookieName])) + switch (cookieIsPresent) { - return; - } - - // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression - // ..."the logging message template should not vary between calls to LoggerExtensions.LogWarning(ILogger, string?, params object?[])" - if (cookieIsPresent) - { - logger.LogWarning($"Access denied by {nameof(ChallengeResourceFilterAttribute)} (incorrect value submitted)"); - } - else - { - logger.LogWarning($"Access denied by {nameof(ChallengeResourceFilterAttribute)}"); + case true when ConfiguredKeys.Contains(context.HttpContext.Request.Cookies[AuthSecretCookieName]): + return; + case true: + logger.LogWarning($"Access denied by {nameof(ChallengeResourceFilterAttribute)} (incorrect value submitted)"); + break; + default: + logger.LogWarning($"Access denied by {nameof(ChallengeResourceFilterAttribute)}"); + break; } var requestedPath = context.HttpContext.Request.Path;