Skip to content

Commit 5ccb6e1

Browse files
authored
Merge pull request #2709 from TechnologyEnhancedLearning/Develop/feature/TD-3914-CentresController-refactor
TD-3914-CentresController - refactor
2 parents ce6e2b2 + 52444ae commit 5ccb6e1

File tree

6 files changed

+190
-76
lines changed

6 files changed

+190
-76
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/SuperAdmin/CentresControllerTests.cs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using DigitalLearningSolutions.Data.DataServices;
2-
using DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService;
3-
using DigitalLearningSolutions.Data.Models;
1+
using DigitalLearningSolutions.Data.Models;
42
using DigitalLearningSolutions.Data.Models.Centres;
53
using DigitalLearningSolutions.Data.Models.SuperAdmin;
64
using DigitalLearningSolutions.Web.Controllers.SuperAdmin.Centres;
@@ -22,13 +20,12 @@ namespace DigitalLearningSolutions.Web.Tests.Controllers.SuperAdmin
2220
public class CentresControllerTests
2321
{
2422
private const int CenterId = 374;
25-
private readonly ICentresDataService centresDataService = A.Fake<ICentresDataService>();
2623
private readonly ICentreApplicationsService centreApplicationsService = A.Fake<ICentreApplicationsService>();
2724
private readonly ICentresService centresService = A.Fake<ICentresService>();
2825
private readonly ISearchSortFilterPaginateService searchSortFilterPaginateService = A.Fake<ISearchSortFilterPaginateService>();
29-
private readonly IRegionDataService regionDataService = A.Fake<IRegionDataService>();
30-
private readonly IContractTypesDataService contractTypesDataService = A.Fake<IContractTypesDataService>();
31-
private readonly ICourseDataService courseDataService = A.Fake<ICourseDataService>();
26+
private readonly IRegionService regionService = A.Fake<IRegionService>();
27+
private readonly IContractTypesService contractTypesService = A.Fake<IContractTypesService>();
28+
private readonly ICourseService courseService = A.Fake<ICourseService>();
3229
private readonly ICentresDownloadFileService centresDownloadFileService = A.Fake<ICentresDownloadFileService>();
3330
private readonly ICentreSelfAssessmentsService centreSelfAssessmentsService = A.Fake<ICentreSelfAssessmentsService>();
3431
private CentresController controller = null!;
@@ -40,17 +37,16 @@ public void Setup()
4037
centresService,
4138
centreApplicationsService,
4239
searchSortFilterPaginateService,
43-
regionDataService,
44-
centresDataService,
45-
contractTypesDataService,
46-
courseDataService,
40+
regionService,
41+
contractTypesService,
42+
courseService,
4743
centresDownloadFileService,
4844
centreSelfAssessmentsService
4945
)
5046
.WithDefaultContext()
5147
.WithMockUser(true);
5248

