|
| 1 | +namespace DigitalLearningSolutions.Web.Tests.Controllers.Support |
| 2 | +{ |
| 3 | + using System.Collections.Generic; |
| 4 | + using System.IO; |
| 5 | + using System.Linq; |
| 6 | + using DigitalLearningSolutions.Data.DataServices; |
| 7 | + using DigitalLearningSolutions.Data.DataServices.UserDataService; |
| 8 | + using DigitalLearningSolutions.Data.Models.Support; |
| 9 | + using DigitalLearningSolutions.Data.Services; |
| 10 | + using DigitalLearningSolutions.Data.Tests.TestHelpers; |
| 11 | + using DigitalLearningSolutions.Data.Utilities; |
| 12 | + using DigitalLearningSolutions.Web.Controllers.SupervisorController; |
| 13 | + using DigitalLearningSolutions.Web.Controllers.Support; |
| 14 | + using DigitalLearningSolutions.Web.Models.Enums; |
| 15 | + using DigitalLearningSolutions.Web.Services; |
| 16 | + using DigitalLearningSolutions.Web.ViewModels.Support.Faqs; |
| 17 | + using FakeItEasy; |
| 18 | + using FluentAssertions; |
| 19 | + using FluentAssertions.AspNetCore.Mvc; |
| 20 | + using GDS.MultiPageFormData; |
| 21 | + using Microsoft.AspNetCore.Mvc; |
| 22 | + using Microsoft.Extensions.Configuration; |
| 23 | + using Microsoft.Extensions.Logging; |
| 24 | + using NUnit.Framework; |
| 25 | + |
| 26 | + public class SupervisorControllerTests |
| 27 | + { |
| 28 | + private ISupervisorService supervisorService = null!; |
| 29 | + private ICommonService commonService = null!; |
| 30 | + private IFrameworkNotificationService frameworkNotificationService = null!; |
| 31 | + private ISelfAssessmentService selfAssessmentService = null!; |
| 32 | + private IFrameworkService frameworkService = null!; |
| 33 | + private IConfigDataService configDataService = null!; |
| 34 | + private ICentreRegistrationPromptsService centreRegistrationPromptsService = null!; |
| 35 | + private IUserDataService userDataService = null!; |
| 36 | + private ILogger<SupervisorController> logger = null!; |
| 37 | + private IConfiguration config = null!; |
| 38 | + private ISearchSortFilterPaginateService searchSortFilterPaginateService = null!; |
| 39 | + private IMultiPageFormService multiPageFormService = null!; |
| 40 | + private IRegistrationService registrationService = null!; |
| 41 | + private ICentresDataService centresDataService = null!; |
| 42 | + private IUserService userService = null!; |
| 43 | + private IEmailGenerationService emailGenerationService = null!; |
| 44 | + private IEmailService emailService = null!; |
| 45 | + private IClockUtility clockUtility = null!; |
| 46 | + private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!; |
| 47 | + |
| 48 | + [SetUp] |
| 49 | + public void Setup() |
| 50 | + { |
| 51 | + supervisorService = A.Fake<ISupervisorService>(); |
| 52 | + commonService = A.Fake<ICommonService>(); |
| 53 | + frameworkNotificationService = A.Fake<IFrameworkNotificationService>(); |
| 54 | + selfAssessmentService = A.Fake<ISelfAssessmentService>(); |
| 55 | + frameworkService = A.Fake<IFrameworkService>(); |
| 56 | + configDataService = A.Fake<IConfigDataService>(); |
| 57 | + centreRegistrationPromptsService = A.Fake<ICentreRegistrationPromptsService>(); |
| 58 | + userDataService = A.Fake<IUserDataService>(); |
| 59 | + logger = A.Fake<ILogger<SupervisorController>>(); |
| 60 | + config = A.Fake<IConfiguration>(); |
| 61 | + searchSortFilterPaginateService = A.Fake<ISearchSortFilterPaginateService>(); |
| 62 | + multiPageFormService = A.Fake<IMultiPageFormService>(); |
| 63 | + registrationService = A.Fake<IRegistrationService>(); |
| 64 | + centresDataService = A.Fake<ICentresDataService>(); |
| 65 | + userService = A.Fake<IUserService>(); |
| 66 | + emailGenerationService = A.Fake<IEmailGenerationService>(); |
| 67 | + emailService = A.Fake<IEmailService>(); |
| 68 | + clockUtility = A.Fake<IClockUtility>(); |
| 69 | + candidateAssessmentDownloadFileService = A.Fake<ICandidateAssessmentDownloadFileService>(); |
| 70 | + |
| 71 | + A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A<int>._, A<int>._, A<bool>._)) |
| 72 | + .Returns(new byte[] { }); |
| 73 | + } |
| 74 | + |
| 75 | + [TestCase(1, "test", "Digital Capability Self Assessment Deprecated", 1)] |
| 76 | + [TestCase(1, "test", "IV Therapy Passport", 1)] |
| 77 | + public void ExportCandidateAssessment_should_return_file_object_with_file_name_is_equal_to_expectedFileName(int candidateAssessmentId, string delegateName, string selfAssessmentName, int delegateUserID) |
| 78 | + { |
| 79 | + // Arrange |
| 80 | + var controller = new SupervisorController( |
| 81 | + supervisorService, |
| 82 | + commonService, |
| 83 | + frameworkNotificationService, |
| 84 | + selfAssessmentService, |
| 85 | + frameworkService, |
| 86 | + configDataService, |
| 87 | + centreRegistrationPromptsService, |
| 88 | + userDataService, |
| 89 | + logger, |
| 90 | + config, |
| 91 | + searchSortFilterPaginateService, |
| 92 | + multiPageFormService, |
| 93 | + registrationService, |
| 94 | + centresDataService, |
| 95 | + userService, |
| 96 | + emailGenerationService, |
| 97 | + emailService, |
| 98 | + candidateAssessmentDownloadFileService, |
| 99 | + clockUtility |
| 100 | + ); |
| 101 | + string expectedFileName = $"{((selfAssessmentName.Length > 30) ? selfAssessmentName.Substring(0, 29) : selfAssessmentName)}-{delegateName}-{clockUtility.UtcNow:yyyy-MM-dd}.xlsx"; |
| 102 | + |
| 103 | + // Act |
| 104 | + var result = controller.ExportCandidateAssessment(candidateAssessmentId, delegateName, selfAssessmentName, delegateUserID) as FileResult; |
| 105 | + |
| 106 | + // Assert |
| 107 | + Assert.Multiple(() => |
| 108 | + { |
| 109 | + Assert.IsNotNull(result); |
| 110 | + Assert.AreEqual(expectedFileName, result!.FileDownloadName); |
| 111 | + }); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments