public void IncrementsPKs() { var db = new FakeDB(); var data = new { Z = "A" }; 2.Times(() => db.Insert("Foosums", data)); Assert.AreEqual("(([FoosumsId,1],[Z,A]),([FoosumsId,2],[Z,A]))", db.Table("Foosums").Print()); }
public void Instantiate() { var db = new FakeDB(); var data = new { F = 1, B = 2 }; var key = db.Insert("tbl", data); Assert.NotNull(key); Assert.NotNull(db); }
public void DoesntRepeatAutoKeys() { var db = new FakeDB(); var data = new { Z = "A" }; 2.Times(() => db.Insert("P", data)); db.Delete("P", new { PId = 2 }); db.Insert("P", new {Z = "B"}); Assert.AreEqual("(([PId,1],[Z,A]),([PId,3],[Z,B]))", db.Table("P").Print()); }
public void InsertPK() { var db = new FakeDB(); var data = new { Filename = "foosums", Created = DateTime.Now }; var key = db.Insert("Investment.PNImport", data); var fromDb = db.ReadPK("Investment.PNImport", key); Assert.AreEqual(1, fromDb["PNImportId"]); Assert.AreEqual(data._AsDictionary().Assoc("PNImportId", 1).Print(), fromDb.Print()); }
public void UpdateWorks() { var db = new FakeDB(); var data = new { Z = "A" }; db.Insert("Foosums", data); var keys = db.Insert("Foosums", data); // Now, we'll update the second row, and the first should remain unchanged db.Update("Foosums", keys.Assoc("Z", "B")); Assert.AreEqual("(([FoosumsId,1],[Z,A]),([FoosumsId,2],[Z,B]))", db.Table("Foosums").Print()); }
public void ReadTCanSetFieldsFromNullForDictionaryBasedTypes() { var db = new FakeDB(); var row = new Dictionary<string,object>{{"Name", "foosums"}}; db.Insert("test", row); // Previously, the way we did this was to write this as: // obj = db.ReadAll("test").Select(r => new DictBasedTestObject()._SetFrom(r)).Single(); var obj = db.Read<DictBasedTestObject>("test", row).Single(); Assert.NotNull(obj); Assert.False(obj.IsSet); Assert.AreEqual("foosums", obj.Name); }
public void Ensure() { var db = new FakeDB(); var data = new { MyTableId = 1, Foo = "bar"}; // This should do an insert db.Ensure("MyTable", data); Assert.AreEqual("(([Foo,bar],[MyTableId,1]))", db.Table("MyTable").Print()); var newData = new { MyTableId = 1, Foo = "sums" }; // This should do an update db.Ensure("MyTable", newData); Assert.AreEqual("(([Foo,sums],[MyTableId,1]))", db.Table("MyTable").Print()); }
public void ReadFromNewTable() { var db = new FakeDB(); Assert.AreEqual("()", db.Read("foosums", new { a = "b" }).Print()); }
public void ReadAllFromNewTable() { var db = new FakeDB(); Assert.AreEqual("()", db.ReadAll("foosums").Print()); }
public void TreatsNullsAndDbNullsTheSame() { var db = new FakeDB(); var rows = new object[]{ new { Age = DBNull.Value }, new Person() { Age = null } }; var ids = rows.Select(r => db.InsertAutoKey("Person", r)).ToList(); var fromDb = db.Read("Person", new { Age = DBNull.Value }); Assert.AreEqual(2, fromDb.Count()); Assert.AreEqual(fromDb.First()["Age"], fromDb.Second()["Age"]); }
public FakeDBTransaction(FakeDB db) { _db = db; _operations = new List<Op>(); }