private void SetupUrlHelperForAccountLegalEntityOne() { UrlHelper.Setup( x => x.Route( "GetLegalEntity", It.Is <object>( obj => IsAccountLegalEntityOne(obj)))) .Returns( $"/api/accounts/{_hashedAccountId}/legalentities/{_response.LegalEntities[0].Id}"); }
public async Task AndTheAccountCannotBeDecodedThenItIsNotReturned() { Mediator.Setup( x => x.SendAsync( It.Is <GetAccountLegalEntitiesByHashedAccountIdRequest>(q => q.HashedAccountId == _hashedAccountId))) .ThrowsAsync(new InvalidRequestException(new Dictionary <string, string>())); var response = await Controller.GetLegalEntities(_hashedAccountId); Assert.IsNotNull(response); Assert.IsInstanceOf <NotFoundResult>(response); }
public async Task AndTheAccountDoesNotExistThenItIsNotReturned() { Mediator.Setup( x => x.SendAsync( It.Is <GetAccountLegalEntitiesByHashedAccountIdRequest>(q => q.HashedAccountId == _hashedAccountId))) .ReturnsAsync( new GetAccountLegalEntitiesByHashedAccountIdResponse { LegalEntities = new List <AccountSpecificLegalEntity>(0) }); var response = await Controller.GetLegalEntities(_hashedAccountId); Assert.IsNotNull(response); Assert.IsInstanceOf <NotFoundResult>(response); }
public static T Is <T>(Action <T> verify) { Func <T, bool> match = arg => { try { verify(arg); return(true); } catch (SpecificationException e) { Console.Write(e); return(false); } }; return(It.Is <T>(arg => match(arg))); }
public async Task Then_The_Provider_Is_Returned_From_Mediator() { //Arrange var fixture = new Fixture(); var ukprn = fixture.Create <long>(); var provider = fixture.Create <ProviderResponse>(); MockMediator.Setup(m => m.SendAsync(It.Is <GetProviderQuery>(c => c.Ukprn.Equals(ukprn)))) .ReturnsAsync(new GetProviderQueryResponse() { Provider = provider }); //Act var actual = await Orchestrator.GetProvider(ukprn); //Assert actual.Provider.ShouldBeEquivalentTo(provider); }
public async Task ThenTheLegalEntitiesAreReturned() { _hashedAccountId = "ABC123"; _response = new GetAccountLegalEntitiesByHashedAccountIdResponse { LegalEntities = new List <AccountSpecificLegalEntity> { new AccountSpecificLegalEntity { Id = 1 }, new AccountSpecificLegalEntity { Id = 4 } } }; Mediator.Setup(x => x.SendAsync(It.Is <GetAccountLegalEntitiesByHashedAccountIdRequest>(q => q.HashedAccountId == _hashedAccountId))).ReturnsAsync(_response); SetupUrlHelperForAccountLegalEntityOne(); SetupUrlHelperForAccountLegalEntityTwo(); var response = await Controller.GetLegalEntities(_hashedAccountId); Assert.IsNotNull(response); Assert.IsInstanceOf <OkNegotiatedContentResult <ResourceList> >(response); var model = response as OkNegotiatedContentResult <ResourceList>; model?.Content.Should().NotBeNull(); foreach (var legalEntity in _response.LegalEntities) { var matchedEntity = model.Content.Single(x => x.Id == legalEntity.Id.ToString()); matchedEntity.Href.Should().Be($"/api/accounts/{_hashedAccountId}/legalentities/{legalEntity.Id}"); } }
public static TValue Is <TValue>(Expression <Func <TValue, bool> > match) { return(Match <TValue> .Create( value => match.CompileUsingExpressionCompiler().Invoke(value), () => It.Is <TValue>(match))); }