Exemplo n.º 1
0
            public void IdentityKey_UsingReturnValue()
            {
                Person p = new Person
                               {
                                   FirstName = "FirstName",
                                   LastName = "LastName",
                                   DateCreated = DateTime.Now,
                                   Active = true
                               };
                Db.Insert(p);
                DateTime start = DateTime.Now;
                List<int> ids = new List<int>();
                for (int i = 0; i < cnt; i++)
                {
                    Person p2 = new Person
                                    {
                                        FirstName = "FirstName" + i,
                                        LastName = "LastName" + i,
                                        DateCreated = DateTime.Now,
                                        Active = true
                                    };
                    var id = Db.Insert(p2);
                    ids.Add(id);
                }

                double total = DateTime.Now.Subtract(start).TotalMilliseconds;
                Console.WriteLine("Total Time:" + total);
                Console.WriteLine("Average Time:" + total / cnt);
            }
Exemplo n.º 2
0
 public void AddsEntityToDatabase_ReturnsKey()
 {
     Person p = new Person { Active = true, FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
     int id = Db.Insert(p);
     Assert.AreEqual(1, id);
     Assert.AreEqual(1, p.Id);
 }
            public void Eq_EnumerableType_GeneratesAndRunsProperSql()
            {
                Person p1 = new Person { Active = true, FirstName = "Alpha", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = true, FirstName = "Beta", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = true, FirstName = "Gamma", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Impl.Insert<Person>(Connection, new[] { p1, p2, p3 }, null, null);

                var predicate = Predicates.Field<Person>(p => p.FirstName, Operator.Eq, new[] { "Alpha", "Gamma" });
                var result = Impl.GetList<Person>(Connection, predicate, null, null, null, true);
                Assert.AreEqual(2, result.Count());
                Assert.IsTrue(result.Any(r => r.FirstName == "Alpha"));
                Assert.IsTrue(result.Any(r => r.FirstName == "Gamma"));
            }
            public void Between_GeneratesAndRunsProperSql()
            {
                Person p1 = new Person { Active = true, FirstName = "Alpha", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = true, FirstName = "Beta", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = true, FirstName = "Gamma", LastName = "Omega", DateCreated = DateTime.UtcNow };
                Impl.Insert<Person>(Connection, new[] { p1, p2, p3 }, null, null);

                var pred = Predicates.Between<Person>(p => p.LastName,
                                                      new BetweenValues { Value1 = "Aaa", Value2 = "Bzz" });
                var result = Impl.GetList<Person>(Connection, pred, null, null, null, true).ToList();
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual("Alpha", result[0].FirstName);
                Assert.AreEqual("Beta", result[1].FirstName);
            }
Exemplo n.º 5
0
            public void UsingKey_ReturnsEntity()
            {
                Person p1 = new Person
                                {
                                    Active = true,
                                    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);
            }
            public void Exists_GeneratesAndRunsProperSql()
            {
                Person p1 = new Person { Active = true, FirstName = "Alpha", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = true, FirstName = "Beta", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = true, FirstName = "Gamma", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Impl.Insert<Person>(Connection, new[] { p1, p2, p3 }, null, null);

                Animal a1 = new Animal { Name = "Gamma" };
                Animal a2 = new Animal { Name = "Beta" };
                Impl.Insert<Animal>(Connection, new[] { a1, a2 }, null, null);

                var subPredicate = Predicates.Property<Person, Animal>(p => p.FirstName, Operator.Eq, a => a.Name);
                var predicate = Predicates.Exists<Animal>(subPredicate);

                var result = Impl.GetList<Person>(Connection, predicate, null, null, null, true);
                Assert.AreEqual(2, result.Count());
                Assert.IsTrue(result.Any(r => r.FirstName == "Beta"));
                Assert.IsTrue(result.Any(r => r.FirstName == "Gamma"));
            }
Exemplo n.º 7
0
            public void UsingKey_DeletesFromDatabase()
            {
                Person p1 = new Person
                                {
                                    Active = true,
                                    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));
            }
Exemplo n.º 8
0
            public void UsingKey_UpdatesEntity()
            {
                Person p1 = new Person
                                {
                                    Active = true,
                                    FirstName = "Foo",
                                    LastName = "Bar",
                                    DateCreated = DateTime.UtcNow
                                };
                int id = Db.Insert(p1);

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

                Db.Update(p2);

                var p3 = Db.Get<Person>(id);
                Assert.AreEqual("Baz", p3.FirstName);
                Assert.AreEqual("Bar", p3.LastName);
                Assert.AreEqual(false, p3.Active);
            }
Exemplo n.º 9
0
            public void UsingObject_DeletesRows()
            {
                Person p1 = new Person { Active = true, FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = true, FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = true, 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());
            }
Exemplo n.º 10
0
            public void UsingPredicate_DeletesRows()
            {
                Person p1 = new Person { Active = true, FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p2 = new Person { Active = true, FirstName = "Foo", LastName = "Bar", DateCreated = DateTime.UtcNow };
                Person p3 = new Person { Active = true, 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());
            }