public async Task <ActionResult> UpdatePhoneBook(long id, UpdatePhoneBook command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> Update([FromBody] UpdatePhoneBook command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _dispatcher.SendAsync(command);

            return(Ok());
        }
        public async Task UpdatePhoneBookSuccessReturnOkResult()
        {
            var command = new UpdatePhoneBook {
                Id = 4, Name = "Jasur", Phone = "+998998431129"
            };

            var result = _controller.Update(command);

            await _dispatcher.Received().SendAsync(Arg.Is <UpdatePhoneBook>(x => x != null));

            Assert.IsType <OkResult>(result.Result);
        }
        public async Task UpdatePhoneBookFailModelStateReturnBadRequest()
        {
            var command = new UpdatePhoneBook {
                Id = 4, Name = null, Phone = null
            };

            _controller.ModelState.AddModelError("Name", "The Name field is required.");
            _controller.ModelState.AddModelError("Phone", "The Phone field is required.");
            var result = _controller.Update(command);

            await _dispatcher.DidNotReceive().SendAsync(Arg.Is <UpdatePhoneBook>(x => x != null));

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }