public void HandleCommand_ThrowsNotFoundException_ForUnknownCarId() { var command = new CreateRideshareCommand() { StartLocation = "Zagreb", EndLocation = "Osijek", StartDate = new DateTime(2020, 10, 1, 8, 0, 0), EndDate = new DateTime(2020, 10, 1, 14, 0, 0), Car = new CreateRideshareCommand.SubCar { Id = 999 }, Employees = new List <CreateRideshareCommand.SubEmployee>() { new CreateRideshareCommand.SubEmployee { Id = 1 }, new CreateRideshareCommand.SubEmployee { Id = 2 }, new CreateRideshareCommand.SubEmployee { Id = 3 }, new CreateRideshareCommand.SubEmployee { Id = 4 } } }; var handler = new CreateRideshareCommandHandler(Context); Should.Throw <NotFoundException>(async() => { var result = await handler.Handle(command, CancellationToken.None); }); }
public void HandleCommand_ThrowsInvalidDateException_ForOccupiedTravelPeriodWithSpecifiedCar() { var command = new CreateRideshareCommand() { StartLocation = "Zagreb", EndLocation = "Osijek", StartDate = new DateTime(2020, 10, 2, 16, 0, 0), EndDate = new DateTime(2020, 10, 2, 23, 0, 0), Car = new CreateRideshareCommand.SubCar { Id = 1 }, Employees = new List <CreateRideshareCommand.SubEmployee>() { new CreateRideshareCommand.SubEmployee { Id = 1 }, new CreateRideshareCommand.SubEmployee { Id = 2 }, new CreateRideshareCommand.SubEmployee { Id = 3 }, new CreateRideshareCommand.SubEmployee { Id = 4 } } }; var handler = new CreateRideshareCommandHandler(Context); Should.Throw <InvalidDateException>(async() => { var result = await handler.Handle(command, CancellationToken.None); }) .Message.ShouldBe(InvalidDateMessageEnum.TravelPeriodTaken.ToDescriptionString()); }
public async Task ReturnsSuccessCode_ForValidCreateRideshareCommand() { var client = _factory.GetClient(); var command = new CreateRideshareCommand { StartLocation = "Zagreb", EndLocation = "Osijek", StartDate = new DateTime(2020, 10, 1, 8, 0, 0), EndDate = new DateTime(2020, 10, 1, 14, 0, 0), Car = new CreateRideshareCommand.SubCar { Id = 1 }, Employees = new List <CreateRideshareCommand.SubEmployee>() { new CreateRideshareCommand.SubEmployee { Id = 1 }, new CreateRideshareCommand.SubEmployee { Id = 2 }, new CreateRideshareCommand.SubEmployee { Id = 3 }, new CreateRideshareCommand.SubEmployee { Id = 4 } } }; var content = TestHelper.GetRequestContent(command); var response = await client.PostAsync($"/api/rideshares", content); response.EnsureSuccessStatusCode(); }
public async Task HandleCommand_ShouldPersistRideshare() { var command = new CreateRideshareCommand() { StartLocation = "Zagreb", EndLocation = "Osijek", StartDate = new DateTime(2020, 10, 1, 8, 0, 0), EndDate = new DateTime(2020, 10, 1, 14, 0, 0), Car = new CreateRideshareCommand.SubCar { Id = 1 }, Employees = new List <CreateRideshareCommand.SubEmployee>() { new CreateRideshareCommand.SubEmployee { Id = 1 }, new CreateRideshareCommand.SubEmployee { Id = 2 }, new CreateRideshareCommand.SubEmployee { Id = 3 }, new CreateRideshareCommand.SubEmployee { Id = 4 } } }; var handler = new CreateRideshareCommandHandler(Context); var result = await handler.Handle(command, CancellationToken.None); var entity = Context.Rideshares.Find(result); entity.ShouldNotBeNull(); entity.StartLocation.ShouldBe(command.StartLocation); entity.EndLocation.ShouldBe(command.EndLocation); entity.StartDate.ShouldBe(command.StartDate); entity.EndDate.ShouldBe(command.EndDate); entity.Car.Id.ShouldBe(command.Car.Id); entity.EmployeeRideshares.Count.ShouldBe(4); var employeeRideshares = Context.EmployeeRideshares.Where(er => er.RideshareId == entity.Id).ToList(); employeeRideshares.ShouldNotBeNull(); employeeRideshares.Count.ShouldBe(4); }
public async Task <IActionResult> Create([FromBody] CreateRideshareCommand command) { var rideshareId = await Mediator.Send(command); return(Ok(rideshareId)); }