Ejemplo n.º 1
0
            public void UsingObject_DeletesRows()
            {
                Person p1 = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow
                };
                Person p2 = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow
                };
                Person p3 = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Barz", DateCreated = DateTime.UtcNow
                };

                Db.Insert(p1);
                Db.Insert(p2);
                Db.Insert(p3);

                var list = Db.GetList <Person>();

                Assert.AreEqual(3, list.Count());

                var result = Db.Delete <Person>(new { LastName = "Bar" });

                Assert.IsTrue(result);

                list = Db.GetList <Person>();
                Assert.AreEqual(1, list.Count());
            }
Ejemplo n.º 2
0
            public void UsingPredicate_DeletesRows()
            {
                Person p1 = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow
                };
                Person p2 = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow
                };
                Person p3 = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Barz", DateCreated = DateTime.UtcNow
                };

                Db.Insert(p1);
                Db.Insert(p2);
                Db.Insert(p3);

                var list = Db.GetList <Person>();

                Assert.AreEqual(3, list.Count());

                IPredicate pred   = Predicates.Field <Person>(p => p.LastName, Operator.Eq, "Bar");
                var        result = Db.Delete <Person>(pred);

                Assert.IsTrue(result);

                list = Db.GetList <Person>();
                Assert.AreEqual(1, list.Count());
            }
Ejemplo n.º 3
0
            public void AddsEntityToDatabase_ReturnsKey()
            {
                Person p = new Person {
                    Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow
                };
                var id = Db.Insert(p);

                Assert.AreEqual(1, id);
                Assert.AreEqual(1, p.Id);
            }
Ejemplo n.º 4
0
            public void UsingKey_DeletesFromDatabase()
            {
                Person p1 = new Person
                {
                    Active      = "Y",
                    FirstName   = "Foo",
                    LastName    = "Bar",
                    DateCreated = DateTime.UtcNow
                };
                var id = Db.Insert(p1);

                Person p2 = Db.Get <Person>(id);

                Db.Delete(p2);
                Assert.IsNull(Db.Get <Person>(id));
            }
Ejemplo n.º 5
0
            public void UsingKey_ReturnsEntity()
            {
                Person p1 = new Person
                {
                    Active      = "Y",
                    FirstName   = "Foo",
                    LastName    = "Bar",
                    DateCreated = DateTime.UtcNow
                };
                var id = Db.Insert(p1);

                Person p2 = Db.Get <Person>(id);

                Assert.AreEqual(id, p2.Id);
                Assert.AreEqual("Foo", p2.FirstName);
                Assert.AreEqual("Bar", p2.LastName);
            }
Ejemplo n.º 6
0
            public void UsingKey_UpdatesEntity()
            {
                Person p1 = new Person
                {
                    Active      = "Y",
                    FirstName   = "Foo",
                    LastName    = "Bar",
                    DateCreated = DateTime.UtcNow
                };
                var id = Db.Insert(p1);

                var p2 = Db.Get <Person>(id);

                p2.FirstName = "Baz";
                p2.Active    = "N";

                Db.Update(p2);

                var p3 = Db.Get <Person>(id);

                Assert.AreEqual("Baz", p3.FirstName);
                Assert.AreEqual("Bar", p3.LastName);
                Assert.AreEqual("N", p3.Active);
            }
Ejemplo n.º 7
0
            public void UsingKey_DeletesFromDatabase()
            {
                Person p1 = new Person
                {
                    Active = "Y",
                    FirstName = "Foo",
                    LastName = "Bar",
                    DateCreated = DateTime.UtcNow
                };
                int id = Db.Insert(p1);

                Person p2 = Db.Get<Person>(id);
                Db.Delete(p2);
                Assert.IsNull(Db.Get<Person>(id));
            }
Ejemplo n.º 8
0
            public void UsingKey_UpdatesEntity()
            {
                Person p1 = new Person
                {
                    Active = "Y",
                    FirstName = "Foo",
                    LastName = "Bar",
                    DateCreated = DateTime.UtcNow
                };
                int id = Db.Insert(p1);

                var p2 = Db.Get<Person>(id);
                p2.FirstName = "Baz";
                p2.Active = "N";

                Db.Update(p2);

                var p3 = Db.Get<Person>(id);
                Assert.AreEqual("Baz", p3.FirstName);
                Assert.AreEqual("Bar", p3.LastName);
                Assert.AreEqual("N", p3.Active);
            }
Ejemplo n.º 9
0
 public void AddsEntityToDatabase_ReturnsKey()
 {
     Person p = new Person { Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
     int id = Db.Insert(p);
     Assert.AreEqual(1, id);
     Assert.AreEqual(1, p.Id);
 }
Ejemplo n.º 10
0
            public void UsingKey_ReturnsEntity()
            {
                Person p1 = new Person
                {
                    Active = "Y",
                    FirstName = "Foo",
                    LastName = "Bar",
                    DateCreated = DateTime.UtcNow
                };
                int id = Db.Insert(p1);

                Person p2 = Db.Get<Person>(id);
                Assert.AreEqual(id, p2.Id);
                Assert.AreEqual("Foo", p2.FirstName);
                Assert.AreEqual("Bar", p2.LastName);
            }
Ejemplo n.º 11
0
            public void UsingPredicate_DeletesRows()
            {
                Person p1 = new Person { Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = "Y", FirstName = "Foo", LastName = "Barz", DateCreated = DateTime.UtcNow };
                Db.Insert(p1);
                Db.Insert(p2);
                Db.Insert(p3);

                var list = Db.GetList<Person>();
                Assert.AreEqual(3, list.Count());

                IPredicate pred = Predicates.Field<Person>(p => p.LastName, Operator.Eq, "Bar");
                var result = Db.Delete<Person>(pred);
                Assert.IsTrue(result);

                list = Db.GetList<Person>();
                Assert.AreEqual(1, list.Count());
            }
Ejemplo n.º 12
0
            public void UsingObject_DeletesRows()
            {
                Person p1 = new Person { Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = "Y", FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = "Y", FirstName = "Foo", LastName = "Barz", DateCreated = DateTime.UtcNow };
                Db.Insert(p1);
                Db.Insert(p2);
                Db.Insert(p3);

                var list = Db.GetList<Person>();
                Assert.AreEqual(3, list.Count());

                var result = Db.Delete<Person>(new { LastName = "Bar" });
                Assert.IsTrue(result);

                list = Db.GetList<Person>();
                Assert.AreEqual(1, list.Count());
            }