public async Task UpdateAsync_GroupNotExists_DatabaseIsNotLoadedNorSaved() { IAppDbContext database = A.Fake <IAppDbContext>(); TasksGroupRepository tasksGroupRepository = new TasksGroupRepository(database, NullLogger <TasksGroupRepository> .Instance); await tasksGroupRepository.UpdateAsync(A.Fake <ITasksGroup>()).ConfigureAwait(false); A.CallTo(() => database.LoadDatabase()).MustNotHaveHappened(); A.CallTo(() => database.SaveCurrentDatabase()).MustNotHaveHappened(); }
public async Task ListAsync_DatabaseIsLoadedOnceAndNoteSaved() { IAppDbContext database = A.Fake <IAppDbContext>(); TasksGroupRepository tasksGroupRepository = new TasksGroupRepository(database, NullLogger <TasksGroupRepository> .Instance); await tasksGroupRepository.ListAsync().ConfigureAwait(false); A.CallTo(() => database.LoadDatabase()).MustHaveHappenedOnceExactly(); A.CallTo(() => database.SaveCurrentDatabase()).MustNotHaveHappened(); }
public async Task UpdateAsync_DatabaseNotLoadedButSavedOnce() { IAppDbContext database = A.Fake <IAppDbContext>(); WorkTaskRepository workTaskRepository = new WorkTaskRepository(database, NullLogger <WorkTaskRepository> .Instance); await workTaskRepository.UpdateAsync(A.Fake <IWorkTask>()).ConfigureAwait(false); A.CallTo(() => database.LoadDatabase()).MustNotHaveHappened(); A.CallTo(() => database.SaveCurrentDatabase()).MustHaveHappenedOnceExactly(); }
public async Task FindAsync_DatabaseIsLoadedOnceAndNoteSaved() { IAppDbContext database = A.Fake <IAppDbContext>(); WorkTaskRepository workTaskRepository = new WorkTaskRepository(database, NullLogger <WorkTaskRepository> .Instance); await workTaskRepository.FindAsync("group1").ConfigureAwait(false); A.CallTo(() => database.LoadDatabase()).MustHaveHappenedOnceExactly(); A.CallTo(() => database.SaveCurrentDatabase()).MustNotHaveHappened(); }
public async Task <IEnumerable <IWorkTask> > ListAsync() { await mDatabase.LoadDatabase().ConfigureAwait(false); List <IWorkTask> allTasks = new List <IWorkTask>(); foreach (ITasksGroup taskGroup in mDatabase.Entities) { allTasks.AddRange(taskGroup.GetAllTasks()); } return(allTasks); }
public async Task <bool> AddAsync(ITasksGroup newGroup) { await mDatabase.LoadDatabase().ConfigureAwait(false); if (mDatabase.Entities.Contains(newGroup) || (mDatabase.Entities.Find(entity => entity.ID == newGroup.ID) != null)) { mLogger.LogError($"Group ID: {newGroup.ID} is already found in database"); return(false); } if (mDatabase.Entities.Find(entity => entity.Name == newGroup.Name) != null) { mLogger.LogError($"Group name: {newGroup.Name} is already found in database"); return(false); } mDatabase.Entities.Add(newGroup); await mDatabase.SaveCurrentDatabase().ConfigureAwait(false); return(true); }
public async Task RemoveAsync_GroupExists_DatabaseIsLoadedAndSavedOnce() { IAppDbContext database = A.Fake <IAppDbContext>(); TasksGroupRepository tasksGroupRepository = new TasksGroupRepository(database, NullLogger <TasksGroupRepository> .Instance); ITasksGroup tasksGroup = mTasksGroupFactory.CreateGroup("group1"); database.Entities.Add(tasksGroup); await tasksGroupRepository.RemoveAsync(tasksGroup).ConfigureAwait(false); A.CallTo(() => database.LoadDatabase()).MustNotHaveHappened(); A.CallTo(() => database.SaveCurrentDatabase()).MustHaveHappenedOnceExactly(); }