public async Task DeleteAsync_Exists_False() { //Arrange _roleRepositoryMock.Setup(m => m.ExistsAsync(It.IsAny <int>())).Returns(() => Task.FromResult(true)); _roleRepositoryMock.Setup(m => m.DeleteAsync(It.IsAny <int>())).Returns(() => Task.FromResult(0)); RoleBusiness roleBusiness = new RoleBusiness(_roleRepositoryMock.Object); //Act bool result = await roleBusiness.DeleteAsync(Role.Id); //Assert Assert.True(result); }
public async Task DeleteAsync_LessThanOrEqualToZero_False(int id) { //Arrange _roleRepositoryMock.Setup(m => m.ExistsAsync(It.IsAny <int>())).Returns(() => Task.FromResult(false)); _roleRepositoryMock.Setup(m => m.DeleteAsync(It.IsAny <int>())).Returns(() => Task.FromResult(0)); RoleBusiness roleBusiness = new RoleBusiness(_roleRepositoryMock.Object); //Act bool result = await roleBusiness.DeleteAsync(id); //Assert Assert.False(result); }
public async Task <ActionResult> Delete(int id) { try { if (await _roleBusiness.DeleteAsync(id)) { return(Ok()); } return(NotFound()); } catch (Exception ex) { _logger.LogError(ex, "Ocorreu um erro ao deletar o usuário"); return(StatusCode(500, $"Ocorreu um erro ao deletar o usuário. Id: {id}")); } }