public async Task UpdateListIdentityAsync()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                var q = new PersonIdentity {
                    FirstName = "Raj", LastName = "Padilla"
                };
                var r = new PersonIdentity {
                    FirstName = "Lidia", LastName = "Bain"
                };

                var lst = new List <PersonIdentity> {
                    p, q, r
                };

                Assert.True(await db.InsertListAsync(lst));

                p.FirstName = "Emily";
                q.FirstName = "Jim";
                r.FirstName = "Laura";

                Assert.True(await db.UpdateListAsync(lst));

                var gp = await db.GetAsync <PersonIdentity>(p.IdentityId);

                Assert.Equal("Emily", gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);
            }
        }
        public async Task UpdateListIdentityThrowsExceptionAsync()
        {
            Skip.If(GetProvider() == Provider.SQLite, "Sqlite doesn't enforce size limit");

            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                var q = new PersonIdentity {
                    FirstName = "Raj", LastName = "Padilla"
                };
                var r = new PersonIdentity {
                    FirstName = "Lidia", LastName = "Bain"
                };

                var lst = new List <PersonIdentity> {
                    p, q, r
                };

                Assert.True(await db.InsertListAsync(lst));

                p.FirstName = "Emily";
                q.FirstName = "a".PadRight(101, 'a');
                r.FirstName = "Laura";

                await Assert.ThrowsAnyAsync <Exception>(() => db.UpdateListAsync(lst));

                var gp = await db.GetAsync <PersonIdentity>(p.IdentityId);

                Assert.Equal("Alice", gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);
            }
        }
Пример #3
0
        public async Task DeleteIdentityAsync()
        {
            using (var db = GetSqlDatabase())
            {
                var pOther = new PersonIdentity {
                    FirstName = "OtherAliceAsync", LastName = "OtherJones"
                };
                var p = new PersonIdentity {
                    FirstName = "AliceAsync", LastName = "Jones"
                };
                Assert.True(await db.InsertAsync(p));
                Assert.True(p.IdentityId > 0);
                Assert.True(await db.InsertAsync(pOther));
                Assert.True(pOther.IdentityId > 0);

                Assert.True(await db.DeleteAsync <PersonIdentity>(p.IdentityId));

                var gp = await db.GetAsync(p);

                var gpOther = await db.GetAsync(pOther);

                Assert.Null(gp);
                Assert.NotNull(gpOther);
            }
        }
Пример #4
0
        public void NestedTransactionCommitInnerRollbackOuter()
        {
            //if (GetProvider() == Provider.SQLite) return;

            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                Assert.True(db.Insert(p));
                using (var tranOuter = db.GetTransaction())
                {
                    using (var tran = db.GetTransaction())
                    {
                        var gp = db.Get <PersonIdentity>(p.IdentityId);
                        gp.FirstName = "Sally";
                        db.Update(gp);
                        tran.Complete();
                    }
                }

                var agp = db.Get <PersonIdentity>(p.IdentityId);  //updates should have been rolled back
                Assert.Equal("Alice", agp.FirstName);
            }
        }
Пример #5
0
        public async Task DeleteWhereClauseAsync()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "DeleteAsync", LastName = "Me"
                };

                for (var i = 0; i < 10; i++)
                {
                    Assert.True(await db.InsertAsync(p));
                }
                var pOther = new PersonIdentity {
                    FirstName = "DeleteOtherAsync", LastName = "MeOther"
                };

                Assert.True(await db.InsertAsync(pOther));

                Assert.Equal(10, await db.CountAsync <PersonIdentity>("where FirstName = 'DeleteAsync'"));
                Assert.Equal(1, await db.CountAsync <PersonIdentity>("where FirstName = 'DeleteOtherAsync'"));

                Assert.True(await db.DeleteAsync <PersonIdentity>("where FirstName = 'DeleteAsync'"));

                Assert.Equal(0, await db.CountAsync <PersonIdentity>("where FirstName = 'DeleteAsync'"));
                //Ensure that this did not delete rows it shouldn't have from the database.
                Assert.Equal(1, await db.CountAsync <PersonIdentity>("where FirstName = 'DeleteOtherAsync'"));
            }
        }
Пример #6
0
        public void DeleteWhereClause()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Delete", LastName = "Me"
                };

                for (var i = 0; i < 10; i++)
                {
                    Assert.True(db.Insert(p));
                }
                var pOther = new PersonIdentity {
                    FirstName = "DeleteOther", LastName = "MeOther"
                };
                Assert.True(db.Insert(pOther));

                Assert.Equal(10, db.Count <PersonIdentity>("where FirstName = 'Delete'"));
                Assert.Equal(1, db.Count <PersonIdentity>("where FirstName = 'DeleteOther'"));

                Assert.True(db.Delete <PersonIdentity>("where FirstName = 'Delete'"));

                Assert.Equal(0, db.Count <PersonIdentity>("where FirstName = 'Delete'"));
                //Ensure that this did not delete rows it shouldn't have from the database.
                Assert.Equal(1, db.Count <PersonIdentity>("where FirstName = 'DeleteOther'"));
            }
        }
Пример #7
0
        public void InsertIdentity()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                Assert.True(db.Insert(p));
                Assert.True(p.IdentityId > 0);
                var gp = db.Get <PersonIdentity>(p.IdentityId);

                Assert.Equal(p.IdentityId, gp.IdentityId);
                Assert.Equal(p.FirstName, gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);
            }
        }
        public async Task InsertIdentityAsync()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                Assert.True(await db.InsertAsync(p));
                Assert.True(p.IdentityId > 0);
                var gp = await db.GetAsync <PersonIdentity>(p.IdentityId);

                Assert.Equal(p.IdentityId, gp.IdentityId);
                Assert.Equal(p.FirstName, gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);
            }
        }
