예제 #1
0
        public void DeleteAndAddAndGet()
        {
            var account    = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row        = new TestRow
            {
                PartitionKey = "partition_key_DeleteAndAddAndGet",
                RowKey       = "row_key_DeleteAndAddAndGet",
                Content      = "content"
            };

            azureTable.Delete(row);
            TestRow deletedRow = (from o in azureTable.Query
                                  where o.RowKey == row.RowKey
                                  select o).SingleOrDefault();

            Assert.IsNull(deletedRow);

            azureTable.Add(row);
            TestRow savedRow = (from o in azureTable.Query
                                where o.RowKey == row.RowKey &&
                                o.PartitionKey == "partition_key_DeleteAndAddAndGet" &&
                                o.Content == "content"
                                select o).SingleOrDefault();

            Assert.IsNotNull(savedRow);

            azureTable.Delete(row);
            TestRow actualRow = (from o in azureTable.Query
                                 where o.RowKey == row.RowKey
                                 select o).SingleOrDefault();

            Assert.IsNull(actualRow);
        }
예제 #2
0
        public void SaveManyAndDeleteMany()
        {
            var account    = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row1       = new TestRow {
                PartitionKey = "partition_key_SaveManyAndDeleteMany", RowKey = "row_key_1_SaveManyAndDeleteMany"
            };
            var row2 = new TestRow {
                PartitionKey = "partition_key_SaveManyAndDeleteMany", RowKey = "row_key_2_SaveManyAndDeleteMany"
            };

            azureTable.Delete(new[] { row1, row2 });
            var rowsToDelete = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_SaveManyAndDeleteMany"
                                select o).ToList();

            Assert.AreEqual(0, rowsToDelete.Count);

            azureTable.Add(new[] { row1, row2 });
            var insertedRows = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_SaveManyAndDeleteMany"
                                select o).ToList();

            Assert.AreEqual(2, insertedRows.Count);

            azureTable.Delete(new[] { row1, row2 });
            var actualRows = (from o in azureTable.Query
                              where o.PartitionKey == "partition_key_SaveManyAndDeleteMany"
                              select o).ToList();

            Assert.AreEqual(0, actualRows.Count);
        }
예제 #3
0
        public void DeleteAndAddAndGet()
        {
            var account    = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row        = new TestRow
            {
                PartitionKey = "partition_key_DeleteAndAddAndGet",
                RowKey       = "row_key_DeleteAndAddAndGet",
                Content      = "content"
            };

            azureTable.Delete(row);
            TableQuery <TestRow> query = new TableQuery <TestRow>().Where(TableQuery.GenerateFilterCondition(("RowKey"), QueryComparisons.Equal, row.RowKey));
            var deletedRow             = azureTable.AzureCloudTable.ExecuteQuery(query).SingleOrDefault();

            //TestRow deletedRow = azureTable.AzureCloudTable.ExecuteQuery( (from o in azureTable.Query
            //                      where o.RowKey == row.RowKey
            //                      select o).SingleOrDefault();
            Assert.IsNull(deletedRow);

            azureTable.Add(row);

            TableQuery <TestRow> query1 = new TableQuery <TestRow>().Where
                                          (
                TableQuery.GenerateFilterCondition(("RowKey"), QueryComparisons.Equal, row.RowKey) +
                TableQuery.GenerateFilterCondition(("PartitionKey"), QueryComparisons.Equal, "partition_key_DeleteAndAddAndGet")
                                          );
            var tableSavedResult = azureTable.AzureCloudTable.Execute(TableOperation.Retrieve("partition_key_DeleteAndAddAndGet", row.RowKey));

            //TestRow savedRow = (TestRow)tableSavedResult.Result;

            //var savedRow = azureTable.AzureCloudTable.ExecuteQuery(query1).SingleOrDefault();
            //TestRow savedRow = (from o in azureTable.Query
            //                    where o.RowKey == row.RowKey &&
            //                          o.PartitionKey == "partition_key_DeleteAndAddAndGet" &&
            //                                  o.Content == "content"
            //                    select o).SingleOrDefault();
            Assert.IsNotNull(tableSavedResult.Result);

            azureTable.Delete(row);
            var tableActualResult = azureTable.AzureCloudTable.Execute(TableOperation.Retrieve("*", row.RowKey));

            //TestRow actualRow = (TestRow)tableActualResult.Result;
            //TestRow actualRow = (from o in azureTable.Query
            //                     where o.RowKey == row.RowKey
            //                     select o).SingleOrDefault();
            Assert.IsNull(tableActualResult.Result);
        }
