Skip to content

Commit cd5c3fc

Browse files
authored
Merge pull request #2690 from TechnologyEnhancedLearning/Develop/feature/TD-3941-Controller-refactor-SetDelegatePasswordController
TD-3941-SetDelegatePasswordController - refactor
2 parents 2181a16 + fa94dd6 commit cd5c3fc

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/SetDelegatePasswordControllerTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace DigitalLearningSolutions.Web.Tests.Controllers.TrackingSystem.Delegates
22
{
33
using System.Threading.Tasks;
4-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
54
using DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates;
65
using DigitalLearningSolutions.Web.Services;
76
using DigitalLearningSolutions.Web.Tests.ControllerHelpers;
@@ -20,14 +19,14 @@ public class SetDelegatePasswordControllerTests
2019

2120
private IPasswordService passwordService = null!;
2221
private SetDelegatePasswordController setDelegatePasswordController = null!;
23-
private IUserDataService userDataService = null!;
22+
private IUserService userService = null!;
2423

2524
[SetUp]
2625
public void Setup()
2726
{
28-
userDataService = A.Fake<IUserDataService>();
27+
userService = A.Fake<IUserService>();
2928
passwordService = A.Fake<IPasswordService>();
30-
setDelegatePasswordController = new SetDelegatePasswordController(passwordService, userDataService)
29+
setDelegatePasswordController = new SetDelegatePasswordController(passwordService, userService)
3130
.WithDefaultContext()
3231
.WithMockUser(true);
3332
}
@@ -36,7 +35,7 @@ public void Setup()
3635
public void Index_should_return_view_result_with_IsFromViewDelegatePage_false_when_not_from_view_page()
3736
{
3837
// Given
39-
A.CallTo(() => userDataService.GetDelegateUserById(DelegateId))
38+
A.CallTo(() => userService.GetDelegateUserById(DelegateId))
4039
.Returns(UserTestHelper.GetDefaultDelegateUser());
4140

4241
// When
@@ -51,7 +50,7 @@ public void Index_should_return_view_result_with_IsFromViewDelegatePage_false_wh
5150
public void Index_should_return_view_result_with_IsFromViewDelegatePage_true_when_from_view_page()
5251
{
5352
// Given
54-
A.CallTo(() => userDataService.GetDelegateUserById(DelegateId))
53+
A.CallTo(() => userService.GetDelegateUserById(DelegateId))
5554
.Returns(UserTestHelper.GetDefaultDelegateUser());
5655

5756
// When
@@ -85,7 +84,7 @@ public async Task IndexAsync_with_valid_model_calls_password_service_and_returns
8584
// Given
8685
var delegateAccount = UserTestHelper.GetDefaultDelegateAccount();
8786
var model = new SetDelegatePasswordViewModel { Password = Password };
88-
A.CallTo(() => userDataService.GetDelegateAccountById(DelegateId))
87+
A.CallTo(() => userService.GetDelegateAccountById(DelegateId))
8988
.Returns(delegateAccount);
9089
A.CallTo(() => passwordService.ChangePasswordAsync(A<int>._, A<string>._)).Returns(Task.CompletedTask);
9190

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates
22
{
33
using System.Threading.Tasks;
4-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
54
using DigitalLearningSolutions.Data.Enums;
65
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
76
using DigitalLearningSolutions.Web.Attributes;
@@ -23,12 +22,12 @@
2322
public class SetDelegatePasswordController : Controller
2423
{
2524
private readonly IPasswordService passwordService;
26-
private readonly IUserDataService userDataService;
25+
private readonly IUserService userService;
2726

28-
public SetDelegatePasswordController(IPasswordService passwordService, IUserDataService userDataService)
27+
public SetDelegatePasswordController(IPasswordService passwordService, IUserService userDataService)
2928
{
3029
this.passwordService = passwordService;
31-
this.userDataService = userDataService;
30+
this.userService = userDataService;
3231
}
3332

3433
[HttpGet]
@@ -38,7 +37,7 @@ public IActionResult Index(
3837
ReturnPageQuery? returnPageQuery = null
3938
)
4039
{
41-
var delegateUser = userDataService.GetDelegateUserById(delegateId)!;
40+
var delegateUser = userService.GetDelegateUserById(delegateId)!;
4241

4342
var model = new SetDelegatePasswordViewModel(
4443
DisplayStringHelper.GetNonSortableFullNameForDisplayOnly(delegateUser.FirstName, delegateUser.LastName),
@@ -64,7 +63,7 @@ bool isFromViewDelegatePage
6463
return View(model);
6564
}
6665

67-
var delegateAccount = userDataService.GetDelegateAccountById(delegateId)!;
66+
var delegateAccount = userService.GetDelegateAccountById(delegateId)!;
6867

6968
await passwordService.ChangePasswordAsync(delegateAccount.UserId, model.Password!);
7069

DigitalLearningSolutions.Web/Services/UserService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ string registrationConfirmationHash
141141
bool CentreSpecificEmailIsInUseAtCentre(string email, int centreId);
142142
int? GetUserIdByAdminId(int adminId);
143143
AdminUser? GetAdminUserByEmailAddress(string emailAddress);
144+
DelegateAccount? GetDelegateAccountById(int id);
144145
}
145146

146147
public class UserService : IUserService
@@ -762,7 +763,7 @@ public void DeleteUserAndAccounts(int userId)
762763
}
763764
public bool PrimaryEmailInUseAtCentres(string email)
764765
{
765-
return userDataService.PrimaryEmailInUseAtCentres(email);
766+
return userDataService.PrimaryEmailInUseAtCentres(email);
766767
}
767768

768769
public bool CentreSpecificEmailIsInUseAtCentre(string email, int centreId)
@@ -779,5 +780,10 @@ public bool CentreSpecificEmailIsInUseAtCentre(string email, int centreId)
779780
{
780781
return userDataService.GetAdminUserByEmailAddress(emailAddress);
781782
}
783+
784+
public DelegateAccount? GetDelegateAccountById(int id)
785+
{
786+
return userDataService.GetDelegateAccountById(id);
787+
}
782788
}
783789
}

0 commit comments

Comments
 (0)