Ejemplo n.º 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>();
            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(42, request.Latitude);
            Assert.Equal(24, request.Longitude);
        }
        public async Task WhenProviderIdIsProvidedAndIsValid_TheStatusOfTheExistingRequestIsUpdated()
        {
            string pid = "someId";
            var request = new Request
            {
                ProviderId = pid,
                Status = RequestStatus.Assigned
            };
            var command = new AddRequestCommand{Request = request};

            var options = this.CreateNewContextOptions();

            using (var context = new AllReadyContext(options)) {
                context.Requests.Add(new Request {
                    ProviderId = pid,
                    Status = RequestStatus.Assigned
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var geocoder = new Mock<IGeocoder>();
                AddRequestCommandHandler sut = new AddRequestCommandHandler(context, geocoder.Object);


                await sut.Handle(command);
            }

            using (var context = new AllReadyContext(options)) {
                var entity = context.Requests.FirstOrDefault(x => x.ProviderId == pid);
                Assert.Equal(entity.Status, RequestStatus.Assigned);
            }
        }
Ejemplo n.º 3
0
        public async Task WhenProviderIdIsProvidedAndIsValid_TheStatusOfTheExistingRequestIsUpdated()
        {
            string pid     = "someId";
            var    request = new Request
            {
                ProviderId = pid,
                Status     = RequestStatus.Assigned
            };
            var command = new AddRequestCommand {
                Request = request
            };

            var options = this.CreateNewContextOptions();

            using (var context = new AllReadyContext(options)) {
                context.Requests.Add(new Request {
                    ProviderId = pid,
                    Status     = RequestStatus.Assigned
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var geocoder = new Mock <IGeocoder>();
                AddRequestCommandHandler sut = new AddRequestCommandHandler(context, geocoder.Object);


                await sut.Handle(command);
            }

            using (var context = new AllReadyContext(options)) {
                var entity = context.Requests.FirstOrDefault(x => x.ProviderId == pid);
                Assert.Equal(entity.Status, RequestStatus.Assigned);
            }
        }
        public async Task WhenNoProviderIdIsProvided_TheStatusIsUnassignedAndIdIsNotNull()
        {
            var request = new Request();
            var command = new AddRequestCommand {Request = request};

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

            Assert.NotNull(request.RequestId);
            Assert.Equal(RequestStatus.Unassigned, request.Status);

        }
        public async Task HandleReturnsNullWhenNoErrorsOccur() {

            var command = new AddRequestCommand {
                Request = new Request {ProviderId = "successId"}
            };

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

            var result = await sut.Handle(command);

            Assert.Null(result);
        }
Ejemplo n.º 6
0
        public async Task WhenNoProviderIdIsProvided_TheStatusIsUnassignedAndIdIsNotNull()
        {
            var request = new Request();
            var command = new AddRequestCommand {
                Request = request
            };

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

            Assert.NotNull(request.RequestId);
            Assert.Equal(RequestStatus.Unassigned, request.Status);
        }
Ejemplo n.º 7
0
        public async Task HandleReturnsNullWhenNoErrorsOccur()
        {
            var command = new AddRequestCommand {
                Request = new Request {
                    ProviderId = "successId"
                }
            };

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

            var result = await sut.Handle(command);

            Assert.Null(result);
        }
Ejemplo n.º 8
0
 public AddRequestCommandHandlerTests()
 {
     _dataAccess = new Mock <IAllReadyDataAccess>();
     _sut        = new AddRequestCommandHandler(_dataAccess.Object);
 }
        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>();
            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(42, request.Latitude);
            Assert.Equal(24, request.Longitude);
        }