Ejemplo n.º 1
0
        public async Task ShouldFailToUpdateReminderUserNotOwner()
        {
            Guid profileId = Guid.NewGuid();

            List <Reminder> reminders = new List <Reminder>
            {
                new Reminder(profileId, true, "Novo para teste", "Testando", new Time(9, 0, 0))
            };

            UpdateReminderCommand command = new UpdateReminderCommand
            {
                ReminderId = reminders.First().Id,
                Title      = "Testes de Reminder",
                Details    = "Registrando um Reminder para testes unitários",
            };

            ReminderFakeRepository reminderFakeReposiotry = new ReminderFakeRepository(reminders);
            ReminderCommandHandler handler = new ReminderCommandHandler(
                reminderFakeReposiotry,
                GetMapper(),
                GetIdentityService(null),
                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);
        }
Ejemplo n.º 2
0
        public async Task ShouldUpdateReminder()
        {
            Guid profileId = Guid.NewGuid();

            List <Reminder> reminders = new List <Reminder>
            {
                new Reminder(profileId, true, "Novo para teste", "Testando", new Time(9, 0, 0))
            };

            UpdateReminderCommand command = new UpdateReminderCommand
            {
                ReminderId = reminders.First().Id,
                Title      = "Testes de Reminder",
                Details    = "Updatando um Reminder para testes unitários",
            };

            ReminderFakeRepository reminderFakeRepository = new ReminderFakeRepository(reminders);
            ReminderCommandHandler handler = new ReminderCommandHandler(
                reminderFakeRepository,
                GetMapper(),
                GetIdentityService(profileId),
                GetMediator(),
                GetUnitOfWork(),
                GetLogger()
                );

            Assert.AreEqual("Novo para teste", reminders.First().Title);

            CommandResult commandResult = await handler.Handle(command, default(CancellationToken));

            Assert.AreEqual("Testes de Reminder", reminders.First().Title);
            Assert.IsTrue(commandResult.Success);
        }
Ejemplo n.º 3
0
        public async Task <CommandResult> Handle(UpdateReminderCommand request, CancellationToken cancellationToken)
        {
            Reminder reminder = await _reminderRepository.GetByIdAsync(request.ReminderId);

            if (!FoundValidGoal(reminder))
            {
                return(FailureDueToReminderNotFound());
            }

            reminder.Update(
                request.Active,
                request.Title,
                request.Details,
                _mapper.Map <Time>(request.TimeOfDay)
                );

            await _reminderRepository.UpdateAsync(reminder);

            return(await CommitAndPublishDefaultAsync());
        }
Ejemplo n.º 4
0
        public async Task ShouldFailToUpdateReminderIdNotFound()
        {
            UpdateReminderCommand command = new UpdateReminderCommand
            {
                ReminderId = Guid.NewGuid(),
                Title      = "Testes de Reminder",
                Details    = "Updatando um Reminder para testes unitários",
            };

            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);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> UpdateAsync(Guid id, [FromBody] UpdateReminderCommand command)
        {
            command.ReminderId = id;

            return(await CreateCommandResponse(command));
        }