Skip to content

Commit 7cc39fb

Browse files
committed
TD-3914-Controller refactor -DataService reference removed from the controller. Code modified to use service class methods.
1 parent 9913802 commit 7cc39fb

File tree

6 files changed

+192
-75
lines changed

6 files changed

+192
-75
lines changed

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using DigitalLearningSolutions.Data.DataServices;
2-
using DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService;
1+
//using DigitalLearningSolutions.Data.DataServices;
2+
//using DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService;
33
using DigitalLearningSolutions.Data.Models;
44
using DigitalLearningSolutions.Data.Models.Centres;
55
using DigitalLearningSolutions.Data.Models.SuperAdmin;
@@ -22,13 +22,12 @@ namespace DigitalLearningSolutions.Web.Tests.Controllers.SuperAdmin
2222
public class CentresControllerTests
2323
{
2424
private const int CenterId = 374;
25-
private readonly ICentresDataService centresDataService = A.Fake<ICentresDataService>();
2625
private readonly ICentreApplicationsService centreApplicationsService = A.Fake<ICentreApplicationsService>();
2726
private readonly ICentresService centresService = A.Fake<ICentresService>();
2827
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>();
28+
private readonly IRegionService regionService = A.Fake<IRegionService>();
29+
private readonly IContractTypesService contractTypesService = A.Fake<IContractTypesService>();
30+
private readonly ICourseService courseService = A.Fake<ICourseService>();
3231
private readonly ICentresDownloadFileService centresDownloadFileService = A.Fake<ICentresDownloadFileService>();
3332
private readonly ICentreSelfAssessmentsService centreSelfAssessmentsService = A.Fake<ICentreSelfAssessmentsService>();
3433
private CentresController controller = null!;
@@ -40,17 +39,16 @@ public void Setup()
4039
centresService,
4140
centreApplicationsService,
4241
searchSortFilterPaginateService,
43-
regionDataService,
44-
centresDataService,
45-
contractTypesDataService,
46-
courseDataService,
42+
regionService,
43+
contractTypesService,
44+
courseService,
4745
centresDownloadFileService,
4846
centreSelfAssessmentsService
4947
)
5048
.WithDefaultContext()
5149
.WithMockUser(true);
5250

53-
A.CallTo(() => centresDataService.UpdateCentreDetailsForSuperAdmin(
51+
A.CallTo(() => centresService.UpdateCentreDetailsForSuperAdmin(
5452
A<int>._,
5553
A<string>._,
5654
A<int>._,
@@ -64,15 +62,15 @@ public void Setup()
6462
[TearDown]
6563
public void Cleanup()
6664
{
67-
Fake.ClearRecordedCalls(centresDataService);
65+
Fake.ClearRecordedCalls(centresService);
6866
}
6967

7068
[Test]
7169
public void EditCentreDetails_updates_centre_and_redirects_with_successful_save()
7270
{
7371
// Given
7472
IEnumerable<(int, string)> centresList = new List<(int, string)> { (374, "##HEE Demo Centre1##") };
75-
A.CallTo(() => centresDataService.GetAllCentres(false)).Returns(centresList);
73+
A.CallTo(() => centresService.GetAllCentres(false)).Returns(centresList);
7674
var model = new EditCentreDetailsSuperAdminViewModel
7775
{
7876
CentreId = 374,
@@ -91,7 +89,7 @@ public void EditCentreDetails_updates_centre_and_redirects_with_successful_save(
9189

9290
// Then
9391
result.Should().BeRedirectToActionResult().WithActionName("ManageCentre");
94-
A.CallTo(() => centresDataService.UpdateCentreDetailsForSuperAdmin(
92+
A.CallTo(() => centresService.UpdateCentreDetailsForSuperAdmin(
9593
model.CentreId,
9694
model.CentreName,
9795
model.CentreTypeId,
@@ -107,7 +105,7 @@ public void EditCentreDetails_results_DuplicateCentre_error()
107105
{
108106
// Given
109107
IEnumerable<(int, string)> centresList = new List<(int, string)> { (374, "##HEE Demo Centre##"), (610, "Alternative Futures Group") };
110-
A.CallTo(() => centresDataService.GetAllCentres(false)).Returns(centresList);
108+
A.CallTo(() => centresService.GetAllCentres(false)).Returns(centresList);
111109
var model = new EditCentreDetailsSuperAdminViewModel
112110
{
113111
CentreId = 374,
@@ -131,7 +129,7 @@ public void EditCentreDetails_results_DuplicateCentre_error()
131129
centreNameErrors.Should().Contain(error => error.ErrorMessage ==
132130
"The centre name you have entered already exists, please enter a different centre name");
133131

134-
A.CallTo(() => centresDataService.UpdateCentreDetailsForSuperAdmin(
132+
A.CallTo(() => centresService.UpdateCentreDetailsForSuperAdmin(
135133
model.CentreId,
136134
model.CentreName,
137135
model.CentreTypeId,
@@ -166,7 +164,7 @@ public void AddCentre_adds_centre_and_redirects_with_successful_save()
166164

167165
// Then
168166
result.Should().BeRedirectToActionResult().WithActionName("ManageCentre");
169-
A.CallTo(() => centresDataService.AddCentreForSuperAdmin(
167+
A.CallTo(() => centresService.AddCentreForSuperAdmin(
170168
model.CentreName,
171169
model.ContactFirstName,
172170
model.ContactLastName,
@@ -186,7 +184,7 @@ public void AddCentre_results_DuplicateCentre_error()
186184
{
187185
// Given
188186
IEnumerable<(int, string)> centresList = new List<(int, string)> { (374, "##HEE Demo Centre##") };
189-
A.CallTo(() => centresDataService.GetAllCentres(false)).Returns(centresList);
187+
A.CallTo(() => centresService.GetAllCentres(false)).Returns(centresList);
190188
var model = new AddCentreSuperAdminViewModel
191189
{
192190
CentreName = "##HEE Demo Centre##",
@@ -214,7 +212,7 @@ public void AddCentre_results_DuplicateCentre_error()
214212
centreNameErrors.Should().Contain(error => error.ErrorMessage ==
215213
"The centre name you have entered already exists, please enter a different centre name");
216214

217-
A.CallTo(() => centresDataService.AddCentreForSuperAdmin(
215+
A.CallTo(() => centresService.AddCentreForSuperAdmin(
218216
model.CentreName,
219217
model.ContactFirstName,
220218
model.ContactLastName,
@@ -242,7 +240,7 @@ public void CentreRoleLimits_route_loads_existing_role_limits_with_derived_flags
242240
RoleLimitTrainers = 30, // set
243241
};
244242

245-
A.CallTo(() => centresDataService.GetRoleLimitsForCentre(
243+
A.CallTo(() => centresService.GetRoleLimitsForCentre(
246244
A<int>._
247245
)).Returns(roleLimits);
248246

@@ -266,7 +264,7 @@ public void CentreRoleLimits_route_loads_existing_role_limits_with_derived_flags
266264

267265
// Then
268266

269-
A.CallTo(() => centresDataService.GetRoleLimitsForCentre(374)).MustHaveHappenedOnceExactly();
267+
A.CallTo(() => centresService.GetRoleLimitsForCentre(374)).MustHaveHappenedOnceExactly();
270268
result.Should().BeViewResult("CentreRoleLimits").ModelAs<CentreRoleLimitsViewModel>().Should().BeEquivalentTo(expectedVm);
271269
}
272270

@@ -294,7 +292,7 @@ public void EditCentreRoleLimits_updates_centre_role_limits_and_redirects_with_s
294292

295293
// Then
296294
A.CallTo(
297-
() => centresDataService.UpdateCentreRoleLimits(
295+
() => centresService.UpdateCentreRoleLimits(
298296
model.CentreId,
299297
model.RoleLimitCmsAdministrators,
300298
model.RoleLimitCmsManagers,
@@ -331,7 +329,7 @@ public void EditCentreRoleLimits_default_role_limit_value_to_negative_if_not_set
331329

332330
// Then
333331
A.CallTo(
334-
() => centresDataService.UpdateCentreRoleLimits(
332+
() => centresService.UpdateCentreRoleLimits(
335333
model.CentreId,
336334
model.RoleLimitCmsAdministrators,
337335
-1,
@@ -357,7 +355,7 @@ public void Get_with_centreId_shows_EditContractInfo_page()
357355
const int contractReviewDay = 28;
358356
const int contractReviewMonth = 8;
359357
const int contractReviewYear = 2023;
360-
A.CallTo(() => centresDataService.GetContractInfo(CenterId)).Returns(CentreContractAdminUsageTestHelper.GetDefaultEditContractInfo(CenterId));
358+
A.CallTo(() => centresService.GetContractInfo(CenterId)).Returns(CentreContractAdminUsageTestHelper.GetDefaultEditContractInfo(CenterId));
361359

362360
// When
363361
var result = controller.EditContractInfo(centreId, 28, 8, 2023, 10024, 10024, 100024);
@@ -399,7 +397,7 @@ public void Edit_ContractInfo_redirects_with_successful_save()
399397

400398
// When
401399
var result = controller.EditContractInfo(model, DateTime.UtcNow.Day, DateTime.UtcNow.Month, DateTime.UtcNow.Year);
402-
A.CallTo(() => centresDataService.UpdateContractTypeandCenter(model.CentreId,
400+
A.CallTo(() => centresService.UpdateContractTypeandCenter(model.CentreId,
403401
model.ContractTypeID,
404402
model.DelegateUploadSpace,
405403
model.ServerSpaceBytesInc,

0 commit comments

Comments
 (0)