public void AddTravelSuccessfully() { Travel travel = new Travel( "Name", new DateTime(2019, 3, 10, 0, 0, 0), new DateTime(2019, 4, 10, 0, 0, 0), "Description", 5 ); Assert.NotZero(TravelRepository.AddTravel(travel)); }
public void AddTravel_RequiredAttributeException_WithoutDatetime() { Travel travel = new Travel( "", DateTime.MinValue, new DateTime(2019, 4, 10, 0, 0, 0), "Description", 5 ); Assert.Throws <RequiredAttributeException>( () => TravelRepository.AddTravel(travel)); }
public void AddTravel_UserNotFoundException() { Travel travel = new Travel( "Name", new DateTime(2019, 3, 10, 0, 0, 0), new DateTime(2019, 4, 10, 0, 0, 0), "Description", 200 ); Assert.Throws <UserNotFoundException>( () => TravelRepository.AddTravel(travel)); }
public IActionResult AddTravel([FromBody] Travel travel) { try{ int id = TravelRepository.AddTravel(travel); return(Ok(travel)); }catch (RequiredAttributeException ex) { return(StatusCode(400, ex.Message)); }catch (UserNotFoundException ex) { return(StatusCode(404, ex.Message)); }catch (InternalServerErrorException ex) { return(StatusCode(500, ex.Message)); }catch (Exception) { return(StatusCode(400)); } }