|
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; |
11 | 11 | using NUnit.Framework; |
12 | 12 | 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 | +} |
0 commit comments