public void EnsureTaskCanBeAdded()
 {
     var name = new Guid().ToString("N");
     var task = new TaskItem(name);
     var repo = new TaskItemRepository(connectionString);
     var newId = repo.AddTask(task);
     Assert.IsTrue(newId > 0);
 }
        public void EnsureTaskIsCorrectlyAdded()
        {
            var name = new Guid().ToString("N");
            var task = new TaskItem(name);

            var repo = new TaskItemRepository(connectionString);
            var newId = repo.AddTask(task);

            var loadedTask = repo.GetTask(newId);

            Assert.IsNotNull(loadedTask);
            Assert.AreEqual(newId, loadedTask.Id);
            Assert.AreEqual(name, loadedTask.Name);
            Assert.AreEqual(false, loadedTask.IsComplete);
        }
        public int AddTask(TaskItem task)
        {
            using (var conn = new SqliteConnection(connectionString))
            using (var cmd = new SqliteCommand(@"
INSERT INTO [Tasks] (
    [Name], 
    [IsComplete]
) VALUES (
    @name,
    @complete
);
SELECT last_insert_rowid();", conn))
            {
                cmd.Parameters.AddWithValue("@name", task.Name);
                cmd.Parameters.AddWithValue("@complete", task.IsComplete);
                conn.Open();

                using (var trans = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {IsolationLevel = IsolationLevel.Serializable}))
                {
                    var result = cmd.ExecuteScalar();
                    trans.Complete();
                    return Convert.ToInt32(result);
                }
            }
        }
 private static TaskItem ReadTask(SqliteDataReader reader)
 {
     TaskItem task = new TaskItem
     {
         Id = Convert.ToInt32(reader["Id"]),
         Name = Convert.ToString(reader["Name"]),
         IsComplete = Convert.ToBoolean(reader["IsComplete"]),
     };
     return task;
 }
        public void UpdateTask(TaskItem task)
        {

        }