Skip to content

Commit 5a7a07a

Browse files
authored
Merge pull request #2679 from TechnologyEnhancedLearning/Develop/feature/TD-3904-RegisterAtNewCentreController-refactor
TD-3904-RegisterAtNewCentreController - refactor
2 parents f0e440c + 1cbdd65 commit 5a7a07a

File tree

6 files changed

+47
-45
lines changed

6 files changed

+47
-45
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/Register/RegisterAtNewCentreControllerTests.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Threading.Tasks;
6-
using DigitalLearningSolutions.Data.DataServices;
7-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
86
using DigitalLearningSolutions.Data.Enums;
97
using DigitalLearningSolutions.Data.Exceptions;
108
using DigitalLearningSolutions.Data.Models.Register;
11-
using DigitalLearningSolutions.Data.Models.User;
9+
using DigitalLearningSolutions.Data.Models.User;
1210
using DigitalLearningSolutions.Web.Controllers.Register;
1311
using DigitalLearningSolutions.Web.Extensions;
1412
using DigitalLearningSolutions.Web.Helpers;
@@ -33,7 +31,7 @@ public class RegisterAtNewCentreControllerTests
3331
{
3432
private const string IpAddress = "1.1.1.1";
3533
private const int UserId = 2;
36-
private ICentresDataService centresDataService = null!;
34+
private ICentresService centresService = null!;
3735
private IConfiguration config = null!;
3836
private RegisterAtNewCentreController controller = null!;
3937
private IEmailVerificationService emailVerificationService = null!;
@@ -42,17 +40,15 @@ public class RegisterAtNewCentreControllerTests
4240
private IRegistrationService registrationService = null!;
4341
private HttpRequest request = null!;
4442
private ISupervisorDelegateService supervisorDelegateService = null!;
45-
private IUserDataService userDataService = null!;
4643
private IUserService userService = null!;
4744
private ISupervisorService supervisorService = null!;
4845

4946
[SetUp]
5047
public void Setup()
5148
{
52-
centresDataService = A.Fake<ICentresDataService>();
49+
centresService = A.Fake<ICentresService>();
5350
registrationService = A.Fake<IRegistrationService>();
5451
userService = A.Fake<IUserService>();
55-
userDataService = A.Fake<IUserDataService>();
5652
supervisorService = A.Fake<ISupervisorService>();
5753
promptsService = A.Fake<PromptsService>();
5854
featureManager = A.Fake<IFeatureManager>();
@@ -62,15 +58,14 @@ public void Setup()
6258
request = A.Fake<HttpRequest>();
6359

6460
controller = new RegisterAtNewCentreController(
65-
centresDataService,
61+
centresService,
6662
config,
6763
emailVerificationService,
6864
featureManager,
6965
promptsService,
7066
registrationService,
7167
supervisorDelegateService,
7268
userService,
73-
userDataService,
7469
supervisorService
7570
)
7671
.WithDefaultContext()
@@ -85,13 +80,13 @@ public void IndexGet_with_invalid_centreId_param_shows_error()
8580
{
8681
// Given
8782
const int centreId = 7;
88-
A.CallTo(() => centresDataService.GetCentreName(centreId)).Returns(null);
83+
A.CallTo(() => centresService.GetCentreName(centreId)).Returns(null);
8984

9085
// When
9186
var result = controller.Index(centreId);
9287

9388
// Then
94-
A.CallTo(() => centresDataService.GetCentreName(centreId)).MustHaveHappened(1, Times.Exactly);
89+
A.CallTo(() => centresService.GetCentreName(centreId)).MustHaveHappened(1, Times.Exactly);
9590
result.Should().BeNotFoundResult();
9691
}
9792

@@ -100,13 +95,13 @@ public void IndexGet_with_valid_centreId_param_sets_data_correctly()
10095
{
10196
// Given
10297
const int centreId = 7;
103-
A.CallTo(() => centresDataService.GetCentreName(centreId)).Returns("Some centre");
98+
A.CallTo(() => centresService.GetCentreName(centreId)).Returns("Some centre");
10499

105100
// When
106101
var result = controller.Index(centreId);
107102

108103
// Then
109-
A.CallTo(() => centresDataService.GetCentreName(centreId)).MustHaveHappened(1, Times.Exactly);
104+
A.CallTo(() => centresService.GetCentreName(centreId)).MustHaveHappened(1, Times.Exactly);
110105
var data = controller.TempData.Peek<InternalDelegateRegistrationData>()!;
111106
data.Centre.Should().Be(centreId);
112107
data.IsCentreSpecificRegistration.Should().BeTrue();
@@ -120,7 +115,7 @@ public void IndexGet_with_no_centreId_param_allows_normal_registration()
120115
var result = controller.Index();
121116

122117
// Then
123-
A.CallTo(() => centresDataService.GetCentreName(A<int>._)).MustNotHaveHappened();
118+
A.CallTo(() => centresService.GetCentreName(A<int>._)).MustNotHaveHappened();
124119
var data = controller.TempData.Peek<InternalDelegateRegistrationData>()!;
125120
data.Centre.Should().BeNull();
126121
data.IsCentreSpecificRegistration.Should().BeFalse();
@@ -140,7 +135,7 @@ public void PersonalInformationPost_with_invalid_emails_fails_validation()
140135
CentreSpecificEmail = "centre email",
141136
};
142137
A.CallTo(
143-
() => userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
138+
() => userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
144139
model.CentreSpecificEmail!,
145140
centreId,
146141
userAccount.Id
@@ -156,7 +151,7 @@ public void PersonalInformationPost_with_invalid_emails_fails_validation()
156151

157152
// Then
158153
A.CallTo(
159-
() => userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
154+
() => userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
160155
model.CentreSpecificEmail!,
161156
centreId,
162157
userAccount.Id
@@ -187,7 +182,7 @@ public void PersonalInformationPost_with_null_centre_email_skips_email_validatio
187182

188183
// Then
189184
A.CallTo(
190-
() => userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
185+
() => userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
191186
A<string>._,
192187
A<int>._,
193188
A<int>._
@@ -207,7 +202,7 @@ public void PersonalInformationPost_with_valid_emails_is_allowed()
207202
CentreSpecificEmail = "centre email",
208203
};
209204
A.CallTo(
210-
() => userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
205+
() => userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
211206
model.CentreSpecificEmail!,
212207
model.Centre!.Value,
213208
UserId
@@ -220,7 +215,7 @@ public void PersonalInformationPost_with_valid_emails_is_allowed()
220215

221216
// Then
222217
A.CallTo(
223-
() => userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
218+
() => userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
224219
model.CentreSpecificEmail!,
225220
model.Centre!.Value,
226221
UserId

DigitalLearningSolutions.Web.Tests/Helpers/RegistrationEmailValidatorTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void ValidateCentreEmailWithUserIdIfNecessary_adds_error_message_when_cen
224224
{
225225
// Given
226226
A.CallTo(
227-
() => userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
227+
() => userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(
228228
DefaultCentreSpecificEmail,
229229
DefaultCentreId,
230230
DefaultUserId
@@ -238,7 +238,7 @@ public void ValidateCentreEmailWithUserIdIfNecessary_adds_error_message_when_cen
238238
DefaultUserId,
239239
DefaultFieldName,
240240
modelState,
241-
userDataService
241+
userService
242242
);
243243

244244
// Then
@@ -265,7 +265,7 @@ public void
265265
DefaultUserId,
266266
DefaultFieldName,
267267
modelState,
268-
userDataService
268+
userService
269269
);
270270

271271
// Then
@@ -282,7 +282,7 @@ public void ValidateCentreEmailWithUserIdIfNecessary_does_not_add_error_message_
282282
DefaultUserId,
283283
DefaultFieldName,
284284
modelState,
285-
userDataService
285+
userService
286286
);
287287

288288
// Then
@@ -311,7 +311,7 @@ public void
311311
DefaultUserId,
312312
DefaultFieldName,
313313
modelState,
314-
userDataService
314+
userService
315315
);
316316

317317
// Then
@@ -332,7 +332,7 @@ public void
332332
DefaultUserId,
333333
DefaultFieldName,
334334
modelState,
335-
userDataService
335+
userService
336336
);
337337

338338
// Then

DigitalLearningSolutions.Web/Controllers/Register/RegisterAtNewCentreController.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Threading.Tasks;
7-
using DigitalLearningSolutions.Data.DataServices;
8-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
97
using DigitalLearningSolutions.Data.Enums;
108
using DigitalLearningSolutions.Data.Exceptions;
119
using DigitalLearningSolutions.Data.Extensions;
@@ -28,39 +26,36 @@
2826
[ServiceFilter(typeof(VerifyUserHasVerifiedPrimaryEmail))]
2927
public class RegisterAtNewCentreController : Controller
3028
{
31-
private readonly ICentresDataService centresDataService;
29+
private readonly ICentresService centresService;
3230
private readonly IConfiguration config;
3331
private readonly IEmailVerificationService emailVerificationService;
3432
private readonly IFeatureManager featureManager;
3533
private readonly PromptsService promptsService;
3634
private readonly IRegistrationService registrationService;
3735
private readonly ISupervisorDelegateService supervisorDelegateService;
38-
private readonly IUserDataService userDataService;
3936
private readonly IUserService userService;
4037
private readonly ISupervisorService supervisorService;
4138

4239
public RegisterAtNewCentreController(
43-
ICentresDataService centresDataService,
40+
ICentresService centresService,
4441
IConfiguration config,
4542
IEmailVerificationService emailVerificationService,
4643
IFeatureManager featureManager,
4744
PromptsService promptsService,
4845
IRegistrationService registrationService,
4946
ISupervisorDelegateService supervisorDelegateService,
5047
IUserService userService,
51-
IUserDataService userDataService,
5248
ISupervisorService supervisorService
5349
)
5450
{
55-
this.centresDataService = centresDataService;
51+
this.centresService = centresService;
5652
this.config = config;
5753
this.emailVerificationService = emailVerificationService;
5854
this.featureManager = featureManager;
5955
this.promptsService = promptsService;
6056
this.registrationService = registrationService;
6157
this.supervisorDelegateService = supervisorDelegateService;
6258
this.userService = userService;
63-
this.userDataService = userDataService;
6459
this.supervisorService = supervisorService;
6560
}
6661

@@ -220,7 +215,7 @@ public IActionResult Summary()
220215
var viewModel = new InternalSummaryViewModel
221216
{
222217
CentreSpecificEmail = data.CentreSpecificEmail,
223-
Centre = centresDataService.GetCentreName((int)data.Centre!),
218+
Centre = centresService.GetCentreName((int)data.Centre!),
224219
DelegateRegistrationPrompts = promptsService.GetDelegateRegistrationPromptsForCentre(
225220
data.Centre!.Value,
226221
data.Answer1,
@@ -348,7 +343,7 @@ public IActionResult Confirmation(
348343

349344
private bool CheckCentreIdValid(int? centreId)
350345
{
351-
return centreId == null || centresDataService.GetCentreName(centreId.Value) != null;
346+
return centreId == null || centresService.GetCentreName(centreId.Value) != null;
352347
}
353348

354349
private void ValidateEmailAddress(InternalPersonalInformationViewModel model)
@@ -361,16 +356,16 @@ private void ValidateEmailAddress(InternalPersonalInformationViewModel model)
361356
User.GetUserIdKnownNotNull(),
362357
nameof(PersonalInformationViewModel.CentreSpecificEmail),
363358
ModelState,
364-
userDataService
359+
userService
365360
);
366361
}
367362
}
368363

369364
private void PopulatePersonalInformationExtraFields(InternalPersonalInformationViewModel model)
370365
{
371-
model.CentreName = model.Centre.HasValue ? centresDataService.GetCentreName(model.Centre.Value) : null;
366+
model.CentreName = model.Centre.HasValue ? centresService.GetCentreName(model.Centre.Value) : null;
372367
model.CentreOptions = SelectListHelper.MapOptionsToSelectListItems(
373-
centresDataService.GetCentresForDelegateSelfRegistrationAlphabetical(),
368+
centresService.GetCentresForDelegateSelfRegistrationAlphabetical(),
374369
model.Centre
375370
);
376371
}

DigitalLearningSolutions.Web/Controllers/Register/RegisterInternalAdminController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public async Task<IActionResult> Index(InternalAdminInformationViewModel model)
103103
userId,
104104
nameof(InternalAdminInformationViewModel.CentreSpecificEmail),
105105
ModelState,
106-
userDataService
106+
userService
107107
);
108108

109109
RegistrationEmailValidator.ValidateEmailsForCentreManagerIfNecessary(

DigitalLearningSolutions.Web/Helpers/RegistrationEmailValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public static void ValidateCentreEmailWithUserIdIfNecessary(
7676
int userId,
7777
string nameOfFieldToValidate,
7878
ModelStateDictionary modelState,
79-
IUserDataService userDataService
79+
IUserService userService
8080
)
8181
{
8282
if (
8383
centreId.HasValue &&
8484
IsValidationNecessary(centreEmail, nameOfFieldToValidate, modelState) &&
85-
userDataService.CentreSpecificEmailIsInUseAtCentreByOtherUser(centreEmail!, centreId.Value, userId)
85+
userService.CentreSpecificEmailIsInUseAtCentreByOtherUser(centreEmail!, centreId.Value, userId)
8686
)
8787
{
8888
modelState.AddModelError(nameOfFieldToValidate, CommonValidationErrorMessages.EmailInUseAtCentre);

DigitalLearningSolutions.Web/Services/CentresService.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void UpdateCentreManagerDetails(
4141
string? telephone
4242
);
4343
string? GetBannerText(int centreId);
44+
string? GetCentreName(int centreId);
45+
IEnumerable<(int, string)> GetCentresForDelegateSelfRegistrationAlphabetical();
4446
}
4547

4648
public class CentresService : ICentresService
@@ -71,12 +73,12 @@ public IEnumerable<CentreRanking> GetCentresForCentreRankingPage(int centreId, i
7173
return centreRanking?.Ranking;
7274
}
7375

74-
public (IEnumerable<CentreEntity>, int) GetAllCentreSummariesForSuperAdmin(string search, int offset, int rows,int region,
76+
public (IEnumerable<CentreEntity>, int) GetAllCentreSummariesForSuperAdmin(string search, int offset, int rows, int region,
7577
int centreType,
7678
int contractType,
7779
string centreStatus)
7880
{
79-
return centresDataService.GetAllCentreSummariesForSuperAdmin(search,offset,rows,region,centreType,contractType,centreStatus);
81+
return centresDataService.GetAllCentreSummariesForSuperAdmin(search, offset, rows, region, centreType, contractType, centreStatus);
8082
}
8183

8284
public IEnumerable<CentreSummaryForFindYourCentre> GetAllCentreSummariesForFindCentre()
@@ -123,15 +125,25 @@ public void ReactivateCentre(int centreId)
123125
return centresDataService.GetCentreManagerDetailsByCentreId(centreId);
124126
}
125127

126-
public void UpdateCentreManagerDetails(int centreId,string firstName,string lastName,string email,string? telephone
128+
public void UpdateCentreManagerDetails(int centreId, string firstName, string lastName, string email, string? telephone
127129
)
128130
{
129-
centresDataService.UpdateCentreManagerDetails(centreId,firstName,lastName,email,telephone);
131+
centresDataService.UpdateCentreManagerDetails(centreId, firstName, lastName, email, telephone);
130132
}
131133

132134
public string? GetBannerText(int centreId)
133135
{
134136
return centresDataService.GetBannerText(centreId);
135137
}
138+
139+
public string? GetCentreName(int centreId)
140+
{
141+
return centresDataService.GetCentreName(centreId);
142+
}
143+
144+
public IEnumerable<(int, string)> GetCentresForDelegateSelfRegistrationAlphabetical()
145+
{
146+
return centresDataService.GetCentresForDelegateSelfRegistrationAlphabetical();
147+
}
136148
}
137149
}

0 commit comments

Comments
 (0)