예제 #4
0
        public void AddOrUpdateAddsWhenNotExists()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var azureTable = new AzureTable <TestRow>(account, TableName);

            azureTable.RetryPolicyFactory = new DefaultRetryPolicyFactory();

            var row = new TestRow
            {
                PartitionKey = "partition_key_AddOrUpdateAddsWhenNotExists",
                RowKey       = "row_key_AddOrUpdateAddsWhenNotExists",
                Content      = "content"
            };

            azureTable.Delete(row);
            TestRow deletedRow = (from o in azureTable.Query
                                  where o.RowKey == row.RowKey
                                  select o).SingleOrDefault();

            Assert.IsNull(deletedRow);

            azureTable.AddOrUpdate(row);
            TestRow savedRow = (from o in azureTable.Query
                                where o.RowKey == row.RowKey &&
                                o.PartitionKey == "partition_key_AddOrUpdateAddsWhenNotExists" &&
                                o.Content == "content"
                                select o).SingleOrDefault();

            Assert.IsNotNull(savedRow);
        }
        public void Delete_Table_Entity()
        {
            CleanupTable("test6");

            IAzureTable <TestTableEntity> testTable = new AzureTable <TestTableEntity>(CloudStorageAccount.DevelopmentStorageAccount, "test6");


            var entity = new TestTableEntity
            {
                PartitionKey = "partitionkey",
                RowKey       = Guid.NewGuid().ToString(),
                Name         = "testname",
                Price        = 10
            };

            testTable.Insert(entity);

            var retrievedEntities = testTable.Query.Where(x => x.PartitionKey == "partitionkey").ToList();

            Assert.AreEqual(1, retrievedEntities.Count);

            testTable.Delete(entity);

            var retrievedEntities2 = testTable.Query.Where(x => x.PartitionKey == "partitionkey").ToList();

            Assert.AreEqual(0, retrievedEntities2.Count);
        }
예제 #6
0
        public void AddOrUpdateMany()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable<TestRow>(account, TableName);
            var row1 = new TestRow { PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_1_AddOrUpdateMany", Content = "content 1" };
            var row2 = new TestRow { PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_2_AddOrUpdateMany", Content = "content 2" };

            azureTable.Delete(new[] { row1, row2 });
            var rowsToDelete = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_AddOrUpdateMany"
                                select o).ToList();
            Assert.AreEqual(0, rowsToDelete.Count);

            azureTable.Add(row1);
            var actualRows = (from o in azureTable.Query
                              where o.PartitionKey == "partition_key_AddOrUpdateMany"
                              select o).ToList();
            Assert.AreEqual(1, actualRows.Count);

            row1.Content = "content modified";
            azureTable.AddOrUpdate(new[] { row1, row2 });
            var insertedRows = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_AddOrUpdateMany"
                                select o).ToList();
            Assert.AreEqual(2, insertedRows.Count);

            TestRow updatedRow = (from o in azureTable.Query
                                  where o.RowKey == row1.RowKey &&
                                        o.PartitionKey == "partition_key_AddOrUpdateMany" &&
                                        o.Content == "content modified"
                                  select o).SingleOrDefault();
            Assert.IsNotNull(updatedRow);
        }
