Skip to content

Instantly share code, notes, and snippets.

@markrendle
Created October 12, 2012 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markrendle/3879476 to your computer and use it in GitHub Desktop.
Save markrendle/3879476 to your computer and use it in GitHub Desktop.
Tests for Simple.Data + Impromptu
[TestFixture]
public class CustomerTest
{
[Test]
public void TestInsert()
{
var db = DatabaseFactory.Create();
var customer = db.Customers.Insert(name: "Megadodo", location: "Ursa Minor Beta");
Assert.AreEqual(1, customer.Id);
Assert.AreEqual("Megadodo", customer.Name);
Assert.AreEqual("Ursa Minor Beta", customer.Location);
}
[Test]
public void TestGet()
{
var db = DatabaseFactory.Create();
db.Customers.Insert(name: "Megadodo", location: "Ursa Minor Beta");
var customer = db.Customers.Get(1);
Assert.AreEqual(1, customer.Id);
Assert.AreEqual("Megadodo", customer.Name);
Assert.AreEqual("Ursa Minor Beta", customer.Location);
}
[Test]
public void TestLazyLoadDetail()
{
var db = DatabaseFactory.Create();
var customer = db.Customers.Insert(name: "Megadodo", location: "Ursa Minor Beta");
db.Employees.Insert(name: "Ford Prefect", employerId: customer.Id);
db.Employees.Insert(name: "Zarniwoop", employerId: customer.Id);
customer = db.Customers.Get(customer.Id);
Assert.AreEqual(2, customer.Employees.Count);
// Make sure we get the same list every time we access the property
customer.Employees.RemoveAt(0);
Assert.AreEqual(1, customer.Employees.Count);
}
[Test]
public void TestLazyLoadMaster()
{
var db = DatabaseFactory.Create();
var customer = db.Customers.Insert(name: "Megadodo", location: "Ursa Minor Beta");
var employee = db.Employees.Insert(name: "Ford Prefect", employerId: customer.Id);
Assert.AreEqual("Megadodo", employee.Employer.Name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment