-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for the cohort service and modified the existing MA …
…tests to use the new concrete class
- Loading branch information
Showing
2 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/SFA.DAS.EmployerFinance.UnitTests/Services/CohortsServiceTests/WhenIGetACohortsCount.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DocumentFormat.OpenXml.Office2010.CustomUI; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Types; | ||
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests; | ||
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses; | ||
using SFA.DAS.EmployerFinance.Interfaces.OuterApi; | ||
using SFA.DAS.EmployerFinance.Services; | ||
|
||
namespace SFA.DAS.EmployerFinance.UnitTests.Services.CohortsServiceTests | ||
{ | ||
public class WhenIGetACohortsCount | ||
{ | ||
private Mock<IApiClient> _apiClient; | ||
private CohortsService _service; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_apiClient = new Mock<IApiClient>(); | ||
_service = new CohortsService(_apiClient.Object); | ||
} | ||
|
||
[Test] | ||
public async Task ThenTheApiIsCalledWithAValidAccountIdAndTheCohortsCountIsReturned() | ||
{ | ||
SetupApiClient(1); | ||
|
||
var actual = await _service.GetCohortsCount(1); | ||
|
||
Assert.AreEqual(1, actual); | ||
} | ||
|
||
[Test] | ||
public async Task ThenTheApiIsCalledWithAnInvalidAccountIdAndTheCohortsCountIsZero() | ||
{ | ||
SetupApiClient(0, false); | ||
|
||
var actual = await _service.GetCohortsCount(0); | ||
|
||
Assert.AreEqual(0, actual); | ||
} | ||
|
||
private void SetupApiClient(long accountId, bool addItem = true) | ||
{ | ||
var items = new List<CohortSummary>(); | ||
|
||
if (addItem) | ||
{ | ||
items = new List<CohortSummary> | ||
{ | ||
new CohortSummary | ||
{ | ||
AccountId = accountId | ||
} | ||
}; | ||
} | ||
|
||
_apiClient.Setup(o => | ||
o.Get<GetCohortsResponse>( | ||
It.Is<GetCohortsRequest>(i => i.GetUrl.Equals($"api/cohorts?accountId={accountId}")))) | ||
.ReturnsAsync(new GetCohortsResponse | ||
{ | ||
Cohorts = items | ||
}); | ||
} | ||
} | ||
} |