public async Task Then_Each_Apprentice_Record_Is_Checked_And_If_Client_Returns_Ok_Is_Returned( List <ApprenticeshipItem> allApprenticeship, ApprenticeshipItem passingApprenticeship, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { //Arrange client.Setup(x => x.GetResponseCode(It.IsAny <IGetApiRequest>())) .ReturnsAsync(HttpStatusCode.NotFound); allApprenticeship.Add(passingApprenticeship); client.Setup(x => x.GetResponseCode(It.Is <GetEligibleApprenticeshipsRequest>(c => c.GetUrl.Contains($@"/{passingApprenticeship.Uln}?") && c.GetUrl.Contains($@"?startDate={passingApprenticeship.StartDate:yyyy-MM-dd}&isApproved") ))) .ReturnsAsync(HttpStatusCode.OK); //Act var actual = await service.GetEligibleApprenticeships(allApprenticeship); //Assert actual.ToList().Should().ContainEquivalentOf(passingApprenticeship); actual.Length.Should().Be(1); }
public async Task Then_Health_Check_Should_Return_False() { var sut = new EmployerIncentivesService(null); var result = await sut.IsHealthy(); result.Should().Be(false); }
public async Task Then_The_InnerApi_Is_Called( [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { await service.EarningsResilienceCheck(); client.Verify(x => x.Post <string>(It.IsAny <EarningsResilenceCheckRequest>()), Times.Once); }
public async Task And_Api_Is_Available_And_Does_Not_Returns_Ok_Then_Health_Check_Should_Return_False( [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, [Greedy] EmployerIncentivesService sut) { client.Setup(x => x.GetResponseCode(It.Is <IGetApiRequest>(p => p.GetUrl == "ping"))) .ReturnsAsync(HttpStatusCode.NotFound); var result = await sut.IsHealthy(); result.Should().BeFalse(); }
public async Task Then_The_InnerApi_Is_Called( ConfirmIncentiveApplicationRequest request, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { await service.ConfirmIncentiveApplication(request); client.Verify(x => x.Patch(It.Is <ConfirmIncentiveApplicationRequest>( c => c.PatchUrl.Contains(request.Data.IncentiveApplicationId.ToString()) )), Times.Once); }
public async Task Then_The_InnerApi_Is_Called( CreateIncentiveApplicationRequestData requestData, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService sut) { await sut.CreateIncentiveApplication(requestData); client.Verify(x => x.Post <CreateIncentiveApplicationRequestData>(It.Is <CreateIncentiveApplicationRequest>( c => (CreateIncentiveApplicationRequestData)c.Data == requestData && c.PostUrl.Contains("application") )), Times.Once); }
public async Task Then_The_InnerApi_Is_Called( SendBankDetailsRepeatReminderEmailsRequest requestData, long accountId, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService sut) { await sut.SendBankDetailsRepeatReminderEmails(requestData); client.Verify(x => x.Post <SendBankDetailsRepeatReminderEmailsRequest>(It.Is <PostBankDetailsRepeatReminderEmailsRequest>( c => c.Data == requestData && c.PostUrl.Contains("bank-details-repeat-reminders") )), Times.Once); }
public async Task Then_The_Api_Is_Called_To_Update_the_vendor_registration_case_status( UpdateVendorRegistrationCaseStatusRequest request, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { await service.UpdateVendorRegistrationCaseStatus(request); client.Verify(x => x.Patch(It.Is <PatchVendorRegistrationCaseStatusRequest>( c => c.PatchUrl.Contains(request.HashedLegalEntityId) && c.Data.IsSameOrEqualTo(request) )), Times.Once ); }
public async Task Then_The_Api_Is_Called_To_Create_The_New_LegalEntity( long accountId, AccountLegalEntityCreateRequest createObject, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { client.Setup(x => x.Put(It.Is <PutAccountLegalEntityRequest>(y => y.PutUrl == $"accounts/{accountId}/legalentities" && y.Data.IsSameOrEqualTo(createObject)))).Returns(Task.CompletedTask); await service.CreateLegalEntity(accountId, createObject); client.Verify(x => x.Put(It.Is <PutAccountLegalEntityRequest>(y => y.PutUrl == $"accounts/{accountId}/legalentities")), Times.Once); }
public void Then_An_Exception_Is_Thrown_If_The_Uln_Is_Not_Found( List <ApprenticeshipItem> allApprenticeship, ApprenticeshipItem passingApprenticeship, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { //Arrange client.Setup(x => x.GetResponseCode(It.IsAny <GetEligibleApprenticeshipsRequest>())) .ReturnsAsync(HttpStatusCode.InternalServerError); //Act Assert.ThrowsAsync <ApplicationException>(() => service.GetEligibleApprenticeships(allApprenticeship)); }
public async Task Then_The_Api_Is_Called_To_Remove_The_LegalEntity_For_An_Account( long accountId, long accountLegalEntityId, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { await service.DeleteAccountLegalEntity(accountId, accountLegalEntityId); client.Verify(x => x.Delete( It.Is <DeleteAccountLegalEntityRequest>(c => c.DeleteUrl.Contains(accountId.ToString()) && c.DeleteUrl.Contains(accountLegalEntityId.ToString()))), Times.Once); }
public async Task Then_The_Api_Client_Is_Sent_A_Ping_Request_And_False_Returned_If_Not_OK_Status_Code( [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { //Arrange client.Setup(x => x.GetResponseCode(It.IsAny <GetPingRequest>())).ReturnsAsync(HttpStatusCode.InternalServerError); //Act var actual = await service.IsHealthy(); //Assert actual.Should().BeFalse(); }
public async Task Then_The_InnerApi_Is_Called( string hashedLegalEntityId, string employerVendorId, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService sut) { await sut.AddEmployerVendorIdToLegalEntity(hashedLegalEntityId, employerVendorId); client.Verify(x => x.Put(It.Is <PutEmployerVendorIdForLegalEntityRequest>( c => ((PutEmployerVendorIdForLegalEntityRequestData)c.Data).EmployerVendorId == employerVendorId && c.PutUrl.Contains(hashedLegalEntityId)) ), Times.Once); }
public async Task Then_The_InnerApi_Is_Called( long accountId, Guid applicationId, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService sut) { await sut.GetApplicationLegalEntity(accountId, applicationId); client.Verify(x => x.Get <long>(It.Is <GetApplicationLegalEntityRequest>( c => c.GetUrl.Contains("accountlegalentity") )), Times.Once); }
public async Task Then_The_InnerApi_Is_Called( UpdateIncentiveApplicationRequestData requestData, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService sut) { await sut.UpdateIncentiveApplication(requestData); client.Verify(x => x.Put(It.Is <UpdateIncentiveApplicationRequest>( c => c.Data == requestData && c.PutUrl.Contains("application") && c.PutUrl.Contains(requestData.IncentiveApplicationId.ToString()) )), Times.Once); }
public async Task Then_The_InnerApi_Is_Called( UpdateCollectionCalendarPeriodRequestData request, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService sut) { await sut.UpdateCollectionCalendarPeriod(request); client.Verify(x => x.Patch <UpdateCollectionCalendarPeriodRequestData>(It.Is <UpdateCollectionCalendarPeriodRequest>( c => ((UpdateCollectionCalendarPeriodRequestData)c.Data).PeriodNumber == request.PeriodNumber && ((UpdateCollectionCalendarPeriodRequestData)c.Data).AcademicYear == request.AcademicYear && ((UpdateCollectionCalendarPeriodRequestData)c.Data).Active == request.Active && c.PatchUrl.Equals("collectionPeriods")) ), Times.Once); }
public async Task Then_The_Api_Is_Called_Returning_The_Incentive_Details( GetIncentiveDetailsResponse apiResponse, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service ) { client.Setup(x => x.Get <GetIncentiveDetailsResponse>( It.IsAny <GetIncentiveDetailsRequest>())) .ReturnsAsync(apiResponse); var actual = await service.GetIncentiveDetails(); actual.Should().BeEquivalentTo(apiResponse); }
public async Task Then_The_IncentivesApi_Is_Called_Returning_The_Response( GetLatestVendorRegistrationCaseUpdateDateTimeResponse apiResponse, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service ) { client.Setup(x => x.Get <GetLatestVendorRegistrationCaseUpdateDateTimeResponse>( It.IsAny <GetLatestVendorRegistrationCaseUpdateDateTimeRequest>())) .ReturnsAsync(apiResponse); var actual = await service.GetLatestVendorRegistrationCaseUpdateDateTime(); actual.Should().BeEquivalentTo(apiResponse); }
public async Task Then_The_Api_Is_Called_Returning_LegalEntities_For_The_Account( long accountId, IEnumerable <AccountLegalEntity> apiResponse, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service ) { client.Setup(x => x.GetAll <AccountLegalEntity>( It.Is <GetAccountLegalEntitiesRequest>(c => c.GetAllUrl.Contains(accountId.ToString())))) .ReturnsAsync(apiResponse); var actual = await service.GetAccountLegalEntities(accountId); actual.Should().BeEquivalentTo(apiResponse); }
public async Task Then_The_Api_Is_Called_To_Sign_The_Agreement( long accountId, long accountLegalEntityId, SignAgreementRequest request, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { await service.SignAgreement(accountId, accountLegalEntityId, request); client.Verify(x => x.Patch(It.Is <PatchSignAgreementRequest>( c => c.PatchUrl.Contains(accountId.ToString()) && c.PatchUrl.Contains(accountLegalEntityId.ToString()) && c.Data.IsSameOrEqualTo(request) )), Times.Once ); }
public async Task Then_The_Api_Is_Called_Returning_The_Application( long accountId, Guid applicationId, IncentiveApplicationDto apiResponse, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service ) { client.Setup(x => x.Get <IncentiveApplicationDto>( It.Is <GetApplicationRequest>(c => c.GetUrl.Contains(accountId.ToString()) && c.GetUrl.Contains(applicationId.ToString())))) .ReturnsAsync(apiResponse); var actual = await service.GetApplication(accountId, applicationId); actual.Should().BeEquivalentTo(apiResponse); }
public async Task Then_The_Api_Is_Called_With_The_Revert_Payments_Request( RevertPaymentsRequest request, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service ) { client.Setup(x => x.PostWithResponseCode <PostRevertPaymentsRequest>( It.Is <PostRevertPaymentsRequest>( c => c.PostUrl.Contains("revert-payments") ))).ReturnsAsync(new ApiResponse <PostRevertPaymentsRequest>(null, HttpStatusCode.NoContent, "")); await service.RevertPayments(request); client.Verify(x => x.PostWithResponseCode <PostRevertPaymentsRequest>( It.Is <PostRevertPaymentsRequest>(c => c.PostUrl.Contains("revert-payments") )), Times.Once); }
public async Task Then_Each_Apprentice_Record_Is_Checked( List <ApprenticeshipItem> allApprenticeship, [Frozen] Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> > client, EmployerIncentivesService service) { //Arrange client.Setup(x => x.GetResponseCode(It.IsAny <GetEligibleApprenticeshipsRequest>())) .ReturnsAsync(HttpStatusCode.OK); //Act var actual = await service.GetEligibleApprenticeships(allApprenticeship); //Assert actual.ToList().Should().BeEquivalentTo(allApprenticeship); client.Verify(x => x.GetResponseCode(It.IsAny <GetEligibleApprenticeshipsRequest>()), Times.Exactly(allApprenticeship.Count)); }
public async Task Then_an_exception_is_thrown_for_a_non_success_http_status_code() { // Arrange var fixture = new Fixture(); var client = new Mock <IEmployerIncentivesApiClient <EmployerIncentivesConfiguration> >(); client.Setup(x => x.PostWithResponseCode <PostRevertPaymentsRequest>( It.Is <PostRevertPaymentsRequest>( c => c.PostUrl.Contains("revert-payments") ))).ReturnsAsync(new ApiResponse <PostRevertPaymentsRequest>(null, HttpStatusCode.BadRequest, "Invalid request")); var request = fixture.Create <RevertPaymentsRequest>(); var service = new EmployerIncentivesService(client.Object); // Act Func <Task> act = async() => { await service.RevertPayments(request); }; // Assert await act.Should().ThrowAsync <HttpRequestContentException>(); }