Esempio n. 1
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 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);
        }
Esempio n. 3
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);
        }
        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);
        }