public async Task UpdateAsync_EmptyGroup_UpdatePerformed() { ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("emptyGroup"); IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(tasksGroup.ID)).Returns(tasksGroup); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, "newGroupName").ConfigureAwait(false); A.CallTo(() => dbRepository.UpdateAsync(A <ITasksGroup> .Ignored)).MustHaveHappenedOnceExactly(); }
public async Task UpdateAsync_GroupWithInvalidName_UpdateNotPerformed() { ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("group"); IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(tasksGroup.ID)).Returns(tasksGroup); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, mInvalidGroupName).ConfigureAwait(false); A.CallTo(() => dbRepository.UpdateAsync(A <ITasksGroup> .Ignored)).MustNotHaveHappened(); }
public async Task UpdateAsync_IdNotExists_UpdateNotPerformed() { const string wrongID = "wrongID"; IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(wrongID)).Returns <ITasksGroup>(null); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); await tasksGroupService.UpdateGroupAsync(wrongID, "newGroupName").ConfigureAwait(false); A.CallTo(() => dbRepository.UpdateAsync(A <ITasksGroup> .Ignored)).MustNotHaveHappened(); }
public async Task UpdateAsync_EmptyGroup_SuccessResponseReturned() { ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("emptyGroup"); IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(tasksGroup.ID)).Returns(tasksGroup); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); IResponse <ITasksGroup> response = await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, "newGroupName").ConfigureAwait(false); Assert.True(response.IsSuccess); Assert.Equal(tasksGroup, response.ResponseObject); }
public async Task UpdateAsync_GroupWithInvalidName_FailResponseReturned() { ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("group"); IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(tasksGroup.ID)).Returns(tasksGroup); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); IResponse <ITasksGroup> response = await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, mInvalidGroupName).ConfigureAwait(false); Assert.False(response.IsSuccess); Assert.Null(response.ResponseObject); }
public async Task UpdateAsync_IdNotExists_FailResponseReturned() { const string wrongID = "wrongID"; IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(wrongID)).Returns <ITasksGroup>(null); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); IResponse <ITasksGroup> response = await tasksGroupService.UpdateGroupAsync(wrongID, "newGroupName").ConfigureAwait(false); Assert.False(response.IsSuccess); Assert.Null(response.ResponseObject); }
public async Task UpdateAsync_GroupAlreadyExistingWithNewName_UpdateNotPerformed() { const string groupName = "groupName"; ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup(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 <ITasksGroup> response = await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, groupName).ConfigureAwait(false); A.CallTo(() => dbRepository.UpdateAsync(A <ITasksGroup> .Ignored)).MustNotHaveHappened(); }
public async Task UpdateAsync_GroupAlreadyExistingWithNewName_FailResponseReturned() { const string groupName = "groupName"; ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup(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 <ITasksGroup> response = await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, groupName).ConfigureAwait(false); Assert.False(response.IsSuccess); Assert.Null(response.ResponseObject); }
public async Task UpdateAsync_GroupWithChildren_ValidNewGrupNameGiven_ChildrenUpdatedWithNewGroupName() { const string oldGroupName = "oldGroupName"; const string newGroupName = "newGroupName"; ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup(oldGroupName); IWorkTask workTask1 = mTasksGroupFactory.CreateTask(tasksGroup, "workTask1"); IWorkTask workTask2 = mTasksGroupFactory.CreateTask(tasksGroup, "workTask2"); IDbRepository <ITasksGroup> dbRepository = A.Fake <IDbRepository <ITasksGroup> >(); A.CallTo(() => dbRepository.FindAsync(tasksGroup.ID)).Returns(tasksGroup); TasksGroupService tasksGroupService = new TasksGroupService(dbRepository, mTasksGroupFactory, NullLogger <TasksGroupService> .Instance); await tasksGroupService.UpdateGroupAsync(tasksGroup.ID, newGroupName).ConfigureAwait(false); Assert.Equal(newGroupName, workTask1.GroupName); Assert.Equal(newGroupName, workTask2.GroupName); }