public async Task UpdateTaskAsync_TaskExists_TaskUpdated()
        {
            IWorkTask taskToUpdate = A.Fake <IWorkTask>();

            A.CallTo(() => taskToUpdate.Description).Returns("some-description");
            A.CallTo(() => taskToUpdate.ID).Returns("some-id");

            ITasksGroup tasksGroup = A.Fake <ITasksGroup>();
            OperationResult <IWorkTask> getTaskResult = new OperationResult <IWorkTask>(true, taskToUpdate);

            A.CallTo(() => tasksGroup.GetTask(A <string> .Ignored)).Returns(getTaskResult);

            IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >();

            A.CallTo(() => dbRepository.ListAsync()).Returns(new List <ITasksGroup>()
            {
                tasksGroup
            });
            TasksGroupService tasksGroupService =
                new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance);

            await tasksGroupService.UpdateTaskAsync(
                new WorkTaskResource
            {
                TaskId      = taskToUpdate.ID,
                Description = taskToUpdate.Description
            }).ConfigureAwait(false);

            A.CallTo(() => dbRepository.UpdateAsync(tasksGroup)).MustHaveHappenedOnceExactly();
        }
        public async Task UpdateTaskAsync_TaskExists_SuccessResponseReturned()
        {
            IWorkTask taskToUpdate = A.Fake <IWorkTask>();

            A.CallTo(() => taskToUpdate.Description).Returns("some-description");
            A.CallTo(() => taskToUpdate.ID).Returns("some-id");

            ITasksGroup tasksGroup = A.Fake <ITasksGroup>();
            OperationResult <IWorkTask> getTaskResult = new OperationResult <IWorkTask>(true, taskToUpdate);

            A.CallTo(() => tasksGroup.GetTask(A <string> .Ignored)).Returns(getTaskResult);

            IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >();

            A.CallTo(() => dbRepository.ListAsync()).Returns(new List <ITasksGroup>()
            {
                tasksGroup
            });

            TasksGroupService tasksGroupService =
                new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance);

            IResponse <IWorkTask> response = await tasksGroupService.UpdateTaskAsync(
                new WorkTaskResource
            {
                TaskId      = taskToUpdate.ID,
                Description = taskToUpdate.Description
            }).ConfigureAwait(false);

            Assert.True(response.IsSuccess);
            Assert.Equal(taskToUpdate, response.ResponseObject);
        }
        public async Task UpdateTaskAsync_WorkTaskNotExists_UpdateNotPerformed()
        {
            IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >();

            A.CallTo(() => dbRepository.ListAsync()).Returns(new List <ITasksGroup>());

            TasksGroupService tasksGroupService =
                new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance);

            IResponse <IWorkTask> response = await tasksGroupService.UpdateTaskAsync(
                new WorkTaskResource
            {
                TaskId      = "notExistingId",
                Description = "some-description"
            }).ConfigureAwait(false);

            A.CallTo(() => dbRepository.UpdateAsync(A <ITasksGroup> .Ignored)).MustNotHaveHappened();
        }
        public async Task UpdateTaskAsync_WorkTaskNotExists_FailResponseReturned()
        {
            IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >();

            A.CallTo(() => dbRepository.ListAsync()).Returns(new List <ITasksGroup>());

            TasksGroupService tasksGroupService =
                new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance);

            IResponse <IWorkTask> response = await tasksGroupService.UpdateTaskAsync(
                new WorkTaskResource
            {
                TaskId      = "notExistingId",
                Description = "some-description"
            }).ConfigureAwait(false);

            Assert.False(response.IsSuccess);
            Assert.Null(response.ResponseObject);
        }
        public async Task UpdateTaskAsync_DescriptionAlreadyExist_FailResponseReturnedAndUpdateNotPerformed()
        {
            IWorkTask taskToUpdate = A.Fake <IWorkTask>();

            A.CallTo(() => taskToUpdate.Description).Returns("same-description");
            A.CallTo(() => taskToUpdate.ID).Returns("some-id");

            IWorkTask taskWithSameDescription = A.Fake <IWorkTask>();

            A.CallTo(() => taskWithSameDescription.Description).Returns("same-description");

            ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("group-name");

            mTasksGroupFactory.CreateTask(tasksGroup, "same-description");
            mTasksGroupFactory.CreateTask(tasksGroup, "same-description");

            IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >();

            A.CallTo(() => dbRepository.ListAsync()).Returns(new List <ITasksGroup>()
            {
                tasksGroup
            });

            TasksGroupService tasksGroupService =
                new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance);

            IResponse <IWorkTask> response = await tasksGroupService.UpdateTaskAsync(
                new WorkTaskResource
            {
                TaskId      = taskToUpdate.ID,
                Description = taskWithSameDescription.Description
            }).ConfigureAwait(false);

            Assert.False(response.IsSuccess);
            Assert.Null(response.ResponseObject);

            A.CallTo(() => dbRepository.UpdateAsync(tasksGroup)).MustNotHaveHappened();
        }