コード例 #1
0
        public void UpdateListItem_InvalidId()
        {
            // Arrange
            var testListItem = new TodoListItemModel()
            {
                TodoListItemId = 2,
                Name           = _fixture.Create <string>(),
                Description    = _fixture.Create <string>(),
                Completed      = _fixture.Create <bool>()
            };

            AddListItems(1);

            var todoListManager = new TodoListManager(_mockConfiguration.Object);

            // Act
            todoListManager.UpdateListItem(testListItem);

            // Assert
            var updatedItem = todoListManager.GetListItems().First();

            Assert.AreNotEqual(testListItem.Name, updatedItem.Name);
            Assert.AreNotEqual(testListItem.Description, updatedItem.Description);
            Assert.AreNotEqual(testListItem.Completed, updatedItem.Completed);
        }
コード例 #2
0
        public void UpdateListItem(TodoListItemModel updatedListItem)
        {
            using (var connection = new SqliteConnection(_connectionString))
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = @"UPDATE todo_list SET name = $name, description = $description, completed = $complete
                    WHERE todo_list_item_id = $id";

                command.Parameters.AddWithValue("$id", updatedListItem.TodoListItemId);
                command.Parameters.AddWithValue("$name", updatedListItem.Name);
                command.Parameters.AddWithValue("$description", updatedListItem.Description);
                command.Parameters.AddWithValue("$complete", updatedListItem.Completed ? 1 : 0);

                command.ExecuteNonQuery();
            }
        }
コード例 #3
0
        public void AddListItem(TodoListItemModel listItem)
        {
            if (listItem == null)
            {
                return;
            }

            using (var connection = new SqliteConnection(_connectionString))
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = @"INSERT INTO todo_list (name, description, completed) VALUES($name, $description, $complete);";

                command.Parameters.AddWithValue("$name", listItem.Name == null ? "" : listItem.Name);
                command.Parameters.AddWithValue("$description", listItem.Description);
                command.Parameters.AddWithValue("$complete", listItem.Completed ? 1 : 0);

                command.ExecuteNonQuery();
            }
        }
コード例 #4
0
        public void AddListItem_Success()
        {
            // Arrange
            var testListItem = new TodoListItemModel()
            {
                Name        = _fixture.Create <string>(),
                Description = _fixture.Create <string>(),
                Completed   = _fixture.Create <bool>()
            };

            var todoListManager = new TodoListManager(_mockConfiguration.Object);

            // Act
            todoListManager.AddListItem(testListItem);

            // Assert
            var insertedItem = todoListManager.GetListItems().First();

            Assert.IsNotNull(insertedItem);
            Assert.AreEqual(testListItem.Name, insertedItem.Name);
            Assert.AreEqual(testListItem.Description, insertedItem.Description);
            Assert.AreEqual(testListItem.Completed, insertedItem.Completed);
        }
コード例 #5
0
 public void Update(int id, TodoListItemModel listItem)
 {
     listItem.TodoListItemId = id; // Parameter ID takes precedence over the one in the object
     _todoListManager.UpdateListItem(listItem);
 }
コード例 #6
0
 public void Add(TodoListItemModel listItem)
 {
     _todoListManager.AddListItem(listItem);
 }