예제 #7
0
        public void AddOrUpdateAddsWhenNotExists()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

            var azureTable = new AzureTable<TestRow>(account, TableName);
            azureTable.RetryPolicyFactory = new DefaultRetryPolicyFactory();

            var row = new TestRow
            {
                PartitionKey = "partition_key_AddOrUpdateAddsWhenNotExists",
                RowKey = "row_key_AddOrUpdateAddsWhenNotExists",
                Content = "content"
            };

            azureTable.Delete(row);
            TestRow deletedRow = (from o in azureTable.Query
                                  where o.RowKey == row.RowKey
                                  select o).SingleOrDefault();
            Assert.IsNull(deletedRow);

            azureTable.AddOrUpdate(row);
            TestRow savedRow = (from o in azureTable.Query
                                where o.RowKey == row.RowKey &&
                                      o.PartitionKey == "partition_key_AddOrUpdateAddsWhenNotExists" &&
                                      o.Content == "content"
                                select o).SingleOrDefault();
            Assert.IsNotNull(savedRow);
        }
        public void Bulk_Delete_Table_Entities()
        {
            CleanupTable("test7");

            IAzureTable <TestTableEntity> testTable = new AzureTable <TestTableEntity>(CloudStorageAccount.DevelopmentStorageAccount, "test7");


            var entities = new List <TestTableEntity>();

            for (var i = 0; i < 150; i++)
            {
                var entity = new TestTableEntity
                {
                    PartitionKey = "partitionkey",
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "testname",
                    Price        = 10
                };
                entities.Add(entity);
            }
            for (var i = 0; i < 30; i++)
            {
                var entity = new TestTableEntity
                {
                    PartitionKey = "partitionkey2",
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "testname",
                    Price        = 10
                };
                entities.Add(entity);
            }
            for (var i = 0; i < 220; i++)
            {
                var entity = new TestTableEntity
                {
                    PartitionKey = "partitionkey3",
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "testname",
                    Price        = 10
                };
                entities.Add(entity);
            }
            testTable.Insert(entities);

            var retrievedEntities = testTable.Query.ToList();

            Assert.AreEqual(400, retrievedEntities.Count);

            testTable.Delete(entities);
            var retrievedEntities2 = testTable.Query.ToList();

            Assert.AreEqual(0, retrievedEntities2.Count);
        }
예제 #9
0
        public void AddOrUpdateMany()
        {
            var account    = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row1       = new TestRow {
                PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_1_AddOrUpdateMany", Content = "content 1"
            };
            var row2 = new TestRow {
                PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_2_AddOrUpdateMany", Content = "content 2"
            };

            azureTable.Delete(new[] { row1, row2 });
            var rowsToDelete = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_AddOrUpdateMany"
                                select o).ToList();

            Assert.AreEqual(0, rowsToDelete.Count);

            azureTable.Add(row1);
            var actualRows = (from o in azureTable.Query
                              where o.PartitionKey == "partition_key_AddOrUpdateMany"
                              select o).ToList();

            Assert.AreEqual(1, actualRows.Count);

            row1.Content = "content modified";
            azureTable.AddOrUpdate(new[] { row1, row2 });
            var insertedRows = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_AddOrUpdateMany"
                                select o).ToList();

            Assert.AreEqual(2, insertedRows.Count);

            TestRow updatedRow = (from o in azureTable.Query
                                  where o.RowKey == row1.RowKey &&
                                  o.PartitionKey == "partition_key_AddOrUpdateMany" &&
                                  o.Content == "content modified"
                                  select o).SingleOrDefault();

            Assert.IsNotNull(updatedRow);
        }
예제 #10
0
        public void SaveManyAndDeleteMany()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable<TestRow>(account, TableName);
            var row1 = new TestRow { PartitionKey = "partition_key_SaveManyAndDeleteMany", RowKey = "row_key_1_SaveManyAndDeleteMany" };
            var row2 = new TestRow { PartitionKey = "partition_key_SaveManyAndDeleteMany", RowKey = "row_key_2_SaveManyAndDeleteMany" };

            azureTable.Delete(new[] { row1, row2 });
            var rowsToDelete = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_SaveManyAndDeleteMany"
                                select o).ToList();
            Assert.AreEqual(0, rowsToDelete.Count);

            azureTable.Add(new[] { row1, row2 });
            var insertedRows = (from o in azureTable.Query
                                where o.PartitionKey == "partition_key_SaveManyAndDeleteMany"
                                select o).ToList();
            Assert.AreEqual(2, insertedRows.Count);

            azureTable.Delete(new[] { row1, row2 });
            var actualRows = (from o in azureTable.Query
                              where o.PartitionKey == "partition_key_SaveManyAndDeleteMany"
                              select o).ToList();
            Assert.AreEqual(0, actualRows.Count);
        }
