public override async Task SaveAsync(TodoTask entity)
        {
            if (entity.TaskID.HasValue)
            {
                TodoTask inDatabaseTodoTask = await _context.TodoTasks.FindAsync(entity);

                inDatabaseTodoTask.LoadFrom(entity);
            }
            else
            {
                _context.TodoTasks.Add(entity);
            }
            await _context.SaveChangesAsync();
        }
Пример #2
0
        public void TaskEntityTest()
        {
            // Arrange
            TodoTask todoTask = new TodoTask {
                TaskID      = 1,
                TaskName    = "Task Testing",
                Description = "Testing this task",
                Colour      = "red",
                ListID      = 1
            };

            TodoTask todoTaskLoadFrom = new TodoTask {
                TaskID      = 2,
                TaskName    = "Task Loading Testing",
                Description = "Testing this method",
                Colour      = "chrysochlorous",
                ListID      = 1
            };

            TodoTask todoTaskLoadTo = new TodoTask();

            // Act
            todoTaskLoadTo.LoadFrom(todoTaskLoadFrom);
            todoTaskLoadFrom.LoadFrom(new TodoTask());

            // Assert
            Assert.IsNotNull(todoTask);
            Assert.AreEqual(todoTask.TaskID, 1);
            Assert.AreEqual(todoTask.ListID, 1);
            Assert.AreEqual(todoTask.TaskName, "Task Testing");
            Assert.AreEqual(todoTask.Description, "Testing this task");
            Assert.AreEqual(todoTask.Colour, "red");
            Assert.IsNull(todoTask.ParentList);

            Assert.IsNotNull(todoTaskLoadTo);
            Assert.AreEqual(todoTaskLoadTo.TaskName, "Task Loading Testing");
            Assert.AreEqual(todoTaskLoadTo.Description, "Testing this method");
            Assert.AreEqual(todoTaskLoadTo.Colour, "chrysochlorous");
            Assert.IsNull(todoTaskLoadTo.ParentList);

            Assert.IsNull(todoTaskLoadFrom.TaskName);
            Assert.IsNull(todoTaskLoadFrom.Description);
            Assert.IsNull(todoTaskLoadFrom.Colour);
            Assert.IsNull(todoTaskLoadFrom.ParentList);
        }