コード例 #1
0
        public async Task ShouldUpdateGoal()
        {
            Guid profileId = Guid.NewGuid();

            List <Goal> goals = new List <Goal>
            {
                new Goal(profileId, "Novo para teste", "Testando")
            };

            UpdateGoalCommand command = new UpdateGoalCommand
            {
                GoalId    = goals.First().Id,
                Title     = "Testes de Goal",
                Details   = "Registrando um goal para testes unitários",
                WritePost = false
            };

            GoalFakeRepository goalFakeRepository = new GoalFakeRepository(goals);
            GoalCommandHandler handler            = new GoalCommandHandler(
                goalFakeRepository,
                GetIdentityService(profileId),
                GetMediator(),
                GetUnitOfWork(),
                GetLogger()
                );

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

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

            Assert.AreEqual("Testes de Goal", goals.First().Title);
            Assert.IsTrue(commandResult.Success);
        }
コード例 #2
0
        public async Task ShouldFailToUpdateGoalUserNotOwner()
        {
            Guid profileId = Guid.NewGuid();

            List <Goal> goals = new List <Goal>
            {
                new Goal(profileId, "Novo para teste", "Testando")
            };

            UpdateGoalCommand command = new UpdateGoalCommand
            {
                GoalId    = goals.First().Id,
                Title     = "Testes de Goal",
                Details   = "Registrando um goal para testes unitários",
                WritePost = false
            };

            GoalFakeRepository goalFakeRepository = new GoalFakeRepository(goals);
            GoalCommandHandler handler            = new GoalCommandHandler(
                goalFakeRepository,
                GetIdentityService(null),
                GetMediator(),
                GetUnitOfWork(),
                GetLogger()
                );

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

            Assert.IsFalse(commandResult.Success);
            Assert.AreEqual("Falha ao buscar Objetivo no banco de dados.", commandResult.Notifications.FirstOrDefault().Description);
        }
コード例 #3
0
        public async Task <IActionResult> UpdateGoalAsync(Guid id, UpdateGoalCommand updateGoalCommand)
        {
            if (!Guid.TryParse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value, out Guid userId))
            {
                return(Unauthorized());
            }

            updateGoalCommand.Id = id;
            var hasBeenUpdated = await _mediator.Send(updateGoalCommand);

            return(NoContent());
        }
コード例 #4
0
 public GoalsController(AllGoalsQuery allGoalsQuery,
                        UserGoalsQuery userGoalsQuery,
                        GoalQuery goalQuery,
                        CreateGoalCommand createGoalCommand,
                        UpdateGoalCommand updateGoalCommand,
                        DeleteGoalCommand deleteGoalCommand,
                        CompleteGoalCommand completeGoalCommand)
 {
     this.allGoalsQuery       = allGoalsQuery;
     this.userGoalsQuery      = userGoalsQuery;
     this.goalQuery           = goalQuery;
     this.createGoalCommand   = createGoalCommand;
     this.updateGoalCommand   = updateGoalCommand;
     this.deleteGoalCommand   = deleteGoalCommand;
     this.completeGoalCommand = completeGoalCommand;
 }
コード例 #5
0
        public async Task <CommandResult> Handle(UpdateGoalCommand request, CancellationToken cancellationToken)
        {
            Goal goal = await _goalRepository.GetByIdAsync(request.GoalId);

            if (!FoundValidGoal(goal))
            {
                return(FailureDueToGoalNotFound());
            }

            goal.Update(
                request.Title,
                request.Details
                );

            await _goalRepository.UpdateAsync(goal);

            return(await CommitAndPublishDefaultAsync());
        }
コード例 #6
0
ファイル: CustomerCommandHandler.cs プロジェクト: thild/koos
        public async Task <bool> Handle(UpdateGoalCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(false);
            }

            var goal = new Goal(message.Description,
                                message.Reward,
                                message.StarsToAchieve,
                                message.StarsEarned,
                                message.StartDate,
                                message.EndDate);

            var existingGoal = _goalRepository.GetById(goal.Id);

            if (existingGoal != null && existingGoal.Id != goal.Id)
            {
                if (!existingGoal.Equals(goal))
                {
                    await Bus.RaiseEvent(new DomainNotification(message.MessageType, "The Goal e-mail has already been taken."));

                    return(false);
                }
            }

            _goalRepository.Update(goal);

            if (await Commit())
            {
                await Bus.RaiseEvent(new GoalUpdatedEvent(goal.Id,
                                                          goal.Description,
                                                          goal.Reward,
                                                          goal.StarsToAchieve,
                                                          goal.StarsEarned,
                                                          goal.StartDate,
                                                          goal.EndDate));
            }

            return(true);
        }
コード例 #7
0
        public async Task <IActionResult> UpdateAsync(Guid id, [FromBody] UpdateGoalCommand command)
        {
            command.GoalId = id;

            return(await CreateCommandResponse(command));
        }