Example #1
0
        public async Task WhenLatitudeAndLogitudeAreNotProvided_SetsThemWithGeocodingAPI()
        {
            var request = new Request
            {
                ProviderId = "someId",
                Address    = "1 Happy Street",
                City       = "Happytown",
                State      = "HP",
                Zip        = "12345",
                Status     = RequestStatus.Unassigned
            };

            var address = new Geocoding.Google.GoogleAddress(
                Geocoding.Google.GoogleAddressType.Premise,
                "formatted address",
                new[] { new Geocoding.Google.GoogleAddressComponent(
                            new [] { Geocoding.Google.GoogleAddressType.Country },
                            "",
                            "") },
                new Geocoding.Location(42, 24), //This is the only part that matters: the coordinates
                null,
                false,
                Geocoding.Google.GoogleLocationType.Rooftop);

            var geocoder = new Mock <IGeocoder>();
            AddRequestCommandHandlerAsync sut = new AddRequestCommandHandlerAsync(this.Context, geocoder.Object);

            geocoder.Setup(g => g.Geocode(request.Address, request.City, request.State, request.Zip, string.Empty))
            .Returns(new[] { address });

            await sut.Handle(new AddRequestCommandAsync { Request = request });

            Assert.Equal(42, request.Latitude);
            Assert.Equal(24, request.Longitude);
        }
        public async Task WhenEitherLatitudeOrLogitudeAreProvided_DoNotChangeThem()
        {
            var request = new Request
            {
                ProviderId = "someId",
                Address    = "1 Happy Street",
                City       = "Happytown",
                State      = "HP",
                Zip        = "12345",
                Latitude   = 13,
                Longitude  = 14,
                Status     = RequestStatus.Unassigned
            };

            var address = new Geocoding.Google.GoogleAddress(
                Geocoding.Google.GoogleAddressType.Premise,
                "formatted address",
                new[] { new Geocoding.Google.GoogleAddressComponent(
                            new [] { Geocoding.Google.GoogleAddressType.Country },
                            "",
                            "") },
                new Geocoding.Location(42, 24), //This is the only part that matters: the coordinates
                null,
                false,
                Geocoding.Google.GoogleLocationType.Rooftop);

            _geocoder.Setup(g => g.Geocode(request.Address, request.City, request.State, request.Zip, string.Empty))
            .Returns(new[] { address });

            await _sut.Handle(new AddRequestCommandAsync { Request = request });

            Assert.Equal(13, request.Latitude);
            Assert.Equal(14, request.Longitude);

            //Clear latitude and re-test
            request.Latitude  = 0;
            request.Longitude = 14;
            await _sut.Handle(new AddRequestCommandAsync { Request = request });

            Assert.Equal(0, request.Latitude);
            Assert.Equal(14, request.Longitude);

            //Clear longitude and re-test
            request.Latitude  = 13;
            request.Longitude = 0;
            await _sut.Handle(new AddRequestCommandAsync { Request = request });

            Assert.Equal(13, request.Latitude);
            Assert.Equal(0, request.Longitude);
        }
        public async Task WhenLatitudeAndLogitudeAreNotProvided_SetsThemWithGeocodingAPI()
        {
            var request = new Request
            {
                ProviderId = "someId",
                Address = "1 Happy Street",
                City = "Happytown",
                State = "HP",
                Zip = "12345",
                Status = RequestStatus.UnAssigned
            };

            var address = new Geocoding.Google.GoogleAddress(
                Geocoding.Google.GoogleAddressType.Premise,
                "formatted address",
                new[] { new Geocoding.Google.GoogleAddressComponent(
                    new [] { Geocoding.Google.GoogleAddressType.Country },
                    "",
                    "")},
                new Geocoding.Location(42, 24), //This is the only part that matters: the coordinates
                null,
                false,
                Geocoding.Google.GoogleLocationType.Rooftop);

            _geocoder.Setup(g => g.Geocode(request.Address, request.City, request.State, request.Zip, string.Empty))
                .Returns(new[] { address });

            await _sut.Handle(new AddRequestCommandAsync { Request = request });

            Assert.Equal(42, request.Latitude);
            Assert.Equal(24, request.Longitude);
        }
        public async Task WhenEitherLatitudeOrLogitudeAreProvided_DoNotChangeThem()
        {
            var request = new Request
            {
                ProviderId = "someId",
                Address = "1 Happy Street",
                City = "Happytown",
                State = "HP",
                Zip = "12345",
                Latitude = 13,
                Longitude = 14,
                Status = RequestStatus.Unassigned
            };

            var address = new Geocoding.Google.GoogleAddress(
                Geocoding.Google.GoogleAddressType.Premise,
                "formatted address",
                new[] { new Geocoding.Google.GoogleAddressComponent(
                    new [] { Geocoding.Google.GoogleAddressType.Country },
                    "",
                    "")},
                new Geocoding.Location(42, 24), //This is the only part that matters: the coordinates
                null,
                false,
                Geocoding.Google.GoogleLocationType.Rooftop);

            var geocoder = new Mock<IGeocoder>();
            AddRequestCommandHandler sut = new AddRequestCommandHandler(this.Context, geocoder.Object);

            geocoder.Setup(g => g.Geocode(request.Address, request.City, request.State, request.Zip, string.Empty))
                .Returns(new[] { address });

            await sut.Handle(new AddRequestCommand { Request = request });

            Assert.Equal(13, request.Latitude);
            Assert.Equal(14, request.Longitude);

            //Clear latitude and re-test
            request.Latitude = 0;
            request.Longitude = 14;
            await sut.Handle(new AddRequestCommand { Request = request });

            Assert.Equal(0, request.Latitude);
            Assert.Equal(14, request.Longitude);

            //Clear longitude and re-test
            request.Latitude = 13;
            request.Longitude = 0;
            await sut.Handle(new AddRequestCommand { Request = request });

            Assert.Equal(13, request.Latitude);
            Assert.Equal(0, request.Longitude);
        }