Пример #9
0
        public void UpsertListIdentityThrowsException()
        {
            Skip.If(GetProvider() == Provider.SQLite, "Sqlite doesn't enforce size limit");

            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                var q = new PersonIdentity {
                    FirstName = "Raj", LastName = "Padilla"
                };
                var r = new PersonIdentity {
                    FirstName = "Lidia", LastName = "Bain"
                };
                var s = new PersonIdentity {
                    FirstName = "Derren", LastName = "Southern"
                };

                var lst = new List <PersonIdentity> {
                    p, q, r
                };

                Assert.True(db.UpsertList(lst));

                p.FirstName = "Emily";
                q.FirstName = "a".PadRight(101, 'a');
                r.FirstName = "Laura";
                lst.Add(s);

                Assert.ThrowsAny <Exception>(() => db.UpsertList(new List <PersonIdentity> {
                    p, q, r
                }));

                var gp = db.Get <PersonIdentity>(p.IdentityId);

                Assert.Equal("Alice", gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);

                var gs = db.Get <PersonIdentity>(s.IdentityId);

                Assert.Null(gs);
            }
        }
Пример #10
0
        public void UpsertListIdentity()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                var q = new PersonIdentity {
                    FirstName = "Raj", LastName = "Padilla"
                };
                var r = new PersonIdentity {
                    FirstName = "Lidia", LastName = "Bain"
                };
                var s = new PersonIdentity {
                    FirstName = "Derren", LastName = "Southern"
                };

                var lst = new List <PersonIdentity> {
                    p, q, r
                };

                Assert.True(db.UpsertList(lst));

                p.FirstName = "Emily";
                q.FirstName = "Jim";
                r.FirstName = "Laura";
                lst.Add(s);

                Assert.True(db.UpsertList(lst));

                var gp = db.Get <PersonIdentity>(p.IdentityId);

                Assert.Equal("Emily", gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);

                var gs = db.Get <PersonIdentity>(s.IdentityId);

                Assert.Equal("Derren", gs.FirstName);
                Assert.Equal("Southern", gs.LastName);
            }
        }
        public async Task UpdatePartialAsync()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                Assert.True(await db.InsertAsync(p));
                Assert.True(p.IdentityId > 0);

                p.FirstName = "Greg";
                p.LastName  = "Smith";
                Assert.True(await db.UpdateAsync(p, new string[] { "LastName" }));

                var gp = await db.GetAsync <PersonIdentity>(p.IdentityId);

                Assert.Equal(p.IdentityId, gp.IdentityId);
                Assert.Equal("Alice", gp.FirstName);
                Assert.Equal("Smith", gp.LastName);
            }
        }
Пример #12
0
        public void UpsertPartial()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                Assert.True(db.Upsert(p));
                Assert.True(p.IdentityId > 0);

                p.FirstName = "Greg";
                p.LastName  = "Smith";
                Assert.True(db.Upsert(p, new string[] { "LastName" }));

                var gp = db.Get <PersonIdentity>(p.IdentityId);

                Assert.Equal(p.IdentityId, gp.IdentityId);
                Assert.Equal("Alice", gp.FirstName);
                Assert.Equal("Smith", gp.LastName);
            }
        }
Пример #13
0
        public async Task InsertListIdentityThrowsExceptionAsync()
        {
            Skip.If(GetProvider() == Provider.SQLite, "Sqlite doesn't enforce size limit");

            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                var q = new PersonIdentity {
                    FirstName = "a".PadRight(101, 'a'), LastName = "Padilla"
                };
                var r = new PersonIdentity {
                    FirstName = "Lidia", LastName = "Bain"
                };
                await Assert.ThrowsAnyAsync <Exception>(() => db.InsertListAsync(new List <PersonIdentity> {
                    p, q, r
                }));

                Assert.Null(await db.GetAsync <PersonIdentity>(p.IdentityId));
            }
        }
Пример #14
0
        public void DeleteIdentity()
        {
            using (var db = GetSqlDatabase())
            {
                var pOther = new PersonIdentity {
                    FirstName = "OtherAlice", LastName = "OtherJones"
                };
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                Assert.True(db.Insert(p));
                Assert.True(p.IdentityId > 0);
                Assert.True(db.Insert(pOther));
                Assert.True(pOther.IdentityId > 0);

                Assert.True(db.Delete <PersonIdentity>(p.IdentityId));

                var gp      = db.Get(p);
                var gpOther = db.Get(pOther);
                Assert.Null(gp);
                Assert.NotNull(gpOther);
            }
        }
Пример #15
0
        public async Task InsertListIdentityAsync()
        {
            using (var db = GetSqlDatabase())
            {
                var p = new PersonIdentity {
                    FirstName = "Alice", LastName = "Jones"
                };
                var q = new PersonIdentity {
                    FirstName = "Raj", LastName = "Padilla"
                };
                var r = new PersonIdentity {
                    FirstName = "Lidia", LastName = "Bain"
                };
                Assert.True(await db.InsertListAsync(new List <PersonIdentity> {
                    p, q, r
                }));
                Assert.True(p.IdentityId > 0);
                var gp = await db.GetAsync <PersonIdentity>(p.IdentityId);

                Assert.Equal(p.IdentityId, gp.IdentityId);
                Assert.Equal(p.FirstName, gp.FirstName);
                Assert.Equal(p.LastName, gp.LastName);
            }
        }