Skip to content

Commit bf44e27

Browse files
committed
TD-3547 Directs call to enrol delegate on course through the enrol service
1 parent a693258 commit bf44e27

File tree

5 files changed

+106
-96
lines changed

5 files changed

+106
-96
lines changed
Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,80 @@
1-
using DigitalLearningSolutions.Web.Services;
2-
using DigitalLearningSolutions.Data.Models.SessionData.Tracking.Delegate.Enrol;
3-
using DigitalLearningSolutions.Data.DataServices;
4-
using DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates;
5-
using DigitalLearningSolutions.Web.Tests.ControllerHelpers;
6-
using FakeItEasy;
7-
using FluentAssertions.AspNetCore.Mvc;
8-
using FluentAssertions.Execution;
9-
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.Mvc.ViewFeatures;
1+
using DigitalLearningSolutions.Web.Services;
2+
using DigitalLearningSolutions.Data.Models.SessionData.Tracking.Delegate.Enrol;
3+
using DigitalLearningSolutions.Data.DataServices;
4+
using DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates;
5+
using DigitalLearningSolutions.Web.Tests.ControllerHelpers;
6+
using FakeItEasy;
7+
using FluentAssertions.AspNetCore.Mvc;
8+
using FluentAssertions.Execution;
9+
using Microsoft.AspNetCore.Http;
10+
using Microsoft.AspNetCore.Mvc.ViewFeatures;
1111
using NUnit.Framework;
1212
using GDS.MultiPageFormData;
13-
using GDS.MultiPageFormData.Enums;
14-
15-
namespace DigitalLearningSolutions.Web.Tests.Controllers.TrackingSystem.Delegates
16-
{
17-
using DigitalLearningSolutions.Data.Services;
18-
19-
public class EnrolControllerTests
20-
{
21-
private EnrolController enrolController = null!;
22-
private ICourseDataService courseDataService = null!;
23-
private IMultiPageFormService multiPageFormService = null!;
24-
private ISupervisorService supervisorService = null!;
25-
private IProgressDataService progressDataService = null!;
26-
private IEnrolService enrolService = null!;
27-
private HttpRequest httpRequest = null!;
28-
private HttpResponse httpResponse = null!;
29-
private HttpContext httpContext = null!;
30-
private TempDataDictionary tempDataDictionary = null!;
31-
private SessionEnrolDelegate sessionEnrolDelegate = null!;
32-
33-
[SetUp]
34-
public void Setup()
35-
{
36-
courseDataService = A.Fake<ICourseDataService>();
37-
multiPageFormService = A.Fake<IMultiPageFormService>();
38-
supervisorService = A.Fake<ISupervisorService>();
39-
enrolService = A.Fake<IEnrolService>();
40-
progressDataService = A.Fake<IProgressDataService>();
41-
sessionEnrolDelegate = A.Fake<SessionEnrolDelegate>();
42-
43-
httpRequest = A.Fake<HttpRequest>();
44-
httpResponse = A.Fake<HttpResponse>();
45-
httpContext = A.Fake<HttpContext>();
46-
tempDataDictionary = new TempDataDictionary(httpContext, A.Fake<ITempDataProvider>());
47-
48-
enrolController = new EnrolController(
49-
courseDataService,
50-
multiPageFormService,
51-
supervisorService,
52-
enrolService,
53-
progressDataService)
54-
.WithMockHttpContext(httpRequest, null, null, httpResponse)
55-
.WithMockTempData()
56-
.WithDefaultContext()
57-
.WithMockUser(true);
58-
}
59-
60-
[Test]
61-
public void StartEnrolProcess_calls_expected_methods_and_returns_view()
62-
{
63-
//Given
64-
A.CallTo(() => multiPageFormService.SetMultiPageFormData(sessionEnrolDelegate,
65-
MultiPageFormDataFeature.EnrolDelegateInActivity,
66-
tempDataDictionary));
67-
68-
//When
69-
var result = enrolController.StartEnrolProcess(1, 1, "DelegateName");
70-
71-
//Then
72-
using (new AssertionScope())
73-
{
74-
// Since MultiPageFormDataFeature.EnrolDelegateInActivity is a static method, it cannot be mocked/faked
75-
A.CallTo(() => multiPageFormService.SetMultiPageFormData(A<SessionEnrolDelegate>._, MultiPageFormDataFeature.EnrolDelegateInActivity, enrolController.TempData)).MustHaveHappenedOnceExactly();
76-
77-
result.Should().BeRedirectToActionResult().WithActionName("Index");
78-
79-
Assert.AreEqual(0, tempDataDictionary.Keys.Count);
80-
}
81-
}
82-
}
83-
}
13+
using GDS.MultiPageFormData.Enums;
14+
15+
namespace DigitalLearningSolutions.Web.Tests.Controllers.TrackingSystem.Delegates
16+
{
17+
using DigitalLearningSolutions.Data.Services;
18+
19+
public class EnrolControllerTests
20+
{
21+
private EnrolController enrolController = null!;
22+
private IMultiPageFormService multiPageFormService = null!;
23+
private ISupervisorService supervisorService = null!;
24+
private ICourseService courseService = null!;
25+
private IEnrolService enrolService = null!;
26+
private HttpRequest httpRequest = null!;
27+
private HttpResponse httpResponse = null!;
28+
private HttpContext httpContext = null!;
29+
private TempDataDictionary tempDataDictionary = null!;
30+
private SessionEnrolDelegate sessionEnrolDelegate = null!;
31+
32+
[SetUp]
33+
public void Setup()
34+
{
35+
multiPageFormService = A.Fake<IMultiPageFormService>();
36+
supervisorService = A.Fake<ISupervisorService>();
37+
enrolService = A.Fake<IEnrolService>();
38+
courseService = A.Fake<ICourseService>();
39+
sessionEnrolDelegate = A.Fake<SessionEnrolDelegate>();
40+
41+
httpRequest = A.Fake<HttpRequest>();
42+
httpResponse = A.Fake<HttpResponse>();
43+
httpContext = A.Fake<HttpContext>();
44+
tempDataDictionary = new TempDataDictionary(httpContext, A.Fake<ITempDataProvider>());
45+
46+
enrolController = new EnrolController(
47+
multiPageFormService,
48+
supervisorService,
49+
enrolService,
50+
courseService)
51+
.WithMockHttpContext(httpRequest, null, null, httpResponse)
52+
.WithMockTempData()
53+
.WithDefaultContext()
54+
.WithMockUser(true);
55+
}
56+
57+
[Test]
58+
public void StartEnrolProcess_calls_expected_methods_and_returns_view()
59+
{
60+
//Given
61+
A.CallTo(() => multiPageFormService.SetMultiPageFormData(sessionEnrolDelegate,
62+
MultiPageFormDataFeature.EnrolDelegateInActivity,
63+
tempDataDictionary));
64+
65+
//When
66+
var result = enrolController.StartEnrolProcess(1, 1, "DelegateName");
67+
68+
//Then
69+
using (new AssertionScope())
70+
{
71+
// Since MultiPageFormDataFeature.EnrolDelegateInActivity is a static method, it cannot be mocked/faked
72+
A.CallTo(() => multiPageFormService.SetMultiPageFormData(A<SessionEnrolDelegate>._, MultiPageFormDataFeature.EnrolDelegateInActivity, enrolController.TempData)).MustHaveHappenedOnceExactly();
73+
74+
result.Should().BeRedirectToActionResult().WithActionName("Index");
75+
76+
Assert.AreEqual(0, tempDataDictionary.Keys.Count);
77+
}
78+
}
79+
}
80+
}

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/EnrolController.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,22 @@ namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates
2626
[Route("TrackingSystem/Delegates/{delegateId:int}/Enrol/{action}")]
2727
public partial class EnrolController : Controller
2828
{
29-
private readonly ICourseDataService courseDataService;
3029
private readonly IMultiPageFormService multiPageFormService;
3130
private readonly ISupervisorService supervisorService;
3231
private readonly IEnrolService enrolService;
33-
private readonly IProgressDataService progressDataService;
32+
private readonly ICourseService courseService;
3433

3534
public EnrolController(
36-
ICourseDataService courseDataService,
3735
IMultiPageFormService multiPageFormService,
3836
ISupervisorService supervisorService,
3937
IEnrolService enrolService,
40-
IProgressDataService progressDataService
38+
ICourseService courseService
4139
)
4240
{
43-
this.courseDataService = courseDataService;
4441
this.multiPageFormService = multiPageFormService;
4542
this.supervisorService = supervisorService;
4643
this.enrolService = enrolService;
47-
this.progressDataService = progressDataService;
44+
this.courseService = courseService;
4845
}
4946

5047
public IActionResult StartEnrolProcess(int delegateId, int delegateUserId, string delegateName)
@@ -80,7 +77,7 @@ public IActionResult Index(int delegateId)
8077
MultiPageFormDataFeature.EnrolDelegateInActivity,
8178
TempData
8279
).GetAwaiter().GetResult();
83-
var selfAssessments = courseDataService.GetAvailableCourses(delegateId, centreId, categoryId ?? default(int));
80+
var selfAssessments = courseService.GetAvailableCourses(delegateId, centreId, categoryId ?? default(int));
8481

