示例#1
0
        public void WhenAddressesGatewayReturnsNullThenGetMultipleUsecasePopulatesDistanceAndMetadataFields()
        {
            // arrange
            var request = Randomm.Create <SearchServicesRequest>();

            request.PostCode = Randomm.Postcode();

            var gatewayResponse = Randomm.SSGatewayResult();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(gatewayResponse);

            var expectedPostcodeCoords = Randomm.Coordinates();

            _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Returns(expectedPostcodeCoords);

            // act
            var usecaseResponse = _classUnderTest.ExecuteGet(request);

            // assert
            usecaseResponse.Metadata.PostCode.Should().Be(request.PostCode);
            usecaseResponse.Metadata.PostCodeLatitude.Should().Be(expectedPostcodeCoords.Latitude);
            usecaseResponse.Metadata.PostCodeLongitude.Should().Be(expectedPostcodeCoords.Longitude);
            usecaseResponse.Metadata.Error.Should().BeNull();
            usecaseResponse.Services.Should().OnlyContain(s => s.Locations.All(l => l.Latitude.HasValue && l.Longitude.HasValue ? l.Distance != null : l.Distance == null));
        }
示例#2
0
        [TestCase(TestName = "Given a postcode, When usecase's ExecuteGet method is called, Then it returns a collection of services ordered asc by the closest service location distance.")] // just as above, except this confirms that sorting works fine under normal conditions
        public void GivenAPostcodeReturnedServicesAreOrderedAscByDistance()
        {
            // arrange
            var request = Randomm.Create <SearchServicesRequest>();

            request.PostCode = Randomm.Postcode();

            var addressGatewayResponse = Randomm.Coordinates();

            _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Returns(addressGatewayResponse);

            var serviceGatewayResponse = Randomm.SSGatewayResult();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(serviceGatewayResponse);

            var fullMLength = serviceGatewayResponse.FullMatchServices.Count;

            // act
            var usecaseResponse             = _classUnderTest.ExecuteGet(request);
            var fullMServicesWithLocations  = usecaseResponse.Services.Take(fullMLength).ToList();
            var splitMServicesWithLocations = usecaseResponse.Services.Skip(fullMLength).ToList();

            // assert
            AssertThatServiceCollectionIsInAscendingDistancesOrder(fullMServicesWithLocations);
            AssertThatServiceCollectionIsInAscendingDistancesOrder(splitMServicesWithLocations);
        }
示例#3
0
        public void GivenAPostcodeReturnedServicesAreOrderedInAWayWhereIfTheyHaveNoChildLocationsTheyAreConsideredTheMostDistant()
        {
            // arrange
            var request = Randomm.Create <SearchServicesRequest>();

            request.PostCode = Randomm.Postcode();

            var addressGatewayResponse = Randomm.Coordinates();

            _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Returns(addressGatewayResponse);

            var serviceGatewayResponse = Randomm.SSGatewayResult();

            serviceGatewayResponse.FullMatchServices.FirstOrDefault().ServiceLocations  = new List <ServiceLocation>();
            serviceGatewayResponse.SplitMatchServices.FirstOrDefault().ServiceLocations = new List <ServiceLocation>();
            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(serviceGatewayResponse);

            var fullMLength  = serviceGatewayResponse.FullMatchServices.Count;
            var splitMLength = serviceGatewayResponse.SplitMatchServices.Count;
            var fullMatchServiceNoLocationsName  = serviceGatewayResponse.FullMatchServices.FirstOrDefault().Name; //unique enough due to being generated as hash
            var splitMatchServiceNoLocationsName = serviceGatewayResponse.SplitMatchServices.FirstOrDefault().Name;

            // act
            var usecaseResponse = _classUnderTest.ExecuteGet(request);

            // assert
            usecaseResponse.Services.Take(fullMLength).Last().Name.Should().Be(fullMatchServiceNoLocationsName); // the service with no locations should be last
            usecaseResponse.Services.Last().Name.Should().Be(splitMatchServiceNoLocationsName);

            var fullMServicesWithLocations  = usecaseResponse.Services.Take(fullMLength - 1).ToList();
            var splitMServicesWithLocations = usecaseResponse.Services.Skip(fullMLength).Take(splitMLength - 1).ToList();

            AssertThatServiceCollectionIsInAscendingDistancesOrder(fullMServicesWithLocations); // checking whether sorting works in the context of empty service location existing. essentially a check that sorting doesn't stop half way just because it encountered an exceptional service with no locations
            AssertThatServiceCollectionIsInAscendingDistancesOrder(splitMServicesWithLocations);
        }
示例#4
0
        public void WhenAddressesGatewayThrowsAnExceptionThenGetMultipleUsecasePopulatesTheMetadataErrorField()
        {
            // arrange
            var request = Randomm.Create <SearchServicesRequest>();

            request.PostCode = Randomm.Postcode();

            var gatewayResponse = Randomm.SSGatewayResult();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(gatewayResponse);

            var expectedException = new Exception(Randomm.Text());

            _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Throws(expectedException);

            // act
            var usecaseResponse = _classUnderTest.ExecuteGet(request);

            // assert
            usecaseResponse.Metadata.PostCode.Should().Be(request.PostCode);
            usecaseResponse.Metadata.PostCodeLatitude.Should().Be(null);
            usecaseResponse.Metadata.PostCodeLongitude.Should().Be(null);
            usecaseResponse.Metadata.Error.Should().Be(expectedException.Message);
            usecaseResponse.Services.Should().OnlyContain(s => s.Locations.All(l => l.Distance == null));
        }
示例#5
0
        public void GivenAUrlEncodedSearchTermGatewayIsCalledWithDecodedTerm() // implementation of this test fixes a front-end bug, where front-end app accidentally encodes the url twice before calling an API - I don't we should be 'fixing' this on back-end API.
        {
            var expectedServices = Randomm.SSGatewayResult();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(expectedServices); // dummy setup - irrelevant for the test
            var searchTerm       = Randomm.Text();
            var urlencodedSearch = searchTerm.Replace(" ", "%2520");
            var reqParams        = new SearchServicesRequest();

            reqParams.Search = urlencodedSearch;
            _classUnderTest.ExecuteGet(reqParams);
            _mockServicesGateway.Verify(g => g.SearchServices(It.Is <SearchServicesRequest>(p => p.Search == searchTerm)), Times.Once);
        }
示例#6
0
        public void FactoryConverts2NonEmptyListOfServiceResponseToGetServiceResponseListBoundary()
        {
            // arrange
            var gatewayResponse    = Randomm.SSGatewayResult();
            var fullMatchServices  = gatewayResponse.FullMatchServices.ToResponseServices();
            var splitMatchServices = gatewayResponse.SplitMatchServices.ToResponseServices();

            var expectedServicesList = fullMatchServices.Concat(splitMatchServices);

            // act
            var factoryResult = ServiceFactory.SearchServiceUsecaseResponse(fullMatchServices, splitMatchServices, null);

            // assert
            factoryResult.Services.Should().BeEquivalentTo(expectedServicesList);
        }
示例#7
0
        public void ReturnsServicesIfSeachParamIsProvided() //Wrap up
        {
            var requestParams   = Randomm.Create <SearchServicesRequest>();
            var gatewayResponse = Randomm.SSGatewayResult();
            var fullMServices   = gatewayResponse.FullMatchServices.ToResponseServices();   // because domain doesn't contain distance field
            var splitMServices  = gatewayResponse.SplitMatchServices.ToResponseServices();

            _mockServicesGateway.Setup(g => g.SearchServices(It.IsAny <SearchServicesRequest>())).Returns(gatewayResponse);


            var expectedServices = fullMServices.Concat(splitMServices);
            var response         = _classUnderTest.ExecuteGet(requestParams);

            response.Should().NotBeNull();
            response.Services.Should().BeEquivalentTo(expectedServices);
        }
示例#8
0
        [TestCase(TestName = "Given 1 empty and 1 non-empty list of service response objects, When Factory SearchServiceUsecaseResponse method is called, Then it returns a GetServiceResponseList boundary object with a list containing all the elements from the non-empty list.")] // essentially a check that it doesn't fall over under these circumstances
        public void FactoryConverts1EmptyAnd1NonEmptyListOfServiceResponseToGetServiceResponseListBoundary()
        {
            // arrange
            var gatewayResponse    = Randomm.SSGatewayResult();
            var fullMatchServices  = gatewayResponse.FullMatchServices.ToResponseServices();
            var splitMatchServices = gatewayResponse.SplitMatchServices.ToResponseServices();
            var emptyList          = new List <Response.Service>();

            // act
            var factoryResult1 = ServiceFactory.SearchServiceUsecaseResponse(fullMatchServices, emptyList, null);
            var factoryResult2 = ServiceFactory.SearchServiceUsecaseResponse(emptyList, splitMatchServices, null);

            // assert
            factoryResult1.Services.Should().BeEquivalentTo(fullMatchServices);
            factoryResult2.Services.Should().BeEquivalentTo(splitMatchServices);
        }