Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
 public void ReadFromNewTable()
 {
     var db = new FakeDB();
     Assert.AreEqual("()", db.Read("foosums", new { a = "b" }).Print());
 }
Exemplo n.º 9
0
 public void ReadAllFromNewTable()
 {
     var db = new FakeDB();
     Assert.AreEqual("()", db.ReadAll("foosums").Print());
 }
Exemplo n.º 10
0
        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"]);
        }
Exemplo n.º 11
0
 public FakeDBTransaction(FakeDB db)
 {
     _db = db;
     _operations = new List<Op>();
 }