public void AlternarStatusTarefa_TarefaNaoEncontrada_DeveDarErro() { // Act var mock = new Mock <ITarefaRepository>(); mock.Setup(x => x.ObterPorId(Guid.NewGuid())).Returns <object>(null); var service = new TarefaService(mock.Object, _mapper.Object); // Assert Assert.ThrowsAsync <Exception>(() => service.Alternar(Guid.NewGuid())); }
public async Task AlternarStatusTarefa_AlternarTarefaComSucesso() { // Arrange var id = Guid.NewGuid(); var tarefa = new Tarefa(Guid.NewGuid(), "xxx", DateTime.Now, Guid.NewGuid()); // Act var mock = new Mock <ITarefaRepository>(); mock.Setup(x => x.ObterPorId(id)).Returns(Task.FromResult(tarefa)); mock.Setup(c => c.Alternar(tarefa)); mock.Setup(c => c.UnitOfWork.Commit()).Returns(Task.FromResult(true)); var service = new TarefaService(mock.Object, _mapper.Object); var alternar = await service.Alternar(id); // Assert Assert.True(alternar); }