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); }
protected static void setup_event_stream(params StreamEvent[] streamEvents) { events_fetcher .Setup(_ => _.Fetch(It.IsAny <StreamPosition>(), It.IsAny <CancellationToken>())) .Returns <StreamPosition, CancellationToken>((position, ct) => { var events = streamEvents.Skip((int)position.Value); return(events.Any() ? Task.FromResult(Try <IEnumerable <StreamEvent> > .Succeeded(events)) : Task.FromResult(Try <IEnumerable <StreamEvent> > .Failed(new Exception()))); }); event_waiter.NotifyForEvent(source_stream_id, (ulong)(streamEvents.Length - 1)); }
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}"); } }
protected static void NotFail() { NotCalled(x => x.Fail(IT.IsAny <string>(), IT.IsAny <object>())); NotCalled(x => x.Fail(IT.IsAny <string>())); }
public static T IsAny <T>() { return(It.IsAny <T>()); }