コード例 #1
0
        public async Task GetVehicles_GivenOwnerId_FetchByPassedOwnerId(
            string ownerId,
            [Frozen] IVehicleService vehicleService,
            OwnersController sut)
        {
            await sut.GetVehicles(ownerId);

            await vehicleService.Received().GetByOwnerAsync(ownerId);
        }
コード例 #2
0
        public async Task GetVehicles_ExceptionThrown_ShouldLog(
            string ownerId,
            Exception exception,
            [Frozen] ILogger <OwnersController> logger,
            [Frozen] IVehicleService vehicleService,
            OwnersController sut)
        {
            vehicleService.GetByOwnerAsync(Arg.Any <string>()).Throws(exception);

            await sut.GetVehicles(ownerId);

            logger.ReceivedWithAnyArgs().LogError(exception, $"Error fetching vehicle for owner {ownerId}.");
        }
コード例 #3
0
        public async Task GetVehicles_OwnerIdNull_Returns400(
            OwnersController sut)
        {
            var result = (await sut.GetVehicles(null)) as BadRequestObjectResult;

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
            var errorInfo = result.Value as ErrorInfo;

            errorInfo.Should().NotBeNull();
            errorInfo.Type.Should().Be(ErrorType.Validation);
            errorInfo.Messages.Should().BeEquivalentTo($"OwnerId is required.");
        }
コード例 #4
0
        public async Task GetVehicles_ExceptionThrown_Returns500(
            string ownerId,
            [Frozen] IVehicleService vehicleService,
            OwnersController sut)
        {
            vehicleService.GetByOwnerAsync(Arg.Any <string>()).Throws(new Exception());

            var result = (await sut.GetVehicles(ownerId)) as ObjectResult;

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status500InternalServerError);
            var errorInfo = result.Value as ErrorInfo;

            errorInfo.Should().NotBeNull();
            errorInfo.Type.Should().Be(ErrorType.UnhandledError);
            errorInfo.Messages.Should().BeEquivalentTo($"Error fetching vehicles for owner id {ownerId}.");
        }
コード例 #5
0
        public async Task GetVehicles_FetchedListOfVehicles_Returns200WithVehicles(
            string ownerId,
            IEnumerable <VehicleViewModel> vehicles,
            [Frozen] IVehicleService vehicleService,
            OwnersController sut)
        {
            vehicleService.GetByOwnerAsync(Arg.Any <string>()).Returns(vehicles);

            var result = (await sut.GetVehicles(ownerId)) as OkObjectResult;

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status200OK);
            var vehiclesResult = result.Value as IEnumerable <VehicleViewModel>;

            vehiclesResult.Should().NotBeNull();
            vehiclesResult.Should().BeEquivalentTo(vehicles);
        }
コード例 #6
0
        public async Task GetVehicles_NoVehiclesFound_Returns404(
            string ownerId,
            [Frozen] IVehicleService vehicleService,
            OwnersController sut)
        {
            vehicleService.GetByOwnerAsync(Arg.Any <string>())
            .Returns((IEnumerable <VehicleViewModel>)null);

            var result = (await sut.GetVehicles(ownerId)) as NotFoundObjectResult;

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status404NotFound);
            var errorInfo = result.Value as ErrorInfo;

            errorInfo.Should().NotBeNull();
            errorInfo.Type.Should().Be(ErrorType.InvalidOperation);
            errorInfo.Messages.Should().BeEquivalentTo($"No vehicles found for ownerId {ownerId}.");
        }