public async Task ShouldFailToRemoveReminderUserNotOwner() { Guid profileId = Guid.NewGuid(); List <Reminder> reminders = new List <Reminder> { new Reminder(profileId, true, "Novo para teste", "Testando", new Time(9, 0, 0)) }; RemoveReminderCommand command = new RemoveReminderCommand { ReminderId = reminders.First().Id }; ReminderFakeRepository reminderFakeRepository = new ReminderFakeRepository(reminders); ReminderCommandHandler handler = new ReminderCommandHandler( reminderFakeRepository, GetMapper(), GetIdentityService(), GetMediator(), GetUnitOfWork(), GetLogger() ); CommandResult commandResult = await handler.Handle(command, default(CancellationToken)); Assert.IsFalse(commandResult.Success); Assert.AreEqual("Falha ao buscar Lembrete no banco de dados.", commandResult.Notifications.FirstOrDefault().Description); }
public async Task ShouldRemoveReminder() { Guid profileId = Guid.NewGuid(); List <Reminder> reminders = new List <Reminder> { new Reminder(profileId, true, "Novo para teste", "Testando", new Time(9, 0, 0)) }; RemoveReminderCommand command = new RemoveReminderCommand { ReminderId = reminders.First().Id }; ReminderFakeRepository reminderFakeRepository = new ReminderFakeRepository(reminders); ReminderCommandHandler handler = new ReminderCommandHandler( reminderFakeRepository, GetMapper(), GetIdentityService(profileId), GetMediator(), GetUnitOfWork(), GetLogger() ); Assert.AreEqual(1, reminderFakeRepository._reminders.Count); CommandResult commandResult = await handler.Handle(command, default(CancellationToken)); Assert.IsTrue(commandResult.Success); Assert.AreEqual(0, reminderFakeRepository._reminders.Count); }
public async Task <IActionResult> RemoveAsync(Guid id) { RemoveReminderCommand command = new RemoveReminderCommand { ReminderId = id }; return(await CreateCommandResponse(command)); }
public async Task <CommandResult> Handle(RemoveReminderCommand request, CancellationToken cancellationToken) { Reminder reminder = await _reminderRepository.GetByIdAsync(request.ReminderId); if (!FoundValidGoal(reminder)) { return(FailureDueToReminderNotFound()); } await _reminderRepository.RemoveAsync(reminder); return(await CommitAndPublishDefaultAsync()); }
public async Task ShouldFailToRemoveReminderIdNotFound() { RemoveReminderCommand command = new RemoveReminderCommand { ReminderId = Guid.NewGuid() }; ReminderFakeRepository reminderFakeRepository = new ReminderFakeRepository(); ReminderCommandHandler handler = new ReminderCommandHandler( reminderFakeRepository, GetMapper(), GetIdentityService(), GetMediator(), GetUnitOfWork(), GetLogger() ); CommandResult commandResult = await handler.Handle(command, default(CancellationToken)); Assert.IsFalse(commandResult.Success); Assert.AreEqual("Falha ao buscar Lembrete no banco de dados.", commandResult.Notifications.FirstOrDefault().Description); }