コード例 #1
0
        public void TestBasicCRUD()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content  = "Test content";
                n.Created  = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit <Note>(n);
                db.SubmitChanges();

                Assert.AreNotEqual(n.Codigo, 0);

                Note result = db.Connection.Query <Note>("SELECT * FROM Notes WHERE Codigo = @Id", new { Id = n.Codigo }).FirstOrDefault();
                Assert.AreNotEqual(result, null);
                Assert.AreEqual(result.Content, n.Content);
                Assert.AreEqual(result.Created, n.Created);
                Assert.AreEqual(result.Modified, n.Modified);

                db.DeleteOnSubmit <Note>(result);
                db.SubmitChanges();

                Assert.IsFalse(db.Connection.Query <Post>("SELECT * FROM Notes WHERE Codigo = @Id", new { Id = n.Codigo }).Any());
            }
        }
コード例 #2
0
        public void TestBasicCRUD()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content = "Test content";
                n.Created = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit<Note>(n);
                db.SubmitChanges();

                Assert.AreNotEqual(n.Codigo, 0);

                Note result = db.Connection.Query<Note>("SELECT * FROM Notes WHERE Codigo = @Id", new { Id = n.Codigo }).FirstOrDefault();
                Assert.AreNotEqual(result, null);
                Assert.AreEqual(result.Content, n.Content);
                Assert.AreEqual(result.Created, n.Created);
                Assert.AreEqual(result.Modified, n.Modified);

                db.DeleteOnSubmit<Note>(result);
                db.SubmitChanges();

                Assert.IsFalse(db.Connection.Query<Post>("SELECT * FROM Notes WHERE Codigo = @Id", new { Id = n.Codigo }).Any());
            }
        }
コード例 #3
0
        public void TestUpdateCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";
                a.Posts    = new List <Post>();

                Post p = new Post();
                p.Content = "Test post content";

                Post pp = new Post();
                pp.Content = "Another test content";

                a.Posts.Add(p);
                a.Posts.Add(pp);

                db.InsertOnSubmit <Author>(a); // assume it works, tested on other methods
                db.SubmitChanges();

                a.Posts.First().Content = "Last content";
                db.UpdateOnSubmit <Author>(a, Context.CascadeStyle.All);
                db.SubmitChanges();

                Post compare = db.Connection.Query <Post>("SELECT * FROM Posts WHERE Id = " + a.Posts.First().Id).FirstOrDefault();

                Assert.AreEqual(compare.Content, a.Posts.First().Content);

                db.DeleteOnSubmit <Author>(a, Context.CascadeStyle.All);
                db.SubmitChanges();
            }
        }
コード例 #4
0
        public void TestUpdateSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content  = "Prueba";
                n.Created  = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit <Note>(n);
                db.SubmitChanges();

                n.Content = "Test";
                db.UpdateOnSubmit <Note>(n);
                db.SubmitChanges();

                Note newNote = db.Connection.Query <Note>("SELECT * FROM Notes WHERE Codigo = " + n.Codigo).FirstOrDefault();

                Assert.AreEqual(newNote.Content, "Test");

                db.DeleteOnSubmit <Note>(newNote);
                db.SubmitChanges();
            }
        }
コード例 #5
0
        public void TestFind()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Dummy post";

                db.InsertOnSubmit <Post>(p);
                db.SubmitChanges();

                Post found = db.Find <Post>(x => { return(x.Content == "Dummy post"); }).FirstOrDefault();

                Assert.AreNotEqual(found, null);
                Assert.AreEqual(found.Content, p.Content);
                Assert.IsTrue(found.Id > 0);
            }
        }
コード例 #6
0
        public void TestChainedInsertSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                Post p = new Post();
                p.Content = "Test content";
                p.Author  = a;

                int id = db.InsertOnSubmit <Post>(p);

                Assert.AreEqual(id, p.Id);
                Assert.AreEqual(p.Author, a);
                Assert.AreNotEqual(p.Author.Id, 0);

                db.DeleteOnSubmit <Post>(p, Context.CascadeStyle.Single); // force cascading delete

                db.SubmitChanges();
            }
        }
