Exemple #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));
        }
Exemple #2
0
        public void WhenAddressesGatewayReturnsNullThenUsecasePopulatesDistanceAndMetadataFields()
        {
            // arrange
            var request = Randomm.Create <GetServiceByIdRequest>();

            request.PostCode = Randomm.Postcode();

            var expectedService = EntityHelpers.CreateService().ToDomain();

            _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService);

            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.Service.Locations.Should().OnlyContain(l => l.Latitude.HasValue && l.Longitude.HasValue ? l.Distance != null : l.Distance == null);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
        public void Success()
        {
            // arrange
            var expectedCoordinates = Randomm.Coordinates();
            var contextResponse     = Randomm.AddressesAPIContextResponse(200, expectedCoordinates);

            _mockAddressesApiContext.Setup(c => c.GetAddressesRequest(It.IsAny <string>())).Returns(contextResponse);

            // act
            var gatewayResponse = _classUnderTest.GetPostcodeCoordinates(It.IsAny <string>());

            // assert
            gatewayResponse.Should().BeEquivalentTo(expectedCoordinates);
        }
Exemple #6
0
        public void GivenAPostcodeIfServicesGatewayReturnsAnEmptyCollectionThenUsecaseAlsoReturnsEmptyCollection() // essentially a test to see if the sorting implementation doesn't fall over upon empty collection.
        {
            // 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 = new SearchServiceGatewayResult(
                fullMatchServices: new List <ServiceEntity>(),
                splitMatchServices: new List <ServiceEntity>()
                );

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

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

            // assert
            usecaseResponse.Services.Should().BeEmpty();
        }