diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Services/Reservations/WhenIGetReservationWithTimeoutData.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Services/Reservations/WhenIGetReservationWithTimeoutData.cs new file mode 100644 index 0000000000..2e33a96858 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Services/Reservations/WhenIGetReservationWithTimeoutData.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Moq; +using Newtonsoft.Json; +using NUnit.Framework; +using Polly; +using Polly.Registry; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.Reservations; +using SFA.DAS.EmployerAccounts.Services; + +namespace SFA.DAS.EmployerAccounts.UnitTests.Services.Reservations +{ + class WhenIGetReservationWithTimeoutData + { + private Mock _mockReservationsApiClient; + private IReservationsService _sut; + private Mock _mockreservationsService; + private string _testData; + private Mock _mockPolicy; + + long _accountId; + + [SetUp] + public void Arrange() + { + _accountId = 123; + _testData = JsonConvert.SerializeObject(new List { new Reservation { AccountId = _accountId } }); + + _mockReservationsApiClient = new Mock(); + _mockReservationsApiClient + .Setup(m => m.Get(_accountId)) + .ReturnsAsync(_testData); + _mockPolicy = new Mock(); + var mockRegistryPolicy = new PolicyRegistry(); + mockRegistryPolicy.Add(Constants.DefaultServiceTimeout, _mockPolicy.Object); + _mockreservationsService = new Mock(_mockReservationsApiClient.Object); + _sut = new ReservationsServiceWithTimeout(_mockreservationsService.Object, mockRegistryPolicy); + } + + [Test] + public async Task ThenTheReservationsAreReturnedFromTheService() + { + //arrange + IEnumerable reservations = new List { + new Reservation {AccountId = _accountId} + }; + _mockreservationsService.Setup(rs => rs.Get(_accountId)) + .Returns(It.IsAny>>()); + //act + await _sut.Get(_accountId); + + // assert + _mockPolicy.Verify(p => p.ExecuteAsync(It.IsAny>>>())); + } + + [Test] + public async Task ThenTheReservationsServiceReturnsATimeout() + { + //act + await _sut.Get(_accountId); + + // assert + _mockPolicy.Verify(p => p.ExecuteAsync(It.IsAny>>>())); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Services/ReservationsService.cs b/src/SFA.DAS.EmployerAccounts/Services/ReservationsService.cs index 631def5c6b..7be36dabfa 100644 --- a/src/SFA.DAS.EmployerAccounts/Services/ReservationsService.cs +++ b/src/SFA.DAS.EmployerAccounts/Services/ReservationsService.cs @@ -18,7 +18,7 @@ public ReservationsService(IReservationsApiClient client) public async Task> Get(long accountId) { - string reservations = await _client.Get(accountId); + var reservations = await _client.Get(accountId); return JsonConvert.DeserializeObject>(reservations); } }