public async Task AddOrUpdateUpdatesWhenExists()
        {
            var azureTable = new AzureTable <TestRow>(account, TableName);

            var row = new TestRow
            {
                PartitionKey = "partition_key_AddOrUpdateUpdatesWhenExists",
                RowKey       = "row_key_AddOrUpdateUpdatesWhenExists",
                Content      = "content"
            };

            await azureTable.DeleteAsync(row);

            TestRow deletedRow = (await azureTable.GetByRowKeyAsync(row.RowKey)).SingleOrDefault();

            Assert.IsNull(deletedRow);

            await azureTable.AddAsync(row);

            TestRow savedRow = await azureTable.GetByPartitionRowKeyAsync("partition_key_AddOrUpdateUpdatesWhenExists", row.RowKey);

            Assert.IsNotNull(savedRow);
            Assert.AreEqual("content", savedRow.Content);

            row.Content = "content modified";
            await azureTable.AddOrUpdateAsync(row);

            TestRow updatedRow = await azureTable.GetByPartitionRowKeyAsync("partition_key_AddOrUpdateUpdatesWhenExists", row.RowKey);

            Assert.IsNotNull(updatedRow);
            Assert.AreEqual("content modified", updatedRow.Content);
        }
        public async Task AddOrUpdateMany()
        {
            var azureTable = new AzureTable <TestRow>(account, TableName);
            var row1       = new TestRow {
                PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_1_AddOrUpdateMany", Content = "content 1", ETag = "*"
            };
            var row2 = new TestRow {
                PartitionKey = "partition_key_AddOrUpdateMany", RowKey = "row_key_2_AddOrUpdateMany", Content = "content 2", ETag = "*"
            };

            await azureTable.DeleteAsync(new[] { row1, row2 });

            var rowsToDelete = await azureTable.GetByPartitionKeyAsync("partition_key_AddOrUpdateMany");

            Assert.AreEqual(0, rowsToDelete.Count());

            await azureTable.AddAsync(row1);

            var actualRows = await azureTable.GetByPartitionKeyAsync("partition_key_AddOrUpdateMany");

            Assert.AreEqual(1, actualRows.Count());

            row1.Content = "content modified";
            await azureTable.AddOrUpdateAsync(new[] { row1, row2 });

            var insertedRows = await azureTable.GetByPartitionKeyAsync("partition_key_AddOrUpdateMany");

            Assert.AreEqual(2, insertedRows.Count());

            TestRow updatedRow = await azureTable.GetByPartitionRowKeyAsync("partition_key_AddOrUpdateMany", row1.RowKey);

            Assert.IsNotNull(updatedRow);
            Assert.AreEqual("content modified", updatedRow.Content);
        }
예제 #3
0
        public async Task AddOrUpdateAddsWhenNotExists()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");

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

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

            await azureTable.DeleteAsync(row);

            TestRow deletedRow = (await azureTable.GetByRowKeyAsync(row.RowKey)).SingleOrDefault();

            Assert.IsNull(deletedRow);

            await azureTable.AddOrUpdateAsync(row);

            TestRow savedRow = await azureTable.GetByPartitionRowKeyAsync("partition_key_AddOrUpdateAddsWhenNotExists", row.RowKey);

            Assert.IsNotNull(savedRow);
            Assert.AreEqual("content", savedRow.Content);
        }