Example #1
0
        public async Task Concurrency_RowOldCopy_MustNotUpdate()
        {
            if (!_tables.HasOptimisticConcurrency)
            {
                return;
            }

            //insert one row
            var row = new TableRow("pk", "rk")
            {
                ["c"] = "1"
            };
            await _tables.InsertAsync(_tableName, new TableRow[] { row });

            Assert.NotNull(row.Id.ConcurrencyKey);

            //update with a new value
            var row1 = new TableRow("pk", "rk")
            {
                ["c"] = "2"
            };
            await _tables.MergeAsync(_tableName, new TableRow[] { row1 });

            Assert.NotNull(row1.Id.ConcurrencyKey);
            Assert.NotEqual(row.Id.ConcurrencyKey, row1.Id.ConcurrencyKey);

            //now use the first row (old ETag) to set the new value
            row["c"] = "2";
            await Assert.ThrowsAsync <StorageException>(() => _tables.UpdateAsync(_tableName, new TableRow[] { row }));

            await Assert.ThrowsAsync <StorageException>(() => _tables.DeleteAsync(_tableName, new TableRowId[] { row.Id }));
        }