public async Task HandleAsync(DeleteCredentialTypeCommand message, CancellationToken token = default(CancellationToken)) { var type = await this.GetCredentialTypeAsync(message.CredentialTypeId, token); type.Delete(); _types.Delete(type); await _types.SaveChangesAsync(); }
public async Task ShouldDeleteExisting() { // Arrange CredentialType entity = CredentialType.Create(Guid.NewGuid(), "Name", "Code"); var repository = new Mock <ICredentialTypeRepository>(); repository.Setup(e => e.GetByIdAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(entity); DeleteCredentialTypeCommand cmd = new DeleteCredentialTypeCommand(entity.Id); CredentialTypeCommandHandler actual = new CredentialTypeCommandHandler(repository.Object); // Act await actual.HandleAsync(cmd); // Assert repository.Verify(e => e.Delete(It.Is <CredentialType>(a => a.Equals(entity))), Times.Once ); }