Esempio n. 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());
            }
        }
        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());
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
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();
            }
        }
        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();
            }
        }
Esempio n. 7
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();
            }
        }
        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();
            }
        }
        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();
            }
        }
        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();
            }
        }