public async System.Threading.Tasks.Task InsertEntryCommandHandler_Success() { //Given var phoneBook = new PhoneBookAggregateRoot { Name = _phoneBookName }; var entryName = "TestUser"; var entryPhoneNumber = "0817810008"; await _phoneBookRepositoryMock.AddAsync(phoneBook); var insertEntryCommandHandler = new InsertEntryCommandHandler(_phoneBookRepositoryMock); var insertEntryCommand = new InsertEntryCommand { Name = entryName, PhoneNumber = entryPhoneNumber, PhoneBookId = phoneBook.Id }; //When await insertEntryCommandHandler.HandleAsync(insertEntryCommand); //Then var entry = ((PhoneBookRepositoryMock)_phoneBookRepositoryMock).phoneBookAggregates.FirstOrDefault().Entries.FirstOrDefault(); Assert.NotNull(entry); Assert.Equal(entryName, entry.Name); Assert.Equal(entryPhoneNumber, entry.PhoneNumber); }
public async Task <IActionResult> InsectEntryAsync([FromBody] InsertEntryDto insertEntryDto) { var command = new InsertEntryCommand { PhoneBookId = insertEntryDto.PhoneBookId, PhoneNumber = insertEntryDto.PhoneNumber, Name = insertEntryDto.Name }; await _mediator.DispatchAsync(command); return(Ok()); }
public async System.Threading.Tasks.Task InsertEntryCommandHandler_Fail() { var entryName = "TestUser"; var entryPhoneNumber = "0817810008"; var phoneBook = new PhoneBookAggregateRoot { Name = _phoneBookName }; phoneBook.InsertEntry(entryName, entryPhoneNumber); await _phoneBookRepositoryMock.AddAsync(phoneBook); var insertEntryCommandHandler = new InsertEntryCommandHandler(_phoneBookRepositoryMock); var insertEntryCommand = new InsertEntryCommand { Name = entryName, PhoneNumber = entryPhoneNumber, PhoneBookId = phoneBook.Id }; await Assert.ThrowsAsync <ValidateException>(() => insertEntryCommandHandler.HandleAsync(insertEntryCommand)); }