public async Task Then_The_Postcode_Service_Is_Called( GetOutcodeQuery query, SuggestedLocation postcode, [Frozen] Mock <IPostcodeService> service, GetOutcodeQueryHandler handler ) { //Arrange service.Setup(x => x.GetDistrictNameByOutcodeQuery(query.Outcode)).ReturnsAsync(postcode); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert actual.Outcode.Should().Be(postcode); }
public async Task Then_The_Outcode_Api_Is_Called_With_The_Query_And_Returns_District_Data( string query, SuggestedLocation location, [Frozen] Mock <IPostcodeApiService> apiService, PostcodeService service ) { //Arrange apiService.Setup(x => x.GetDistrictData(query)).ReturnsAsync(location); //Act var actual = await service.GetDistrictNameByOutcodeQuery(query); actual.Lat.Should().Be(location.Lat); //Assert actual.Should().BeEquivalentTo(location); }
public async Task Then_If_No_District_Is_Returned_It_Is_Not_Added( string searchTerm, GetLocationsQuery query, List <SuggestedLocation> locations, SuggestedLocation district, [Frozen] Mock <IPostcodeService> service, GetLocationsQueryHandler handler) { //Arrange query.Query = searchTerm; service.Setup(x => x.GetPostcodesByOutcodeQuery(query.Query, query.ResultCount)).ReturnsAsync(locations); service.Setup(y => y.GetDistrictNameByOutcodeQuery(query.Query)).ReturnsAsync((SuggestedLocation)null); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert actual.SuggestedLocations.Should().Contain(locations); actual.SuggestedLocations.Should().NotContainNulls(); }
public async Task Then_The_Service_Is_Called_And_District_First( string searchTerm, GetLocationsQuery query, List <SuggestedLocation> locations, SuggestedLocation district, [Frozen] Mock <IPostcodeService> service, GetLocationsQueryHandler handler) { //Arrange query.Query = searchTerm; service.Setup(x => x.GetPostcodesByOutcodeQuery(query.Query, query.ResultCount)).ReturnsAsync(locations); service.Setup(y => y.GetDistrictNameByOutcodeQuery(query.Query)).ReturnsAsync(district); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert actual.SuggestedLocations.Should().Contain(locations, district); actual.SuggestedLocations.First().Should().Be(district); }
public async Task If_Query_Is_Two_Letter_String_Then_Service_Is_Not_Called( string searchTerm, GetLocationsQuery query, List <SuggestedLocation> locations, SuggestedLocation district, [Frozen] Mock <IPostcodeService> service, GetLocationsQueryHandler handler) { //Arrange query.Query = searchTerm; service.Setup(x => x.GetPostcodesByOutcodeQuery(query.Query, query.ResultCount)).ReturnsAsync(locations); service.Setup(y => y.GetDistrictNameByOutcodeQuery(query.Query)).ReturnsAsync(district); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert service.Verify(x => x.GetPostcodesByOutcodeQuery(It.IsAny <string>(), It.IsAny <int>()), Times.Never); service.Verify(y => y.GetDistrictNameByOutcodeQuery(It.IsAny <string>()), Times.Never); actual.SuggestedLocations.Should().BeNull(); }