public TaskCategoryEntity UpdateCategory(TaskCategoryEntity category)
        {
            var findCategory = FindCategoryById(category.Id);

            _dbContext.Entry(findCategory).CurrentValues.SetValues(category);
            Save();
            return(findCategory);
        }
Beispiel #2
0
        public void UpdateCategory_CannotUpdateIfItDoesntExist_ReturnObjectNotFoundException()
        {
            // Arrange
            var category = new TaskCategoryEntity()
            {
                Id       = "Guid 1",
                DateTime = DateTime.Now,
                Title    = "Daily",
            };

            ITaskCategoryRepository repository = new TaskCategoryRepository();

            // Act
            repository.UpdateCategory(category);
        }
Beispiel #3
0
        public void AddCategory_CanAddValidCategory_ReturnCategory()
        {
            // Arrange
            var category = new TaskCategoryEntity()
            {
                Id       = "Guid 1",
                DateTime = DateTime.Now,
                Title    = "Daily",
            };

            ITaskCategoryRepository repository = new TaskCategoryRepository();

            // Act
            var result = repository.AddCategory(category);

            repository.DeleteCategoryById(category.Id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(category, result);
        }
        public void SortTasksByCategory_CanSortByCategoryTitle_ReturnTasks()
        {
            // Arrange
            var category = new TaskCategoryEntity()
            {
                Id       = "Guid 1",
                DateTime = DateTime.Now,
                Title    = "Daily",
            };

            var taskEntity = new TaskEntity
            {
                Id           = "Guid1",
                Completeness = false,
                DateTime     = DateTime.Now,
                Description  = "Description",
                Name         = "Name",
                Category     = category,
            };

            ITaskRepository         taskRepository         = new TaskRepository();
            ITaskCategoryRepository taskCategoryRepository = new TaskCategoryRepository();

            taskRepository.AddTask(taskEntity);


            // Act
            var result = taskRepository.SortTasksByCategory(taskEntity.Category.Title);

            // Assert
            Assert.IsNotNull(result);

            Assert.AreEqual(taskEntity, result.FirstOrDefault(t => t.Name == taskEntity.Name));

            taskRepository.DeleteTaskById(taskEntity.Id);
            taskCategoryRepository.DeleteCategoryById(category.Id);
        }
 public TaskCategoryEntity AddCategory(TaskCategoryEntity category)
 {
     _dbContext.TaskCategories.Add(category);
     Save();
     return(category);
 }