示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
 private IActionResult InvalidChildToAdd(AddChildVM child)
 {
     Logger.ForContext("Child", child).Information("Tried to add invalid child");
     return(BadRequest("Invalid child"));
 }