Exemplo n.º 1
0
        public void TestRemovalOfCompositeKeys_Commit()
        {
            UserProduct retrievedUP = null;

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                UserProduct up = new UserProduct();
                up.UserId    = userId;
                up.ProductId = productId;

                context.Insert <UserProduct>(up);
                context.Commit();
            }

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                // Makes sure user product being retreived exists
                UserProduct up = context.QueryItems <UserProduct>("select * from dbo.UserProduct where UserId = @userId and ProductId = @productId", new { userId = userId, productId = productId }).FirstOrDefault();
                Assert.IsTrue(up != null && up.UserId == userId && up.ProductId == productId);

                context.Remove(up);
                context.Commit();

                retrievedUP = context.QueryItems <UserProduct>("select * from dbo.UserProduct where UserId = @userId and ProductId = @productId", new { userId = userId, productId = productId }).FirstOrDefault();
            }

            Assert.IsTrue(retrievedUP == null, "A problem occurred when trying to remove a composite key");
        }
Exemplo n.º 2
0
        public void TestRemove_NoCommit()
        {
            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                Product p = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault();

                Assert.IsTrue(p != null && p.Id > 0);

                context.Remove(p);
            }

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                Product p = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault();

                Assert.IsTrue(p != null && p.Id > 0);
            }
        }