-
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.
- Loading branch information
1 parent
1277499
commit 66d9074
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/SFA.DAS.EmployerAccounts.UnitTests/Services/ProviderRegistration/WhenIGetInvitation.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,91 @@ | ||
using System; | ||
using System.Configuration; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using Moq.Protected; | ||
using NUnit.Framework; | ||
using SFA.DAS.EmployerAccounts.Configuration; | ||
using SFA.DAS.EmployerAccounts.Interfaces; | ||
using SFA.DAS.EmployerAccounts.Services; | ||
|
||
namespace SFA.DAS.EmployerAccounts.UnitTests.Services.ProviderRegistration | ||
{ | ||
class WhenIGetInvitation | ||
{ | ||
private IProviderRegistrationApiClient _sut; | ||
private ProviderRegistrationClientApiConfiguration _configuration; | ||
private string _correlationId; | ||
private string _testData; | ||
private string _apiBaseUrl; | ||
private string _identifierUri; | ||
Mock<HttpMessageHandler> _mockHttpMessageHandler; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
ConfigurationManager.AppSettings["EnvironmentName"] = "LOCAL"; | ||
_apiBaseUrl = $"http://{Guid.NewGuid().ToString()}/"; | ||
_identifierUri = Guid.NewGuid().ToString(); | ||
_correlationId = Guid.NewGuid().ToString(); | ||
_testData = "Employer details"; | ||
|
||
_configuration = new ProviderRegistrationClientApiConfiguration | ||
{ | ||
BaseUrl = _apiBaseUrl, | ||
IdentifierUri = _identifierUri | ||
}; | ||
|
||
_mockHttpMessageHandler = new Mock<HttpMessageHandler>(); | ||
|
||
_mockHttpMessageHandler | ||
.Protected() | ||
.Setup<Task<HttpResponseMessage>>("SendAsync", | ||
ItExpr.IsAny<HttpRequestMessage>(), | ||
ItExpr.IsAny<CancellationToken>()) | ||
.ReturnsAsync(new HttpResponseMessage | ||
{ | ||
Content = new StringContent(_testData), | ||
StatusCode = HttpStatusCode.OK | ||
} | ||
).Verifiable(""); | ||
|
||
var httpClient = new HttpClient(_mockHttpMessageHandler.Object); | ||
|
||
_sut = new ProviderRegistrationApiClient(httpClient, _configuration); | ||
} | ||
|
||
[Test] | ||
public async Task Verify_ProviderRegistrationApiToGetInvitationIsCalled() | ||
{ | ||
//act | ||
await _sut.GetInvitations(_correlationId); | ||
|
||
//assert | ||
_mockHttpMessageHandler | ||
.Protected() | ||
.Verify("SendAsync", Times.Once(), | ||
ItExpr.Is<HttpRequestMessage>(r => r.Method == HttpMethod.Get | ||
&& r.RequestUri.AbsoluteUri == $"{_configuration.BaseUrl}api/invitations/{_correlationId}"), | ||
ItExpr.IsAny<CancellationToken>()); | ||
} | ||
|
||
[Test] | ||
public async Task Verify_ProviderRegistrationApiToUnsubscribeIsCalled() | ||
{ | ||
//act | ||
await _sut.Unsubscribe(_correlationId); | ||
|
||
//assert | ||
_mockHttpMessageHandler | ||
.Protected() | ||
.Verify("SendAsync", Times.Once(), | ||
ItExpr.Is<HttpRequestMessage>(r => r.Method == HttpMethod.Get | ||
&& r.RequestUri.AbsoluteUri == $"{_configuration.BaseUrl}api/unsubscribe/{_correlationId}"), | ||
ItExpr.IsAny<CancellationToken>()); | ||
} | ||
|
||
} | ||
} |