public async Task <IActionResult> Post([FromBody] CreateFlightModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var id = Guid.NewGuid(); var command = new CreateFlightCommand { Id = id, DeparturePoint = model.DeparturePoint, DepartureTime = model.DepartureTime, Destination = model.Destination, Number = model.Number, TicketsId = model.TicketsId, TimeOfArrival = model.TimeOfArrival }; await _commandBus.ExecuteAsync(command); return(Ok()); }
public GenericCommandResult Create( [FromBody] CreateFlightCommand command, [FromServices] FlightHandler handler ) { return((GenericCommandResult)handler.Handle(command)); }
public async Task Put([FromBody] ClubFlightModel value) { CreateFlightCommand createFlightCommand = new CreateFlightCommand(); createFlightCommand.ClubFlightModel = value; createFlightCommand.ClubId = 1; var result = _mediator.Send(createFlightCommand); }
public static Flight Map(this CreateFlightCommand command) { return(new Flight() { Destination = command.Destination, FlightNumber = command.FlightNumber, Origin = command.Origin, Status = FlightStatus.WaitingForBoarding }); }
public CreateFlightCommandTests() { _repositories = new Mock <IFlightRepositoryFacade>(); _repositories.Setup(x => x.GetAirport(It.IsAny <int>())).Returns(new Airport()); _repositories.Setup(x => x.GetAircraft(It.IsAny <int>())).Returns(new Aircraft()); _uow = new Mock <IUnitOfWork>(); _command = new CreateFlightCommand(_repositories.Object, _uow.Object); }
public async Task <IActionResult> CreateFlight( [FromServices] ICommandHandler <CreateFlightCommand, CreateFlightResult> commandHandler, [FromServices] IQueryHandler <GetFlightDetailsQuery, FlightDetails?> queryHandler, [FromServices] IMapper mapper, [FromBody] CreateFlightInputModel inputModel) { var command = new CreateFlightCommand(inputModel.Capacity); var result = await commandHandler.HandleAsync(command); return(result switch { CreateFlightResult.Created created => CreatedAtAction( nameof(GetFlightById), new { id = created.Id.Value }, null), });
public async Task Test1() { // Arrange var flights = new List <Flight>() { new Flight() { Id = 1, Passengers = new List <Passenger>(), FlightRoute = new FlightRoute("London", "Paris"), Plane = new Plane(), } }; var repositoryMock = new Mock <IFlightRepository>(); List <Flight> matchObj = new List <Flight>(); repositoryMock.Setup(x => x.ScheduleFlightsAsync(It.IsAny <List <Flight> >())).Callback <List <Flight> >((obj) => matchObj.AddRange(obj)); var sut = new CreateFlightCommandHandler(repositoryMock.Object); // Act var request = new CreateFlightCommand() { }; var result = await sut.Handle(request, CancellationToken.None); // Assert repositoryMock.Verify(x => x.ScheduleFlightsAsync(It.IsAny <List <Flight> >()), Times.Once()); Assert.Equal(flights.First().Id, matchObj.First().Id); Assert.Empty(matchObj.First().Passengers); Assert.Equal(flights.First().FlightRoute.Origin, matchObj.First().FlightRoute.Origin); Assert.Equal(flights.First().FlightRoute.Destination, matchObj.First().FlightRoute.Destination); Assert.IsType <Plane>(matchObj.First().Plane); Assert.Equal(Unit.Value, result); }
public async Task <IActionResult> CreateFlight([FromBody] CreateFlightCommand command) => Ok((await m_Mediator.Send(command)));