53-
A.CallTo(() => centresDataService.UpdateCentreDetailsForSuperAdmin(
49+
A.CallTo(() => centresService.UpdateCentreDetailsForSuperAdmin(
5450
A<int>._,
5551
A<string>._,
5652
A<int>._,
@@ -64,15 +60,15 @@ public void Setup()
6460
[TearDown]
6561
public void Cleanup()
6662
{
67-
Fake.ClearRecordedCalls(centresDataService);
63+
Fake.ClearRecordedCalls(centresService);
6864
}
6965

7066
[Test]
7167
public void EditCentreDetails_updates_centre_and_redirects_with_successful_save()
7268
{
7369
// Given
7470
IEnumerable<(int, string)> centresList = new List<(int, string)> { (374, "##HEE Demo Centre1##") };
75-
A.CallTo(() => centresDataService.GetAllCentres(false)).Returns(centresList);
71+
A.CallTo(() => centresService.GetAllCentres(false)).Returns(centresList);
7672
var model = new EditCentreDetailsSuperAdminViewModel
7773
{
7874
CentreId = 374,
@@ -91,7 +87,7 @@ public void EditCentreDetails_updates_centre_and_redirects_with_successful_save(
9187

9288
// Then
9389
result.Should().BeRedirectToActionResult().WithActionName("ManageCentre");
94-
A.CallTo(() => centresDataService.UpdateCentreDetailsForSuperAdmin(
90+
A.CallTo(() => centresService.UpdateCentreDetailsForSuperAdmin(
9591
model.CentreId,
9692
model.CentreName,
9793
model.CentreTypeId,
@@ -107,7 +103,7 @@ public void EditCentreDetails_results_DuplicateCentre_error()
107103
{
108104
// Given
109105
IEnumerable<(int, string)> centresList = new List<(int, string)> { (374, "##HEE Demo Centre##"), (610, "Alternative Futures Group") };
110-
A.CallTo(() => centresDataService.GetAllCentres(false)).Returns(centresList);
106+
A.CallTo(() => centresService.GetAllCentres(false)).Returns(centresList);
111107
var model = new EditCentreDetailsSuperAdminViewModel
112108
{
113109
CentreId = 374,
@@ -131,7 +127,7 @@ public void EditCentreDetails_results_DuplicateCentre_error()
131127
centreNameErrors.Should().Contain(error => error.ErrorMessage ==
132128
"The centre name you have entered already exists, please enter a different centre name");
133129

134-
A.CallTo(() => centresDataService.UpdateCentreDetailsForSuperAdmin(
130+
A.CallTo(() => centresService.UpdateCentreDetailsForSuperAdmin(
135131
model.CentreId,
136132
model.CentreName,
137133
model.CentreTypeId,
@@ -166,7 +162,7 @@ public void AddCentre_adds_centre_and_redirects_with_successful_save()
166162

167163
// Then
168164
result.Should().BeRedirectToActionResult().WithActionName("ManageCentre");
169-
A.CallTo(() => centresDataService.AddCentreForSuperAdmin(
165+
A.CallTo(() => centresService.AddCentreForSuperAdmin(
170166
model.CentreName,
171167
model.ContactFirstName,
172168
model.ContactLastName,
@@ -186,7 +182,7 @@ public void AddCentre_results_DuplicateCentre_error()
186182
{
187183
// Given
188184
IEnumerable<(int, string)> centresList = new List<(int, string)> { (374, "##HEE Demo Centre##") };
189-
A.CallTo(() => centresDataService.GetAllCentres(false)).Returns(centresList);
185+
A.CallTo(() => centresService.GetAllCentres(false)).Returns(centresList);
190186
var model = new AddCentreSuperAdminViewModel
191187
{
192188
CentreName = "##HEE Demo Centre##",
@@ -214,7 +210,7 @@ public void AddCentre_results_DuplicateCentre_error()
214210
centreNameErrors.Should().Contain(error => error.ErrorMessage ==
215211
"The centre name you have entered already exists, please enter a different centre name");
216212

217-
A.CallTo(() => centresDataService.AddCentreForSuperAdmin(
213+
A.CallTo(() => centresService.AddCentreForSuperAdmin(
218214
model.CentreName,
219215
model.ContactFirstName,
220216
model.ContactLastName,
@@ -242,7 +238,7 @@ public void CentreRoleLimits_route_loads_existing_role_limits_with_derived_flags
242238
RoleLimitTrainers = 30, // set
243239
};
244240

245-
A.CallTo(() => centresDataService.GetRoleLimitsForCentre(
241+
A.CallTo(() => centresService.GetRoleLimitsForCentre(
246242
A<int>._
247243
)).Returns(roleLimits);
248244

@@ -266,7 +262,7 @@ public void CentreRoleLimits_route_loads_existing_role_limits_with_derived_flags
266262

267263
// Then
268264

269-
A.CallTo(() => centresDataService.GetRoleLimitsForCentre(374)).MustHaveHappenedOnceExactly();
265+
A.CallTo(() => centresService.GetRoleLimitsForCentre(374)).MustHaveHappenedOnceExactly();
270266
result.Should().BeViewResult("CentreRoleLimits").ModelAs<CentreRoleLimitsViewModel>().Should().BeEquivalentTo(expectedVm);
271267
}
272268

@@ -294,7 +290,7 @@ public void EditCentreRoleLimits_updates_centre_role_limits_and_redirects_with_s
294290

295291
// Then
296292
A.CallTo(
297-
() => centresDataService.UpdateCentreRoleLimits(
293+
() => centresService.UpdateCentreRoleLimits(
298294
model.CentreId,
299295
model.RoleLimitCmsAdministrators,
300296
model.RoleLimitCmsManagers,
@@ -331,7 +327,7 @@ public void EditCentreRoleLimits_default_role_limit_value_to_negative_if_not_set
331327

332328
// Then
333329
A.CallTo(
334-
() => centresDataService.UpdateCentreRoleLimits(
330+
() => centresService.UpdateCentreRoleLimits(
335331
model.CentreId,
336332
model.RoleLimitCmsAdministrators,
337333
-1,
@@ -357,7 +353,7 @@ public void Get_with_centreId_shows_EditContractInfo_page()
357353
const int contractReviewDay = 28;
358354
const int contractReviewMonth = 8;
359355
const int contractReviewYear = 2023;
360-
A.CallTo(() => centresDataService.GetContractInfo(CenterId)).Returns(CentreContractAdminUsageTestHelper.GetDefaultEditContractInfo(CenterId));
356+
A.CallTo(() => centresService.GetContractInfo(CenterId)).Returns(CentreContractAdminUsageTestHelper.GetDefaultEditContractInfo(CenterId));
361357

362358
// When
363359
var result = controller.EditContractInfo(centreId, 28, 8, 2023, 10024, 10024, 100024);
@@ -399,7 +395,7 @@ public void Edit_ContractInfo_redirects_with_successful_save()
399395

400396
// When
401397
var result = controller.EditContractInfo(model, DateTime.UtcNow.Day, DateTime.UtcNow.Month, DateTime.UtcNow.Year);
402-
A.CallTo(() => centresDataService.UpdateContractTypeandCenter(model.CentreId,
398+
A.CallTo(() => centresService.UpdateContractTypeandCenter(model.CentreId,
403399
model.ContractTypeID,
404400
model.DelegateUploadSpace,
405401
model.ServerSpaceBytesInc,

0 commit comments

Comments
 (0)