8582
var model = new EnrolCurrentLearningViewModel(
8683
delegateId,
@@ -100,7 +97,7 @@ public IActionResult Index(int delegateId, EnrolCurrentLearningViewModel enrolCu
10097
MultiPageFormDataFeature.EnrolDelegateInActivity,
10198
TempData
10299
).GetAwaiter().GetResult();
103-
var selfAssessments = courseDataService.GetAvailableCourses(delegateId, centreId, categoryId ?? default(int));
100+
var selfAssessments = courseService.GetAvailableCourses(delegateId, centreId, categoryId ?? default(int));
104101

105102
if (enrolCurrentLearningViewModel.SelectedActivity < 1)
106103
{
@@ -289,22 +286,16 @@ public IActionResult EnrolDelegateSummary(int delegateId)
289286
public IActionResult EnrolDelegateSummary()
290287
{
291288
var centreId = User.GetCentreIdKnownNotNull();
292-
var clockUtility = new ClockUtility();
293-
294289
var sessionEnrol = multiPageFormService.GetMultiPageFormData<SessionEnrolDelegate>(MultiPageFormDataFeature.EnrolDelegateInActivity, TempData).GetAwaiter().GetResult();
295290
var delegateId = (int)sessionEnrol.DelegateID;
296291
if (!sessionEnrol.IsSelfAssessment)
297292
{
298-
progressDataService.CreateNewDelegateProgress(delegateId, sessionEnrol.AssessmentID.GetValueOrDefault(), sessionEnrol.AssessmentVersion,
299-
clockUtility.UtcNow, 0, GetAdminID(), sessionEnrol.CompleteByDate, sessionEnrol.SupervisorID.GetValueOrDefault());
300-
301293
enrolService.EnrolDelegateOnCourse(delegateId, sessionEnrol.AssessmentID.GetValueOrDefault(), sessionEnrol.AssessmentVersion, 0, GetAdminID(), sessionEnrol.CompleteByDate, sessionEnrol.SupervisorID.GetValueOrDefault(), "AdminEnrolDelegateOnCourse");
302-
303294
}
304295
else
305296
{
306297
var adminEmail = User.GetUserPrimaryEmailKnownNotNull();
307-
var selfAssessmentId = courseDataService.EnrolOnActivitySelfAssessment(
298+
var selfAssessmentId = enrolService.EnrolOnActivitySelfAssessment(
308299
sessionEnrol.AssessmentID.GetValueOrDefault(),
309300
delegateId,
310301
sessionEnrol.SupervisorID.GetValueOrDefault(),

DigitalLearningSolutions.Web/Services/CourseService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ int diagCompletionThreshold
120120

121121
public IEnumerable<CourseStatisticsWithAdminFieldResponseCounts> GetDelegateCourses(string searchString,int centreId, int? categoryId, bool allCentreCourses, bool? hideInLearnerPortal,string isActive, string categoryName, string courseTopic, string hasAdminFields);
122122
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessments(string searchString, int centreId, string categoryName, string isActive);
123+
IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? centreId, int categoryId);
123124
}
124125

125126
public class CourseService : ICourseService
@@ -552,5 +553,10 @@ public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessments(string s
552553
{
553554
return courseDataService.GetDelegateAssessmentStatisticsAtCentre(searchString, centreId, categoryName, isActive);
554555
}
556+
557+
public IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? centreId, int categoryId)
558+
{
559+
return courseDataService.GetAvailableCourses(delegateId, centreId, categoryId);
560+
}
555561
}
556562
}

DigitalLearningSolutions.Web/Services/EnrolService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public Email BuildEnrolmentEmail(
3333
int customisationId,
3434
DateTime? completeByDate
3535
);
36+
37+
int EnrolOnActivitySelfAssessment(
38+
int selfAssessmentId,
39+
int candidateId,
40+
int supervisorId,
41+
string adminEmail,
42+
int selfAssessmentSupervisorRoleId,
43+
DateTime? completeByDate,
44+
int delegateUserId,
45+
int centreId
46+
);
3647
}
3748
public class EnrolService : IEnrolService
3849
{
@@ -170,5 +181,10 @@ by the system because a previous course completion has expired.</p>
170181

171182
return new Email(EnrolEmailSubject, body, emailAddress);
172183
}
184+
185+
public int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int supervisorId, string adminEmail, int selfAssessmentSupervisorRoleId, DateTime? completeByDate, int delegateUserId, int centreId)
186+
{
187+
return courseDataService.EnrolOnActivitySelfAssessment(selfAssessmentId, candidateId, supervisorId, adminEmail, selfAssessmentSupervisorRoleId, completeByDate, delegateUserId, centreId);
188+
}
173189
}
174190
}

0 commit comments

Comments
 (0)