public async Task ShouldFailToSetUncompletedTwice()
        {
            Guid profileId = Guid.NewGuid();

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

            goals.First().SetCompleted(DateTime.Now, "Completado para testes");

            SetUncompletedGoalCommand command = new SetUncompletedGoalCommand
            {
                GoalId = goals.FirstOrDefault().Id
            };

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

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

            Assert.IsTrue(commandResult.Success);
            Assert.IsFalse(goals.First().Status.IsCompleted);

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

            Assert.IsFalse(commandResultTwo.Success);
            Assert.AreEqual("Esse objetivo já está marcado como incompleto.", commandResultTwo.Notifications.FirstOrDefault().Description);
        }
        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);
        }
        public async Task ShouldFailToSetGoalUncompletedIdNotFound()
        {
            Guid profileId = Guid.NewGuid();

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

            goals.First().SetCompleted(DateTime.Now, "Completado para testes");

            SetUncompletedGoalCommand command = new SetUncompletedGoalCommand
            {
                GoalId = Guid.NewGuid()
            };

            GoalFakeRepository goalFakeRepository = new GoalFakeRepository(goals);
            GoalCommandHandler handler            = new GoalCommandHandler(
                goalFakeRepository,
                GetIdentityService(profileId),
                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);
        }
        public async Task ShouldSetCompleted()
        {
            Guid profileId = Guid.NewGuid();

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

            SetCompletedGoalCommand command = new SetCompletedGoalCommand
            {
                GoalId = goals.FirstOrDefault().Id,
                AccomplishmentDetails = "Ëu completei !!!!",
                DateCompleted         = DateTime.Now
            };

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

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

            Assert.IsTrue(commandResult.Success);
            Assert.IsTrue(goals.First().Status.IsCompleted);
        }
        public async Task ShouldFailToRemoveGoalUserNotOwner()
        {
            List <Goal> goals = new List <Goal>
            {
                new Goal(Guid.NewGuid(), "Novo para teste", "Testando")
            };

            RemoveGoalCommand command = new RemoveGoalCommand
            {
                GoalId = goals.First().Id
            };

            GoalFakeRepository goalFakeRepository = new GoalFakeRepository(goals);
            GoalCommandHandler handler            = new GoalCommandHandler(
                goalFakeRepository,
                GetIdentityService(),
                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);
        }
        public async Task ShouldRemoveGoal()
        {
            Guid profileId = Guid.NewGuid();

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

            RemoveGoalCommand command = new RemoveGoalCommand
            {
                GoalId = goals.First().Id
            };

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

            Assert.AreEqual(1, goalFakeRepository._goals.Count);

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

            Assert.IsTrue(commandResult.Success);
            Assert.AreEqual(0, goalFakeRepository._goals.Count);
        }
        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);
        }
        public async Task ShouldFailToRemoveGoalIdNotFound()
        {
            RemoveGoalCommand command = new RemoveGoalCommand
            {
                GoalId = Guid.NewGuid()
            };

            GoalFakeRepository goalFakeRepository = new GoalFakeRepository();
            GoalCommandHandler handler            = new GoalCommandHandler(
                goalFakeRepository,
                GetIdentityService(),
                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);
        }
        public async Task ShouldRegisterGoal()
        {
            RegisterGoalCommand command = new RegisterGoalCommand
            {
                Title     = "Testes de Goal",
                Details   = "Registrando um goal para testes unitários",
                WritePost = false
            };

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

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

            Assert.IsTrue(commandResult.Success);
            Assert.AreEqual(1, goalFakeRepository._goals.Count);
        }