コード例 #1
0
        public async Task GetLocationByVehicleIdAndPeriodTimeAsync_WithFilterRequest_ReturnLocationResponse()
        {
            // Arrange
            var locationFilter = new LocationFilterRequest
            {
                VehicleId = 1,
                StartDate = new DateTime(2020, 3, 1),
                EndDate   = new DateTime(2020, 3, 2)
            };

            var locations = new List <Location>
            {
                new Location
                {
                    Id         = Guid.NewGuid(),
                    VehicleId  = 1,
                    Latitude   = 13.788571,
                    Longitude  = 100.538034,
                    UpdateDate = new DateTime(2020, 3, 1)
                }
            };

            locationsRepository
            .GetLocationByVehicleIdAndPeriodTimeAsync(Arg.Any <int>(), Arg.Any <DateTime>(), Arg.Any <DateTime>())
            .Returns(Task.FromResult(locations));

            // Act
            var response = await locationsService.GetLocationByVehicleIdAndPeriodTimeAsync(locationFilter);

            // Assert
            Assert.NotNull(response);
            Assert.IsType <List <LocationResponse> >(response);
        }
コード例 #2
0
        public async Task <IActionResult> GetLocationByVehicleIdAndPeriodTime([FromBody] LocationFilterRequest request)
        {
            if (request == null)
            {
                return(BadRequest(ModelState));
            }

            var responses = await locationsService.GetLocationByVehicleIdAndPeriodTimeAsync(request);

            if (responses == null)
            {
                return(NotFound());
            }

            return(Ok(responses));
        }
コード例 #3
0
        public async Task GetCurrentLocation_WithVehicleIdAndPeriodTime_ReturnStatusCodeOK()
        {
            // Arrange
            var locationFilter = new LocationFilterRequest
            {
                VehicleId = 1,
                StartDate = new DateTime(2020, 3, 1),
                EndDate   = new DateTime(2020, 3, 2)
            };

            var locationId = new Guid("CFB31112-C780-4535-815A-BB0C93EDD249");

            var locationResponses = new List <LocationResponse>
            {
                new LocationResponse
                {
                    Id        = locationId,
                    VehicleId = 1,
                    Latitude  = 13.788571,
                    Longitude = 100.538034,
                }
            };

            locationsService
            .GetLocationByVehicleIdAndPeriodTimeAsync(Arg.Any <LocationFilterRequest>())
            .Returns(Task.FromResult <IReadOnlyCollection <LocationResponse> >(locationResponses));

            // Act
            var actionResult = await locationsController.GetLocationByVehicleIdAndPeriodTime(locationFilter);

            var objectResult = actionResult as OkObjectResult;

            //Assert
            Assert.NotNull(objectResult);
            Assert.Equal((int)System.Net.HttpStatusCode.OK, objectResult.StatusCode);
        }
コード例 #4
0
        public async Task <IReadOnlyCollection <LocationResponse> > GetLocationByVehicleIdAndPeriodTimeAsync(LocationFilterRequest filterRequest)
        {
            var startDateUtc = filterRequest.StartDate.ToUniversalTime();
            var endDateUtc   = filterRequest.EndDate.ToUniversalTime();

            var locations = await locationsRepository.GetLocationByVehicleIdAndPeriodTimeAsync(filterRequest.VehicleId, startDateUtc, endDateUtc);

            var locationResponses = new List <LocationResponse>();

            foreach (var location in locations)
            {
                locationResponses.Add(MapLocationResponse(location));
            }

            return(locationResponses);
        }