コード例 #7
0
        public void TestChainedInsertUsingCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Test content 'n' escapes!";

                Author a = new Author();
                a.Username = "******";
                a.Posts    = new List <Post>();
                a.Posts.Add(p);

                int id = db.InsertOnSubmit <Author>(a);

                Assert.AreEqual(a.Id, id);
                Assert.AreEqual(a.Posts.First(), p);

                db.DeleteOnSubmit <Author>(a, Context.CascadeStyle.Collection); // force cascading delete

                db.SubmitChanges();
            }
        }
コード例 #8
0
        public void TestUpdateSingle()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                // Now let's use the inserted author
                Post p = new Post();
                p.Content = "Test";
                p.Author  = a;

                db.InsertOnSubmit <Post>(p);
                db.SubmitChanges();

                //db.UpdateOnSubmit<Post>(test);
                //db.SubmitChanges();

                //Author compare = db.Connection.Query<Author>("SELECT * FROM Authors WHERE Id = " + test.Author.Id).FirstOrDefault();
                //Assert.AreEqual(compare, test.Author);
            }
        }
コード例 #9
0
        public void TestChainedInsertSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                Post p = new Post();
                p.Content = "Test content";
                p.Author = a;

                int id = db.InsertOnSubmit<Post>(p);

                Assert.AreEqual(id, p.Id);
                Assert.AreEqual(p.Author, a);
                Assert.AreNotEqual(p.Author.Id, 0);

                db.DeleteOnSubmit<Post>(p, Context.CascadeStyle.Single); // force cascading delete

                db.SubmitChanges();
            }
        }
コード例 #10
0
        public void TestChainedInsertUsingCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Test content 'n' escapes!";

                Author a = new Author();
                a.Username = "******";
                a.Posts = new List<Post>();
                a.Posts.Add(p);

                int id = db.InsertOnSubmit<Author>(a);

                Assert.AreEqual(a.Id, id);
                Assert.AreEqual(a.Posts.First(), p);

                db.DeleteOnSubmit<Author>(a, Context.CascadeStyle.Collection); // force cascading delete

                db.SubmitChanges();
            }
        }
コード例 #11
0
        public void TestUpdateSingle()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                // Now let's use the inserted author
                Post p = new Post();
                p.Content = "Test";
                p.Author = a;

                db.InsertOnSubmit<Post>(p);
                db.SubmitChanges();

                //db.UpdateOnSubmit<Post>(test);
                //db.SubmitChanges();

                //Author compare = db.Connection.Query<Author>("SELECT * FROM Authors WHERE Id = " + test.Author.Id).FirstOrDefault();
                //Assert.AreEqual(compare, test.Author);
            }
        }
コード例 #12
0
        public void TestUpdateSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content = "Prueba";
                n.Created = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit<Note>(n);
                db.SubmitChanges();

                n.Content = "Test";
                db.UpdateOnSubmit<Note>(n);
                db.SubmitChanges();

                Note newNote = db.Connection.Query<Note>("SELECT * FROM Notes WHERE Codigo = " + n.Codigo).FirstOrDefault();

                Assert.AreEqual(newNote.Content, "Test");

                db.DeleteOnSubmit<Note>(newNote);
                db.SubmitChanges();
            }
        }
コード例 #13
0
        public void TestUpdateCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";
                a.Posts = new List<Post>();

                Post p = new Post();
                p.Content = "Test post content";

                Post pp = new Post();
                pp.Content = "Another test content";

                a.Posts.Add(p);
                a.Posts.Add(pp);

                db.InsertOnSubmit<Author>(a); // assume it works, tested on other methods
                db.SubmitChanges();

                a.Posts.First().Content = "Last content";
                db.UpdateOnSubmit<Author>(a, Context.CascadeStyle.All);
                db.SubmitChanges();

                Post compare = db.Connection.Query<Post>("SELECT * FROM Posts WHERE Id = " + a.Posts.First().Id).FirstOrDefault();

                Assert.AreEqual(compare.Content, a.Posts.First().Content);

                db.DeleteOnSubmit<Author>(a, Context.CascadeStyle.All);
                db.SubmitChanges();
            }
        }
コード例 #14
0
        public void TestFind()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Dummy post";

                db.InsertOnSubmit<Post>(p);
                db.SubmitChanges();

                Post found = db.Find<Post>(x => { return x.Content == "Dummy post"; }).FirstOrDefault();

                Assert.AreNotEqual(found, null);
                Assert.AreEqual(found.Content, p.Content);
                Assert.IsTrue(found.Id > 0);
            }
        }