Skip to content

Commit

Permalink
ReSharper & Sonar suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGHippo committed Jul 8, 2024
1 parent 54c8740 commit c615f11
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<IActionResult> Get()
[HttpGet("qualification-details/{qualificationId}")]
public async Task<IActionResult> Index(string qualificationId)
{
if (string.IsNullOrEmpty(qualificationId))
if (!ModelState.IsValid || string.IsNullOrEmpty(qualificationId))
{
return BadRequest();
}
Expand All @@ -63,17 +63,19 @@ public async Task<IActionResult> Index(string qualificationId)
var model = await MapDetails(qualification, detailsPageContent);
return View(model);
}

private async Task<List<Qualification>> GetFilteredQualifications()
{
var level = userJourneyCookieService.GetLevelOfQualification();
(int? startDateMonth, int? startDateYear) = userJourneyCookieService.GetWhenWasQualificationAwarded();
var (startDateMonth, startDateYear) = userJourneyCookieService.GetWhenWasQualificationAwarded();
var awardingOrganisation = userJourneyCookieService.GetAwardingOrganisation();

return await contentFilterService.GetFilteredQualifications(level, startDateMonth, startDateYear, awardingOrganisation);
return await contentFilterService.GetFilteredQualifications(level, startDateMonth, startDateYear,
awardingOrganisation);
}

private async Task<QualificationListModel> MapList(QualificationListPage content, List<Qualification>? qualifications)
private async Task<QualificationListModel> MapList(QualificationListPage content,
List<Qualification>? qualifications)
{
var basicQualificationsModels = GetBasicQualificationsModels(qualifications);

Expand Down Expand Up @@ -104,7 +106,7 @@ private FilterModel GetFilterModel()
Country = userJourneyCookieService.GetWhereWasQualificationAwarded()!
};

(int? startDateMonth, int? startDateYear) = userJourneyCookieService.GetWhenWasQualificationAwarded();
var (startDateMonth, startDateYear) = userJourneyCookieService.GetWhenWasQualificationAwarded();
if (startDateMonth is not null && startDateYear is not null)
{
var date = new DateOnly(startDateYear.Value, startDateMonth.Value, 1);
Expand Down Expand Up @@ -133,11 +135,11 @@ private static List<BasicQualificationModel> GetBasicQualificationsModels(List<Q
{
foreach (var qualification in qualifications)
{
basicQualificationsModels.Add(new BasicQualificationModel()
basicQualificationsModels.Add(new BasicQualificationModel
{
QualificationId = qualification.QualificationId,
QualificationLevel = qualification.QualificationLevel,
QualificationName = qualification.QualificationName,
QualificationId = qualification.QualificationId,
QualificationLevel = qualification.QualificationLevel,
QualificationName = qualification.QualificationName,
AwardingOrganisationTitle = qualification.AwardingOrganisationTitle
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Dfe.EarlyYearsQualification.Web.Models.Content;

public class FilterModel
{
public string Country { get; set; } = string.Empty;
public string Country { get; init; } = string.Empty;

public string StartDate { get; set; } = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ public async Task Post_WhatLevelIsTheQualification_ReturnsRedirectResponse()
resultType.Should().NotBeNull();

resultType!.ActionName.Should().Be("WhatIsTheAwardingOrganisation");

mockUserJourneyCookieService.Verify(x => x.SetLevelOfQualification("3"), Times.Once);
}

[TestMethod]
public async Task Post_WhatLevelIsTheQualification_Level2WithInDate_ReturnsRedirectResponse()
{
Expand All @@ -529,8 +529,9 @@ public async Task Post_WhatLevelIsTheQualification_Level2WithInDate_ReturnsRedir
var mockContentFilterService = new Mock<IContentFilterService>();

mockUserJourneyCookieService.Setup(x => x.GetWhenWasQualificationAwarded())
.Returns((6,2015));
var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object, mockUserJourneyCookieService.Object, mockContentFilterService.Object);
.Returns((6, 2015));
var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object,
mockUserJourneyCookieService.Object, mockContentFilterService.Object);

var result = await controller.WhatLevelIsTheQualification(new RadioQuestionModel
{
Expand All @@ -543,7 +544,7 @@ public async Task Post_WhatLevelIsTheQualification_Level2WithInDate_ReturnsRedir
resultType.Should().NotBeNull();

resultType!.ActionName.Should().Be("QualificationsStartedBetweenSept2014AndAug2019");
resultType!.ControllerName.Should().Be("Advice");
resultType.ControllerName.Should().Be("Advice");
}

[TestMethod]
Expand Down Expand Up @@ -600,7 +601,11 @@ public async Task WhatIsTheAwardingOrganisation_ContentServiceReturnsQuestionPag

mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel());
mockContentFilterService
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<string?>()))
.Setup(x => x.GetFilteredQualifications(
It.IsAny<int?>(),
It.IsAny<int?>(),
It.IsAny<int?>(),
It.IsAny<string?>()))
.ReturnsAsync([]);

var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object,
Expand Down Expand Up @@ -666,7 +671,8 @@ public async Task

mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel());
mockContentFilterService
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<string?>()))
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(),
It.IsAny<string?>()))
.ReturnsAsync(listOfQualifications);

var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object,
Expand Down Expand Up @@ -731,7 +737,8 @@ public async Task

mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel());
mockContentFilterService
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<string?>()))
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(),
It.IsAny<string?>()))
.ReturnsAsync(listOfQualifications);

var controller = new QuestionsController(mockLogger.Object, mockContentService.Object, mockRenderer.Object,
Expand Down Expand Up @@ -781,7 +788,8 @@ public async Task Post_WhatIsTheAwardingOrganisation_InvalidModel_ReturnsQuestio

mockUserJourneyCookieService.Setup(x => x.GetUserJourneyModelFromCookie()).Returns(new UserJourneyModel());
mockContentFilterService
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<string?>()))
.Setup(x => x.GetFilteredQualifications(It.IsAny<int?>(), It.IsAny<int?>(), It.IsAny<int?>(),
It.IsAny<string?>()))
.ReturnsAsync([]);

controller.ModelState.AddModelError("option", "test error");
Expand Down

0 comments on commit c615f11

Please sign in to comment.