示例#1
0
        public async Task <IActionResult> Create([FromBody] CreatePhoneBook command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _dispatcher.SendAsync(command);

            return(Ok());
        }
        public async Task CreatePhoneBookSuccessReturnOkResult()
        {
            var command = new CreatePhoneBook {
                Name = "Jasur", Phone = "+998998431129"
            };

            var result = _controller.Create(command);

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

            Assert.IsType <OkResult>(result.Result);
        }
        public async Task CreatePhoneBookFailModelStateReturnBadRequest()
        {
            var command = new CreatePhoneBook {
                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.Create(command);

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

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
 public async Task <ActionResult <long> > CreatePhoneBook(CreatePhoneBook command)
 {
     return(await Mediator.Send(command));
 }