public void Update_When_stewardesseDto_is_null_Then_throw_NullBodyException() { StewardesseDto nullDto = null; int id = 1; Assert.Throws <NullBodyException>(() => _service.Update(id, nullDto)); }
public void Add_When_stewardesseModel_is_not_valid_Then_throw_ValidationException() { var notValidDto = new StewardesseDto { FirstName = "A", LastName = "Karenina", Birthdate = new DateTime(1991, 9, 12) }; Assert.Throws <ValidationException>(() => _service.Add(notValidDto)); }
public void Update_When_id_is_not_exist_Then_throw_NotExistException() { var validDto = new StewardesseDto { FirstName = "Anna", LastName = "Karenina", Birthdate = new DateTime(1991, 9, 12) }; int notExistId = 2; Assert.Throws <NotExistException>(() => _service.Update(notExistId, validDto)); }
public void Update_When_stewardesseModel_is_not_valid_and_id_is_exist_Then_throw_ValidationException() { var notValidDto = new StewardesseDto { FirstName = "Anna", LastName = "", Birthdate = new DateTime(1991, 9, 12) }; int existId = 3; Assert.Throws <ValidationException>(() => _service.Update(existId, notValidDto)); }
public void Add_When_stewardesseModel_is_valid_Then_return_created_model_id() { var validDto = new StewardesseDto { FirstName = "Anna", LastName = "Karenina", Birthdate = new DateTime(1991, 9, 12) }; var result = _service.Add(validDto); Assert.AreEqual(result, 1); }
public void Update_When_stewardesseModel_is_valid_and_id_is_exist_Then_call_Update_method() { var validDto = new StewardesseDto { FirstName = "Anna", LastName = "Karenina", Birthdate = new DateTime(1991, 9, 12) }; int existId = 3; _service.Update(existId, validDto); A.CallTo(() => _repository.Update(A <int> ._, A <Stewardesse> ._)).MustHaveHappened(); }
public IActionResult Post([FromBody] StewardesseDto dto) { try { var createdId = _stewardessesService.Add(dto); return(CreatedAtAction("Get", _stewardessesService.GetById(createdId))); } catch (ValidationException ex) { return(BadRequest(ex.Errors)); } catch (NullBodyException) { return(BadRequest()); } }
public IActionResult Put(int id, [FromBody] StewardesseDto dto) { try { _stewardessesService.Update(id, dto); return(Ok()); } catch (NotExistException) { return(NotFound()); } catch (ValidationException ex) { return(BadRequest(ex.Errors)); } catch (NullBodyException) { return(BadRequest()); } }
public async Task <IActionResult> Post([FromBody] StewardesseDto dto) { try { var createdId = await _stewardessesService.AddAsync(dto); return(CreatedAtAction("Get", await _stewardessesService.GetByIdAsync(createdId))); } catch (ValidationException ex) { return(BadRequest(ex.Errors)); } catch (NullBodyException) { return(BadRequest()); } catch (DbUpdateException ex) { return(BadRequest(ex.InnerException.Message)); } }
public void Add_When_stewardesseDto_is_null_Then_throw_NullBodyException() { StewardesseDto nullDto = null; Assert.Throws <NullBodyException>(() => _service.Add(nullDto)); }