public async Task <IActionResult> PublishTravelPlan([FromQuery] PublishTravelPlanInput input) { try { using (var scope = _provider.CreateScope()) { var userService = scope.ServiceProvider.GetService <UserService>(); var travelPlan = new TravelPlan { Date = DateTime.Parse(input.Date), DepartureCityId = input.DepartureCityId, Description = input.Description, DestinationCityId = input.DestinationCityId, IsActive = true, SeatCount = input.SeatCount, UserTravelPlans = new List <UserTravelPlan>(), }; var plan = await userService.PublishTravelPlanAsync(input.UserId, travelPlan); var dto = new PublishTravelPlanDto(); if (plan == null) { dto.Status = false; dto.Message = "Couldn't publish travel plan"; return(BadRequest(dto)); } else { dto.Status = true; dto.Message = "Travel plan has been published"; return(Ok(dto)); } } } catch (Exception e) { return(StatusCode(500, new { Message = e.Message })); } }
public async void PublishTravelPlan_ReturnsBadRequest_WithoutAnyUsers() { // Arrange var input = new PublishTravelPlanInput { Date = DateTime.Now.ToString(), DepartureCityId = 1, Description = "Test", DestinationCityId = 2, SeatCount = 5, UserId = 1 }; string queryString = "Date={0}&DepartureCityId={1}&Description={2}&DestinationCityId={3}&SeatCount={4}&UserId={5}"; queryString = String.Format(queryString, input.Date, input.DepartureCityId, input.Description, input.DestinationCityId, input.SeatCount, input.UserId); // Act var response = await TestClient.PostAsync("/User/PublishTravelPlan?" + queryString, null); // body is null // Assert response.StatusCode.Should().Be(HttpStatusCode.BadRequest); }