Skip to content

Instantly share code, notes, and snippets.

@yareally
Last active August 29, 2015 14:00
Show Gist options
  • Save yareally/f7521dbda4d37d7c6d7f to your computer and use it in GitHub Desktop.
Save yareally/f7521dbda4d37d7c6d7f to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Helpers.Storage;
using UnityEngine;
namespace Test
{
using NUnit.Framework;
[TestFixture]
public class SQLiteTests : MonoBehaviour {
private const string DB_NAME = "test.db";
private const string TBL_NAME = "test_tbl";
private SQLiteHelper dbh;
private enum ColNames {
id = 0,
name = 1,
value = 2
}
public SQLiteTests()
{
dbh = new SQLiteHelper(DB_NAME);
}
[SetUp]
public void Init()
{
}
[Test]
public void createTableTest()
{
dbh.dropTable(TBL_NAME);
var colNames = new[] { ColNames.id.ToString(), ColNames.name.ToString(), ColNames.value.ToString() };
var colTypes = new[] { SQLiteTypes.INTEGER, SQLiteTypes.TEXT, SQLiteTypes.TEXT };
var result = dbh.createTable(TBL_NAME, colNames, colTypes);
Assert.AreEqual(0, result);
}
[Test]
public void insertRecordTest()
{
var insertResult = dbh.insert(TBL_NAME,
new[] { ColNames.name.ToString(), ColNames.value.ToString(), },
new[] { "test", "test value" });
Assert.AreEqual(1, insertResult);
var query = string.Format("SELECT * FROM {0} WHERE {1} = '{2}' LIMIT 1", TBL_NAME, ColNames.name, "test");
var queryResult = dbh.rawQuery(query);
Assert.AreEqual("test", queryResult.GetValue(Convert.ToInt32(ColNames.name)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment