public async Task SaveTaskAsync_ValidWorkTaskToAdd_SuccessResponseReturnedAndSavePerformed()
        {
            IWorkTask validWorkTask = A.Fake <IWorkTask>();

            validWorkTask.GroupName   = "groupName";
            validWorkTask.Description = "validDescription";

            ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("bla");

            tasksGroup.SetGroupName(validWorkTask.GroupName);

            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.SaveTaskAsync(validWorkTask.GroupName, validWorkTask.Description)
                .ConfigureAwait(false);

            Assert.True(response.IsSuccess);
            Assert.Equal(tasksGroup.GetAllTasks().First(), response.ResponseObject);
            A.CallTo(() => dbRepository.UpdateAsync(A <ITasksGroup> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public async Task SaveTaskAsync_DescriptionExistsInTheSameGroup_SaveNotPerformed()
        {
            IWorkTask workTask = A.Fake <IWorkTask>();

            workTask.GroupName   = "groupName";
            workTask.Description = "description";

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

            workTask.GroupName   = workTask.GroupName;
            workTask.Description = workTask.Description;

            ITasksGroup tasksGroup = A.Fake <ITasksGroup>();

            tasksGroup.SetGroupName(workTask.GroupName);
            A.CallTo(() => tasksGroup.GetAllTasks()).Returns(new List <IWorkTask> {
                workTask
            });

            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.SaveTaskAsync(workTask.GroupName, workTask.Description).ConfigureAwait(false);

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

            workTask.GroupName   = "groupName";
            workTask.Description = "description";

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

            workTask.GroupName   = workTask.GroupName;
            workTask.Description = workTask.Description;

            ITasksGroup tasksGroup = A.Fake <ITasksGroup>();

            tasksGroup.SetGroupName(workTask.GroupName);
            A.CallTo(() => tasksGroup.GetAllTasks()).Returns(new List <IWorkTask> {
                workTask
            });

            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.SaveTaskAsync(workTask.GroupName, workTask.Description).ConfigureAwait(false);

            Assert.False(response.IsSuccess);
            Assert.Null(response.ResponseObject);
        }
        public async Task SaveTaskAsync_InvalidTaskName_FailResponseReturnedAndSaveNotPerformed()
        {
            const string groupName = "groupName";

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

            workTask.GroupName   = groupName;
            workTask.Description = mInvalidTaskName;
            OperationResult <IWorkTask> createTaskResult = new OperationResult <IWorkTask>(true, workTask);

            ITasksGroup tasksGroup = A.Fake <ITasksGroup>();

            tasksGroup.SetGroupName(groupName);

            A.CallTo(() => tasksGroup.CreateTask(A <string> .Ignored, A <string> .Ignored)).Returns(createTaskResult);

            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.SaveTaskAsync(workTask.GroupName, workTask.Description).ConfigureAwait(false);

            Assert.False(response.IsSuccess);
            Assert.Null(response.ResponseObject);
            A.CallTo(() => dbRepository.AddAsync(A <ITasksGroup> .Ignored)).MustNotHaveHappened();
        }
        public async Task SaveTaskAsync_GroupIdentifierNotExists_SaveNotPerformed()
        {
            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.SaveTaskAsync("notExistingGroupIdentifier", mInvalidTaskName).ConfigureAwait(false);

            A.CallTo(() => dbRepository.AddAsync(A <ITasksGroup> .Ignored)).MustNotHaveHappened();
        }
        public async Task SaveTaskAsync_GroupIdentifierNotExists_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.SaveTaskAsync("notExistingGroupIdentifier", mInvalidTaskName).ConfigureAwait(false);

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