public async Task <IActionResult> AddNew([FromBody] AddNewPersonCommand addNewPersonCommand) { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(await _mediator.Send(addNewPersonCommand))); }
public async Task NewPersonShouldBeAddedAsync() { var handler = new AddNewPersonHandler(_personRepositoryMock.Object, _countryRepositoryMock.Object); var request = new AddNewPersonCommand { CountryId = 1 }; _countryRepositoryMock.Setup(x => x.GetById(It.IsAny <int>())).Returns(Task.FromResult(GetMockedCountry())); await handler.Handle(request, CancellationToken.None); _countryRepositoryMock.Verify(x => x.GetById(It.IsAny <int>())); _personRepositoryMock.Verify(x => x.Add(It.IsAny <Domain.Entities.Person>()), Times.Once); _personRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once); }