public static async Task <IActionResult> RunPost( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "vehiculs")] HttpRequest req, ILogger log) { try { CreateVehiculCommand command = await ExtractCommandFromRequestBody(req); await _mediator.Send(command); return((ActionResult) new OkObjectResult($"Vehicul created.")); } catch (MicroserviceBarebone.Application.Exceptions.ValidationException e) { return((ActionResult) new BadRequestObjectResult(e.Failures)); } catch (Exception e) { return((ActionResult) new BadRequestObjectResult(e.Message)); } }
public async Task Shoud_Add_Vehicul_To_Repository() { #region Arrange var command = new CreateVehiculCommand() { VehiculId = Guid.NewGuid(), Label = "First One", Type = Domain.Enums.VehiculType.Car }; #endregion #region Act await _commandHandler.Handle(command, CancellationToken.None); #endregion #region Assert Assert.True(_vehiculs.Count(x => x.VehiculId == command.VehiculId && x.Label == command.Label && x.Type == command.Type) == 1); #endregion }