Esempio n. 1
0
        public async Task Update_MultipleRows()
        {
            // first insert 2 categories and 4 products, one for each category
            var categories        = new Categories();
            var insertedCategory1 = await categories.InsertAsync(new { CategoryName = "Category 1", Description = "Cat 1 desc" });

            int category1ID = insertedCategory1.CategoryID;

            Assert.IsTrue(category1ID > 0);
            var insertedCategory2 = await categories.InsertAsync(new { CategoryName = "Category 2", Description = "Cat 2 desc" });

            int category2ID = insertedCategory2.CategoryID;

            Assert.IsTrue(category2ID > 0);

            var products = new Products();

            for (int i = 0; i < 4; i++)
            {
                var category = i % 2 == 0 ? insertedCategory1 : insertedCategory2;
                var p        = await products.InsertAsync(new { ProductName = "Prod" + i, category.CategoryID });

                Assert.IsTrue(p.ProductID > 0);
            }
            var allCat1Products = await(await products.AllAsync(where : "WHERE CategoryID=@0", args: category1ID)).ToArrayAsync();

            Assert.AreEqual(2, allCat1Products.Length);
            foreach (var p in allCat1Products)
            {
                Assert.AreEqual(category1ID, p.CategoryID);
                p.CategoryID = category2ID;
            }
            Assert.AreEqual(2, await products.SaveAsync(allCat1Products));
        }
Esempio n. 2
0
        public async Task Update_MultipleRows(bool explicitConnection)
        {
            // first insert 2 categories and 4 products, one for each category
            var          categories = new Categories(explicitConnection);
            DbConnection connection = null;

            if (explicitConnection)
            {
                MightyTests.ConnectionStringUtils.CheckConnectionStringRequiredForOpenConnectionAsync(categories);
                connection = await categories.OpenConnectionAsync(MightyTests.ConnectionStringUtils.GetConnectionString(TestConstants.WriteTestConnection, TestConstants.ProviderName));
            }
            using (connection)
            {
                var insertedCategory1 = await categories.InsertAsync(new { CategoryName = "Category 1", Description = "Cat 1 desc" }, connection);

                int category1ID = insertedCategory1.CategoryID;
                Assert.IsTrue(category1ID > 0);
                var insertedCategory2 = await categories.InsertAsync(new { CategoryName = "Category 2", Description = "Cat 2 desc" }, connection);

                int category2ID = insertedCategory2.CategoryID;
                Assert.IsTrue(category2ID > 0);

                var products = new Products(explicitConnection);
                if (explicitConnection)
                {
                    MightyTests.ConnectionStringUtils.CheckConnectionStringRequiredForOpenConnectionAsync(products);
                }
                for (int i = 0; i < 4; i++)
                {
                    var category = i % 2 == 0 ? insertedCategory1 : insertedCategory2;
                    var p        = await products.InsertAsync(new { ProductName = "Prod" + i, category.CategoryID }, connection);

                    Assert.IsTrue(p.ProductID > 0);
                }
                var allCat1Products = await(await products.AllAsync(connection, where : "WHERE CategoryID=@0", args: category1ID)).ToArrayAsync();
                Assert.AreEqual(2, allCat1Products.Length);
                foreach (var p in allCat1Products)
                {
                    Assert.AreEqual(category1ID, p.CategoryID);
                    p.CategoryID = category2ID;
                }
                Assert.AreEqual(2, await products.SaveAsync(connection, allCat1Products));
            }
        }