markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

Rollback not working #335

Open westonal opened 10 years ago

westonal commented 10 years ago

If I insert in a transaction and roll that transaction back I would expect that the table would be empty. Instead it is not. This affects InMemoryAdapter.

[TestClass]
public sealed class SimpleDataRollbackTest
{
    [TestInitialize]
    public void Setup()
    {
        Database.UseMockAdapter(new InMemoryAdapter());
    }

    [TestCleanup]
    public void TearDown()
    {
        Database.StopUsingMockAdapter();
    }

    [TestMethod]
    public void Rollback()
    {
        var db = Database.Open();
        Assert.AreEqual(0, db.MyTable.All().Count());
        using (var transaction = db.BeginTransaction())
        {
            transaction.MyTable.Insert(ID: 1);
            Assert.AreEqual(1, transaction.MyTable.All().Count());
            transaction.Rollback();
        }
        Assert.AreEqual(0, db.MyTable.All().Count());
    }
}
westonal commented 10 years ago

Initially I was not using the transaction correctly: db.MyTable.Insert(ID: 1); rather than transaction.MyTable.Insert(ID: 1); Now I do, it works with actual DB, but still not with in-memory, so updated the issue.