public async Task <IActionResult> AddChild(AddChildVM child) { if (!ModelState.IsValid) { return(InvalidChildToAdd(child)); } var addedChild = await _manager.AddChildForUser(child.FirstName, child.LastName, UserId); var childVM = ChildToVM(addedChild); return(Ok(childVM)); }
public async Task AddChild_should_return_badRequest_if_childToAdd_isnt_valid() { // Given var childToAdd = new AddChildVM { FirstName = "Adam", LastName = null }; SUT.ModelState.AddModelError("LastName", "Last name required"); // When var result = await SUT.AddChild(childToAdd); // Then EarlyLearningAssert.HttpResultIsBadRequest("Invalid child", result); }
public async Task AddChild_should_return_child_from_manager() { // Given var childToAdd = new AddChildVM { FirstName = "Adam", LastName = "Smith" }; var child = _testFactory.NewChild("Adam", "Smith"); _manager.Setup(x => x.AddChildForUser("Adam", "Smith", _testFactory.CurrentUser.UserId)) .ReturnsAsync(child); // When var result = await SUT.AddChild(childToAdd); // Then EarlyLearningAssert.HttpResultIsOk(result); EarlyLearningAssert.AreEqual(child, EarlyLearningAssert.DataInResult <ChildVM>(result)); }
private IActionResult InvalidChildToAdd(AddChildVM child) { Logger.ForContext("Child", child).Information("Tried to add invalid child"); return(BadRequest("Invalid child")); }