Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLSV2-604 Refactor use of TempData for multi-page forms to use new MultiPageFormService. #1329

54 changes: 54 additions & 0 deletions DigitalLearningSolutions.Data/Enums/MultiPageFormDataFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,60 @@ public class MultiPageFormDataFeature : Enumeration
"EditAdminFieldDataGuid"
);

public static readonly MultiPageFormDataFeature AddNewFramework = new MultiPageFormDataFeature(
5,
nameof(AddNewFramework),
"AddNewFrameworkDataGuid"
);

public static readonly MultiPageFormDataFeature EditAssessmentQuestion = new MultiPageFormDataFeature(
6,
nameof(EditAssessmentQuestion),
"EditAssessmentQuestionDataGuid"
);

public static readonly MultiPageFormDataFeature EditSignpostingParameter = new MultiPageFormDataFeature(
7,
nameof(EditSignpostingParameter),
"EditSignpostingParameterDataGuid"
);

public static readonly MultiPageFormDataFeature AddCompetencyLearningResourceSummary = new MultiPageFormDataFeature(
8,
nameof(AddCompetencyLearningResourceSummary),
"AddCompetencyLearningResourceSummaryDataGuid"
);

public static readonly MultiPageFormDataFeature EditCompetencyLearningResources = new MultiPageFormDataFeature(
9,
nameof(EditCompetencyLearningResources),
"EditCompetencyLearningResourcesDataGuid"
);

public static readonly MultiPageFormDataFeature SearchInSelfAssessmentOverviewGroups = new MultiPageFormDataFeature(
10,
nameof(SearchInSelfAssessmentOverviewGroups),
"SearchInSelfAssessmentOverviewGroupsDataGuid"
);

public static readonly MultiPageFormDataFeature AddSelfAssessmentRequestVerification = new MultiPageFormDataFeature(
11,
nameof(AddSelfAssessmentRequestVerification),
"AddSelfAssessmentRequestVerificationDataGuid"
);

public static readonly MultiPageFormDataFeature AddNewSupervisor = new MultiPageFormDataFeature(
12,
nameof(AddNewSupervisor),
"AddNewSupervisorDataGuid"
);

public static readonly MultiPageFormDataFeature EnrolDelegateOnProfileAssessment = new MultiPageFormDataFeature(
13,
nameof(EnrolDelegateOnProfileAssessment),
"EnrolDelegateOnProfileAssessmentDataGuid"
);

public readonly string TempDataKey;

private MultiPageFormDataFeature(int id, string name, string tempDataKey) : base(id, name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
namespace DigitalLearningSolutions.Data.Models.SessionData.SelfAssessments
{
using System;
public class SessionAddSupervisor
{
public SessionAddSupervisor()
{
Id = new Guid();
}
public Guid Id { get; set; }
public int SelfAssessmentID { get; set; }
public string SelfAssessmentName { get; set; }
public int SupervisorAdminId { get; set; }
public string? SupervisorEmail { get; set; }
public int? SelfAssessmentSupervisorRoleId { get; set; }
}
}
namespace DigitalLearningSolutions.Data.Models.SessionData.SelfAssessments
{
public class SessionAddSupervisor
{
public int SelfAssessmentID { get; set; }
public string SelfAssessmentName { get; set; }
public int SupervisorAdminId { get; set; }
public string? SupervisorEmail { get; set; }
public int? SelfAssessmentSupervisorRoleId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
namespace DigitalLearningSolutions.Data.Models.SessionData.SelfAssessments
{
using System;
using System.Collections.Generic;

public class SessionRequestVerification
{
public SessionRequestVerification()
{
Id = new Guid();
}
public Guid Id { get; set; }
public int SelfAssessmentID { get; set; }
public string SelfAssessmentName { get; set; }
public string Vocabulary { get; set; }
public int CandidateAssessmentSupervisorId { get; set; }
public List<int>? ResultIds { get; set; }
public bool SupervisorSelfAssessmentReview { get; set; }
}
}
namespace DigitalLearningSolutions.Data.Models.SessionData.SelfAssessments
{
using System;
using System.Collections.Generic;

public class SessionRequestVerification
{
public int SelfAssessmentID { get; set; }
public string SelfAssessmentName { get; set; }
public string Vocabulary { get; set; }
public int CandidateAssessmentSupervisorId { get; set; }
public List<int>? ResultIds { get; set; }
public bool SupervisorSelfAssessmentReview { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public T GetMultiPageFormData<T>(MultiPageFormDataFeature feature, ITempDataDict
throw new MultiPageFormDataException("Attempted to get data with no Guid identifier");
}

var settings = new JsonSerializerSettings() { ObjectCreationHandling = ObjectCreationHandling.Replace };
var tempDataGuid = (Guid)tempData.Peek(feature.TempDataKey);
var existingMultiPageFormData =
multiPageFormDataService.GetMultiPageFormDataByGuidAndFeature(tempDataGuid, feature.Name);
Expand All @@ -83,7 +84,7 @@ public T GetMultiPageFormData<T>(MultiPageFormDataFeature feature, ITempDataDict
}

tempData[feature.TempDataKey] = tempDataGuid;
return JsonConvert.DeserializeObject<T>(existingMultiPageFormData.Json);
return JsonConvert.DeserializeObject<T>(existingMultiPageFormData.Json, settings);
}

public void ClearMultiPageFormData(MultiPageFormDataFeature feature, ITempDataDictionary tempData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class FrameworkControllerTests
private IImportCompetenciesFromFileService importCompetenciesFromFileService = null!;
private ILearningHubApiClient learningHubApiClient = null!;
private ISearchSortFilterPaginateService searchSortFilterPaginateService = null!;
private IMultiPageFormService multiPageFormService = null!;

[SetUp]
public void SetUp()
Expand All @@ -39,6 +40,7 @@ public void SetUp()
competencyLearningResourcesDataService = A.Fake<ICompetencyLearningResourcesDataService>();
learningHubApiClient = A.Fake<ILearningHubApiClient>();
searchSortFilterPaginateService = A.Fake<ISearchSortFilterPaginateService>();
multiPageFormService = A.Fake<IMultiPageFormService>();

A.CallTo(() => config["CurrentSystemBaseUrl"]).Returns(BaseUrl);

Expand All @@ -61,7 +63,8 @@ public void SetUp()
importCompetenciesFromFileService,
competencyLearningResourcesDataService,
learningHubApiClient,
searchSortFilterPaginateService
searchSortFilterPaginateService,
multiPageFormService
)
{
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public partial class LearningPortalControllerTests
private IFrameworkService frameworkService = null!;
private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!;
private ISearchSortFilterPaginateService searchSortFilterPaginateService = null!;
private IMultiPageFormService multiPageFormService = null!;

[SetUp]
public void SetUp()
Expand Down Expand Up @@ -75,7 +76,8 @@ public void SetUp()
config,
actionPlanService,
candidateAssessmentDownloadFileService,
searchSortFilterPaginateService
searchSortFilterPaginateService,
multiPageFormService
);
controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } };
controller = controller.WithMockTempData();
Expand Down
Loading