コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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();
        }