public void AddLocation_ReturnsNotFoundResult_WhenUnknownTripIdentifier()
        {
            const string tripIdentifier = "ab7d8df0-e952-4956-8c38-0351b90fd045";

            var mockRepository = Substitute.For <ITripRepository>();

            mockRepository.FindTrip(tripIdentifier).Returns(x => null);
            var controller = new TripController(mockRepository);

            var result = controller.AddLocation(tripIdentifier, new LocationDto
            {
                Latitude  = 55.6782377,
                Longitude = 12.5594759
            });

            Assert.IsType <NotFoundResult>(result);
        }
        public void AddLocation_ReturnsBadRequestObjectResult_WhenModelStateIsInvalid()
        {
            var mockRepository = Substitute.For <ITripRepository>();
            var controller     = new TripController(mockRepository);

            controller.ModelState.AddModelError("Latitude", "Value out of range");
            controller.ModelState.AddModelError("Longitude", "Value out of range");
            var location = new LocationDto
            {
                Latitude  = -91,
                Longitude = 181
            };

            var result = controller.AddLocation("ab7d8df0-e952-4956-8c38-0351b90fd045", location);

            var badRequestResult   = Assert.IsType <BadRequestObjectResult>(result);
            var badRequestLocation = Assert.IsType <LocationDto>(badRequestResult.Value);

            Assert.Equal(location.Latitude, badRequestLocation.Latitude);
            Assert.Equal(location.Longitude, badRequestLocation.Longitude);
        }
        public void AddLocation_ReturnsBadRequestObjectResult_WhenInvalidTripIdentifier(string tripIdentifier,
                                                                                        double latitude, double longitude)
        {
            var trip = new Trip
            {
                TripIdentifier = tripIdentifier
            };

            var mockRepository = Substitute.For <ITripRepository>();

            mockRepository.FindTrip(tripIdentifier).Returns(trip);
            var controller = new TripController(mockRepository);

            var result = controller.AddLocation(trip.TripIdentifier, new LocationDto
            {
                Latitude  = latitude,
                Longitude = longitude
            });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Example #4
0
        public async Task AddLocation()
        {
            // Inject
            CreateIdentity(Users[0].Auth);

            // Arrange
            UserTrips trip;
            Locations locations;

            using (var a = factory.CreateDbContext())
            {
                trip = new UserTrips()
                {
                    UserId = Users[0].Id, Name = "Trip to somewhere 2", Transportation = "BICYCLING"
                };

                locations = new Locations()
                {
                    Lang = 5, Long = 3, PlaceId = "PlaceId6", Name = "aweawezsS", TripId = trip.Id
                };
                trip.Locations.Add(locations);

                await a.AddAsync(trip);

                await a.SaveChangesAsync();
            }

            var expected = mapper.Map <LocationsViewModel>(locations);


            // Act
            var result = await controller.AddLocation(trip.Id, locations);

            // Assert
            Assert.Equal(Serialize(expected), Serialize(((OkObjectResult)result).Value));
        }