예제 #11
0
        public void DeleteAndAddAndGet()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var azureTable = new AzureTable<TestRow>(account, TableName);
            var row = new TestRow
            {
                PartitionKey = "partition_key_DeleteAndAddAndGet",
                RowKey = "row_key_DeleteAndAddAndGet",
                Content = "content"
            };

            azureTable.Delete(row);
            TestRow deletedRow = (from o in azureTable.Query
                                  where o.RowKey == row.RowKey
                                  select o).SingleOrDefault();
            Assert.IsNull(deletedRow);

            azureTable.Add(row);
            TestRow savedRow = (from o in azureTable.Query
                                where o.RowKey == row.RowKey &&
                                      o.PartitionKey == "partition_key_DeleteAndAddAndGet" &&
                                              o.Content == "content"
                                select o).SingleOrDefault();
            Assert.IsNotNull(savedRow);

            azureTable.Delete(row);
            TestRow actualRow = (from o in azureTable.Query
                                 where o.RowKey == row.RowKey
                                 select o).SingleOrDefault();
            Assert.IsNull(actualRow);
        }
        public void Bulk_Delete_Table_Entities()
        {
            CleanupTable("test7");

            IAzureTable<TestTableEntity> testTable = new AzureTable<TestTableEntity>(CloudStorageAccount.DevelopmentStorageAccount, "test7");
            

            var entities = new List<TestTableEntity>();

            for (var i = 0; i < 150; i++)
            {
                var entity = new TestTableEntity
                {
                    PartitionKey = "partitionkey",
                    RowKey = Guid.NewGuid().ToString(),
                    Name = "testname",
                    Price = 10
                };
                entities.Add(entity);
            }
            for (var i = 0; i < 30; i++)
            {
                var entity = new TestTableEntity
                {
                    PartitionKey = "partitionkey2",
                    RowKey = Guid.NewGuid().ToString(),
                    Name = "testname",
                    Price = 10
                };
                entities.Add(entity);
            }
            for (var i = 0; i < 220; i++)
            {
                var entity = new TestTableEntity
                {
                    PartitionKey = "partitionkey3",
                    RowKey = Guid.NewGuid().ToString(),
                    Name = "testname",
                    Price = 10
                };
                entities.Add(entity);
            }
            testTable.Insert(entities);

            var retrievedEntities = testTable.Query.ToList();
            Assert.AreEqual(400, retrievedEntities.Count);
            
            testTable.Delete(entities);
            var retrievedEntities2 = testTable.Query.ToList();
            Assert.AreEqual(0, retrievedEntities2.Count);

        }
        public void Delete_Table_Entity()
        {
            CleanupTable("test6");

            IAzureTable<TestTableEntity> testTable = new AzureTable<TestTableEntity>(CloudStorageAccount.DevelopmentStorageAccount, "test6");
            

            var entity = new TestTableEntity
            {
                PartitionKey = "partitionkey",
                RowKey = Guid.NewGuid().ToString(),
                Name = "testname",
                Price = 10
            };

            testTable.Insert(entity);

            var retrievedEntities = testTable.Query.Where(x => x.PartitionKey == "partitionkey").ToList();
            Assert.AreEqual(1, retrievedEntities.Count);
            
            testTable.Delete(entity);

            var retrievedEntities2 = testTable.Query.Where(x => x.PartitionKey == "partitionkey").ToList();
            Assert.AreEqual(0, retrievedEntities2.Count);
        }