private static DynamicReplicatedTableEntity GenerateRandomEnitity(string pk)
        {
            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity();
            ent.Properties.Add("foo", new EntityProperty("bar"));

            ent.PartitionKey = pk;
            ent.RowKey = Guid.NewGuid().ToString();
            return ent;
        }
        public void TableEntityPropertyGenerator()
        {
            string pk = Guid.NewGuid().ToString();
            string rk = Guid.NewGuid().ToString();
            Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
            EntityProperty boolEntity = EntityProperty.GeneratePropertyForBool(true);
            properties.Add("boolEntity", boolEntity);
            EntityProperty timeEntity = EntityProperty.GeneratePropertyForDateTimeOffset(DateTimeOffset.UtcNow);
            properties.Add("timeEntity", timeEntity);
            EntityProperty doubleEntity = EntityProperty.GeneratePropertyForDouble(0.1);
            properties.Add("doubleEntity", doubleEntity);
            EntityProperty guidEntity = EntityProperty.GeneratePropertyForGuid(Guid.NewGuid());
            properties.Add("guidEntity", guidEntity);
            EntityProperty intEntity = EntityProperty.GeneratePropertyForInt(1);
            properties.Add("intEntity", intEntity);
            EntityProperty longEntity = EntityProperty.GeneratePropertyForLong(1);
            properties.Add("longEntity", longEntity);
            EntityProperty stringEntity = EntityProperty.GeneratePropertyForString("string");
            properties.Add("stringEntity", stringEntity);

            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity(pk, rk, "*", properties);
            this.repTable.Execute(TableOperation.Insert(ent));
        }
        public void TableEntityPropertySetter()
        {
            string pk = Guid.NewGuid().ToString();
            string rk = Guid.NewGuid().ToString();
            Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
            EntityProperty boolEntity = EntityProperty.GeneratePropertyForBool(null);
            boolEntity.BooleanValue = true;
            properties.Add("boolEntity", boolEntity);

            EntityProperty timeEntity = EntityProperty.GeneratePropertyForDateTimeOffset(null);
            timeEntity.DateTimeOffsetValue = DateTimeOffset.UtcNow;
            properties.Add("timeEntity", timeEntity);

            EntityProperty doubleEntity = EntityProperty.GeneratePropertyForDouble(null);
            doubleEntity.DoubleValue = 0.1;
            properties.Add("doubleEntity", doubleEntity);

            EntityProperty guidEntity = EntityProperty.GeneratePropertyForGuid(null);
            guidEntity.GuidValue = Guid.NewGuid();
            properties.Add("guidEntity", guidEntity);

            EntityProperty intEntity = EntityProperty.GeneratePropertyForInt(null);
            intEntity.Int32Value = 1;
            properties.Add("intEntity", intEntity);

            EntityProperty longEntity = EntityProperty.GeneratePropertyForLong(null);
            longEntity.Int64Value = 1;
            properties.Add("longEntity", longEntity);

            EntityProperty stringEntity = EntityProperty.GeneratePropertyForString(null);
            stringEntity.StringValue = "string";
            properties.Add("stringEntity", stringEntity);

            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity(pk, rk, "*", properties);
            this.repTable.Execute(TableOperation.Insert(ent));
        }
        public void TableDynamicReplicatedTableEntityConstructor()
        {
            string pk = Guid.NewGuid().ToString();
            string rk = Guid.NewGuid().ToString();
            Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
            properties.Add("foo", new EntityProperty("bar"));
            properties.Add("foo1", new EntityProperty("bar1"));

            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity(pk, rk, "*", properties);
            this.repTable.Execute(TableOperation.Insert(ent));
        }
        public void TableDynamicReplicatedTableEntitySetter()
        {
            string pk = Guid.NewGuid().ToString();
            string rk = Guid.NewGuid().ToString();
            Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
            properties.Add("foo", new EntityProperty("bar"));
            properties.Add("foo1", new EntityProperty("bar1"));

            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity();
            ent.PartitionKey = pk;
            ent.RowKey = rk;
            ent.Properties = properties;
            ent.ETag = "*";
            ent.Timestamp = DateTimeOffset.MinValue;
            this.repTable.Execute(TableOperation.Insert(ent));
        }
        public void TableBatchReplaceSync()
        {
            // Insert Entity
            Console.WriteLine("Calling Insert()...");
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("replace test", "foo");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            this.repTable.Execute(TableOperation.Insert(baseEntity));

            // ReplaceEntity
            DynamicReplicatedTableEntity replaceEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey)
            {
                ETag = "1"
            };
            replaceEntity.Properties.Add("prop2", new EntityProperty("value2"));

            Console.WriteLine("Calling Replace()...");
            TableBatchOperation batch = new TableBatchOperation();
            batch.Replace(replaceEntity);
            this.repTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            Console.WriteLine("Calling Retrieve()...");
            TableResult result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(replaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);

            //
            // Replace() again
            //
            Console.WriteLine("Calling Replace() again, setting Etag to {0}", retrievedEntity._rtable_Version);
            replaceEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey)
            {
                ETag = retrievedEntity._rtable_Version.ToString()
            };
            replaceEntity.Properties.Add("prop3", new EntityProperty("value3"));
            batch = new TableBatchOperation();
            batch.Replace(replaceEntity);
            this.repTable.ExecuteBatch(batch);

            Console.WriteLine("Calling Retrieve()...");
            result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity);

            Console.WriteLine("{0}", retrievedEntity.ToString());
            Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(replaceEntity.Properties["prop3"], retrievedEntity.Properties["prop3"]);
        }
        public void TableBatchWithPropertyOver255CharsShouldThrow()
        {
            TableBatchOperation batch = new TableBatchOperation();
            string pk = Guid.NewGuid().ToString();

            string propName = new string('a', 256);  // propName has 256 chars

            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity("foo", "bar");
            ent.Properties.Add(propName, new EntityProperty("propbar"));
            batch.Insert(ent);

            OperationContext opContext = new OperationContext();
            try
            {
                this.repTable.ExecuteBatch(batch, null, opContext);
                Assert.Fail();
            }
            catch (StorageException)
            {
                TestHelper.ValidateResponse(opContext, 1, (int)HttpStatusCode.BadRequest, new string[] { "PropertyNameTooLong" }, "The property name exceeds the maximum allowed length (255).");
            }
        }
        public void TableBatchMergeSync()
        {
            // Insert Entity
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("merge test", "foo");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            this.repTable.Execute(TableOperation.Insert(baseEntity));

            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = baseEntity.ETag };
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));

            TableBatchOperation batch = new TableBatchOperation();
            batch.Merge(mergeEntity);

            this.repTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            TableResult result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));

            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(2, retrievedEntity.Properties.Count);
            Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
        }
        public void TableBatchOperationsWithEmptyKeys()
        {
            // Insert Entity
            DynamicReplicatedTableEntity ent = new DynamicReplicatedTableEntity() { PartitionKey = "", RowKey = "" };
            ent.Properties.Add("foo2", new EntityProperty("bar2"));
            ent.Properties.Add("foo", new EntityProperty("bar"));
            TableBatchOperation batch = new TableBatchOperation();
            batch.Insert(ent);
            this.repTable.ExecuteBatch(batch);

            // Retrieve Entity
            TableBatchOperation retrieveBatch = new TableBatchOperation();
            retrieveBatch.Retrieve<DynamicReplicatedTableEntity>(ent.PartitionKey, ent.RowKey);
            TableResult result = this.repTable.ExecuteBatch(retrieveBatch).First();

            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
            Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
            Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(ent.Properties["foo"].StringValue, retrievedEntity.Properties["foo"].StringValue);
            Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
            Assert.AreEqual(ent.Properties["foo2"].StringValue, retrievedEntity.Properties["foo2"].StringValue);
            Assert.AreEqual(ent.Properties["foo2"], retrievedEntity.Properties["foo2"]);

            // InsertOrMerge
            DynamicReplicatedTableEntity insertOrMergeEntity = new DynamicReplicatedTableEntity(ent.PartitionKey, ent.RowKey);
            insertOrMergeEntity.Properties.Add("foo3", new EntityProperty("value"));
            batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            this.repTable.ExecuteBatch(batch);

            result = this.repTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["foo3"], retrievedEntity.Properties["foo3"]);

            // InsertOrReplace
            DynamicReplicatedTableEntity insertOrReplaceEntity = new DynamicReplicatedTableEntity(ent.PartitionKey, ent.RowKey);
            insertOrReplaceEntity.Properties.Add("prop2", new EntityProperty("otherValue"));
            batch = new TableBatchOperation();
            batch.InsertOrReplace(insertOrReplaceEntity);
            this.repTable.ExecuteBatch(batch);

            result = this.repTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(1, retrievedEntity.Properties.Count);
            Assert.AreEqual(insertOrReplaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);

            // Merge
            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(retrievedEntity.PartitionKey, retrievedEntity.RowKey) { ETag = retrievedEntity.ETag };
            mergeEntity.Properties.Add("mergeProp", new EntityProperty("merged"));
            batch = new TableBatchOperation();
            batch.Merge(mergeEntity);
            this.repTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            result = this.repTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(mergeEntity.Properties["mergeProp"], retrievedEntity.Properties["mergeProp"]);

            // Replace
            DynamicReplicatedTableEntity replaceEntity = new DynamicReplicatedTableEntity(ent.PartitionKey, ent.RowKey) { ETag = retrievedEntity.ETag };
            replaceEntity.Properties.Add("replaceProp", new EntityProperty("replace"));
            batch = new TableBatchOperation();
            batch.Replace(replaceEntity);
            this.repTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            result = this.repTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(replaceEntity.Properties["replaceProp"], retrievedEntity.Properties["replaceProp"]);

            // Delete Entity
            batch = new TableBatchOperation();
            batch.Delete(retrievedEntity);
            this.repTable.ExecuteBatch(batch);

            // Retrieve Entity
            result = this.repTable.ExecuteBatch(retrieveBatch).First();
            Assert.IsNull(result.Result);
        }
        public void TableBatchDeleteSyncUsingRetrieve()
        {
            // Insert Entity
            Console.WriteLine("Calling Insert()...");
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("replace test", "foo");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            this.repTable.Execute(TableOperation.Insert(baseEntity));

            // Retrieve existing entities using Retrieve
            Console.WriteLine("Calling Retrieve()...");
            TableResult result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(baseEntity.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);

            TableBatchOperation batch = new TableBatchOperation();

            // Add delete
            batch.Delete(retrievedEntity);

            Console.WriteLine("Calling ExecuteBatch() to delete...");
            IList<TableResult> results = this.repTable.ExecuteBatch(batch);
            Assert.AreEqual(results.Count, 1);
            Assert.AreEqual(results.First().HttpStatusCode, (int)HttpStatusCode.NoContent);
        }
        public void TableBatchInsertOrMergeSync()
        {
            // Insert Or Merge with no pre-existing entity
            DynamicReplicatedTableEntity insertOrMergeEntity = new DynamicReplicatedTableEntity("batchInsertOrMerge entity", "foo");
            insertOrMergeEntity.Properties.Add("prop1", new EntityProperty("value1"));

            TableBatchOperation batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            IList<TableResult> batchResultList = this.repTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            TableResult result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties.Count, retrievedEntity.Properties.Count);

            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(insertOrMergeEntity.PartitionKey,
                                                                      insertOrMergeEntity.RowKey,
                                                                      batchResultList[0].Etag,
                                                                      retrievedEntity.Properties);
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));

            TableBatchOperation batch2 = new TableBatchOperation();
            batch2.InsertOrMerge(mergeEntity);
            this.repTable.ExecuteBatch(batch2);

            // Retrieve Entity & Verify Contents
            result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(2, retrievedEntity.Properties.Count, "retrievedEntity.Properties.Count={0}. (Expecting 2)", retrievedEntity.Properties.Count);

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
        }
        public void TableBatchDeleteSyncUsingExecuteQuery()
        {
            // Insert Entity
            Console.WriteLine("Calling Insert()...");
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("replace test", "foo");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            this.repTable.Execute(TableOperation.Insert(baseEntity));

            TableBatchOperation batch = new TableBatchOperation();

            // Retrieve existing entities using TableQuery
            TableQuery<DynamicReplicatedTableEntity> query = new TableQuery<DynamicReplicatedTableEntity>().Where(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, baseEntity.PartitionKey));

            IEnumerable<DynamicReplicatedTableEntity> allEntities = this.repTable.ExecuteQuery<DynamicReplicatedTableEntity>(query);
            foreach (DynamicReplicatedTableEntity entity in allEntities)
            {
                entity.ETag = entity._rtable_Version.ToString();
                // Add delete
                batch.Delete(entity);
            }

            Console.WriteLine("Calling ExecuteBatch() to delete...");
            IList<TableResult> results = this.repTable.ExecuteBatch(batch);
            Assert.AreEqual(results.Count, 1);
            Assert.AreEqual(results.First().HttpStatusCode, (int)HttpStatusCode.NoContent);
        }
Example #13
0
        public void MergeUsingLargerViewId()
        {
            long currentViewId = 100;
            long futureViewId = currentViewId + 1;
            int expectedVersion = 1;

            this.UpdateConfiguration(replicas, 0, false, currentViewId);

            // Insert Entity
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("merge test02", "foo02");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            Console.WriteLine("Calling TableOperation.Insert()...");
            TableResult result = this.repTable.Execute(TableOperation.Insert(baseEntity));
            Assert.AreNotEqual(null, result, "Insert(): result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "Insert(): result.HttpStatusCode mismatch");

            //
            // Call ModifyConfigurationBlob to change the viewId of the wrapper to a larger value
            //
            Console.WriteLine("Changing the viewId to futureViewId {0}", futureViewId);
            this.UpdateConfiguration(replicas, 0, false, futureViewId);

            //
            // Merge
            //
            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag };
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
            Console.WriteLine("\nCalling TableOperation.Merge() with a larger viewId...");
            result = this.repTable.Execute(TableOperation.Merge(mergeEntity));
            expectedVersion++;
            Assert.AreNotEqual(null, result, "Merge(): result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "Merge(): result.HttpStatusCode mismatch");

            //
            // InsertOrMerge
            //
            DynamicReplicatedTableEntity mergeEntity2 = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag };
            mergeEntity2.Properties.Add("prop3", new EntityProperty("value3"));
            Console.WriteLine("\nCalling TableOperation.InsertOrMerge() with a larger viewId...");
            result = this.repTable.Execute(TableOperation.InsertOrMerge(mergeEntity2));
            expectedVersion++;
            Assert.AreNotEqual(null, result, "InsertOrMerge(): result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "InsertOrMerge(): result.HttpStatusCode mismatch");

            // Retrieve Entity & Verify Contents
            Console.WriteLine("\nCalling TableOperation.Retrieve() with a larger viewId...");
            result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            Assert.AreNotEqual(null, result, "Retrieve(): result = null");
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity, "retrievedEntity = null");
            Assert.AreEqual(3, retrievedEntity.Properties.Count, "Properties.Count mismatch");
            Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"], "Properties[prop1] mismatch");
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"], "Properties[prop2] mismatch");
            Assert.AreEqual(mergeEntity2.Properties["prop3"], retrievedEntity.Properties["prop3"], "Properties[prop3] mismatch");
            Assert.AreEqual(futureViewId, retrievedEntity._rtable_ViewId, "retrievedEntity._rtable_ViewId mismatch");
            Assert.AreEqual(expectedVersion, retrievedEntity._rtable_Version, "retrievedEntity._rtable_Version mismatch");
        }
Example #14
0
        public void RTableMergeSync()
        {
            // Insert Entity
            Console.WriteLine("Calling TableOperation.Insert()...");
            ReplicatedTable currentTable = this.repTable;
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("merge test01", "foo01");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            TableResult result = currentTable.Execute(TableOperation.Insert(baseEntity));
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "result.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, result, "result = null");
            Assert.AreEqual("1", result.Etag, "result.Etag mismatch");

            // Retrieve Entity & Verify Contents
            Console.WriteLine("Calling TableOperation.Retrieve()...");
            result = currentTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            Assert.AreNotEqual(null, result, "result = null");
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity, "retrievedEntity = null");

            DynamicReplicatedTableEntity row = retrievedEntity;
            Assert.AreEqual(false, row._rtable_RowLock, "row._rtable_RowLock mismatch");
            Assert.AreEqual(1, row._rtable_Version, "row._rtable_Version mismatch");
            Assert.AreEqual(false, row._rtable_Tombstone, "row._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, row._rtable_ViewId, "row._rtable_ViewId mismatch");

            // Merge
            Console.WriteLine("Calling TableOperation.Merge()...");
            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag };
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
            result = currentTable.Execute(TableOperation.Merge(mergeEntity));

            Assert.AreNotEqual(null, result, "result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "result.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, result.Result, "result.Result = null");
            Assert.AreEqual("2", result.Etag, "result.Etag mismatch");

            row = (DynamicReplicatedTableEntity)result.Result;
            Assert.AreEqual(false, row._rtable_RowLock, "row._rtable_RowLock mismatch");
            Assert.AreEqual(2, row._rtable_Version, "row._rtable_Version mismatch");
            Assert.AreEqual(false, row._rtable_Tombstone, "row._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, row._rtable_ViewId, "row._rtable_ViewId mismatch");

            // Retrieve Entity & Verify Contents
            Console.WriteLine("Calling TableOperation.Retrieve() after Merge() was called...");
            result = currentTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            Assert.AreNotEqual(null, result, "result = null");
            Assert.AreEqual((int)HttpStatusCode.OK, result.HttpStatusCode, "result.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, result.Result, "result.Result = null");

            retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity, "retrievedEntity = null");

            row = retrievedEntity;
            Assert.AreEqual(false, row._rtable_RowLock, "row._rtable_RowLock mismatch");
            Assert.AreEqual(2, row._rtable_Version, "row._rtable_Version mismatch");
            Assert.AreEqual(false, row._rtable_Tombstone, "row._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, row._rtable_ViewId, "row._rtable_ViewId mismatch");
            Assert.AreEqual(2, retrievedEntity.Properties.Count, "retrievedEntity.Properties.Count mismatch");
            Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"], "Properties[prop1] mismatch");
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"], "Properties[prop2] mismatch");
        }
Example #15
0
        public void RTableInsertOrReplaceSync()
        {
            string firstName = "FirstName01";
            string lastName = "LastName01";
            string email = "*****@*****.**";
            string phone = "1-800-123-0001";

            string dynamicFirstName = "DynFirstName01";
            string dynamicLastName = "DynLastName01";
            string dynamicEmail = "*****@*****.**";
            string dynamicPhone = "1-800-123-0002";

            // Insert entity
            CustomerEntity newCustomer = new CustomerEntity(firstName, lastName);
            newCustomer.Email = email;
            newCustomer.PhoneNumber = phone;

            TableOperation operation = TableOperation.Insert(newCustomer);
            TableResult result = repTable.Execute(operation);
            Assert.AreNotEqual(null, result, "result = null");
            ReplicatedTableEntity row = (ReplicatedTableEntity)result.Result;
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "result.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, result.Result, "result.Result = null");
            Assert.AreEqual("1", result.Etag, "result.Etag mismatch");
            Assert.AreEqual(false, row._rtable_RowLock, "row._rtable_RowLock mismatch");
            Assert.AreEqual(1, row._rtable_Version, "row._rtable_Version mismatch");
            Assert.AreEqual(false, row._rtable_Tombstone, "row._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, row._rtable_ViewId, "row._rtable_ViewId mismatch");

            //Non-generic retrieve
            operation = TableOperation.Retrieve(firstName, lastName);
            TableResult retrievedResult = this.repTable.Execute(operation);
            Assert.AreNotEqual(null, retrievedResult, "retrievedResult = null");
            Assert.IsTrue(retrievedResult.Result is IReplicatedTableEntity, "Expected entity to be of type IReplicatedTableEntity");
            DynamicReplicatedTableEntity readRow = retrievedResult.Result as DynamicReplicatedTableEntity;
            Assert.IsTrue(readRow.ETag == "1", "Returned etag is not zero");
            Assert.IsTrue(readRow.Properties.ContainsKey("Email"), "DynamicRTableEntity returned didnt contain Email");
            Assert.IsTrue(readRow.Properties.ContainsKey("PhoneNumber"), "DynamicRTableEntity returned didnt contain PhoneNumber");
            Assert.IsTrue(readRow.Properties.Count == 2, "DynamicRTableEntity returned contained diff number of properties");

            ////Dynamic insert entity
            DynamicReplicatedTableEntity newDynamicCustomer = new DynamicReplicatedTableEntity(dynamicFirstName, dynamicLastName);
            newDynamicCustomer.Properties["Email"] = EntityProperty.CreateEntityPropertyFromObject(dynamicEmail);
            newDynamicCustomer.Properties["PhoneNumber"] = EntityProperty.CreateEntityPropertyFromObject(dynamicPhone);

            operation = TableOperation.Insert(newDynamicCustomer);
            result = repTable.Execute(operation);
            Assert.AreNotEqual(null, result, "result = null");
            row = (DynamicReplicatedTableEntity)result.Result;
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "result.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, result.Result, "result.Result = null");
            Assert.AreEqual("1", result.Etag, "result.Etag mismatch");
            Assert.AreEqual(false, row._rtable_RowLock, "row._rtable_RowLock mismatch");
            Assert.AreEqual(1, row._rtable_Version, "row._rtable_Version mismatch");
            Assert.AreEqual(false, row._rtable_Tombstone, "row._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, row._rtable_ViewId, "row._rtable_ViewId mismatch");

            //Non-generic retrieve for dynamic entity
            operation = TableOperation.Retrieve(dynamicFirstName, dynamicLastName);
            retrievedResult = this.repTable.Execute(operation);
            Assert.AreNotEqual(null, retrievedResult, "retrievedResult = null");
            Assert.IsTrue(retrievedResult.Result is IReplicatedTableEntity, "Expected entity to be of type IReplicatedTableEntity");
            readRow = retrievedResult.Result as DynamicReplicatedTableEntity;
            Assert.IsTrue(readRow.ETag == "1", "Returned etag is not zero");
            Assert.IsTrue(readRow.Properties.ContainsKey("Email"), "DynamicRTableEntity returned didnt contain Email");
            Assert.IsTrue(readRow.Properties.ContainsKey("PhoneNumber"), "DynamicRTableEntity returned didnt contain PhoneNumber");
            Assert.IsTrue(readRow.Properties.Count == 2, "DynamicRTableEntity returned contained diff number of properties");

            // Retrieve entity
            operation = TableOperation.Retrieve<CustomerEntity>(firstName, lastName);
            retrievedResult = this.repTable.Execute(operation);
            Assert.AreNotEqual(null, retrievedResult, "retrievedResult = null");
            CustomerEntity customer = (CustomerEntity)retrievedResult.Result;

            Assert.AreEqual((int)HttpStatusCode.OK, retrievedResult.HttpStatusCode, "retrievedResult.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, retrievedResult.Result, "retrievedResult.Result = null");
            Assert.AreEqual("1", retrievedResult.Etag, "retrievedResult.Etag mismatch");
            Assert.AreEqual(false, customer._rtable_RowLock, "customer._rtable_RowLock mismatch");
            Assert.AreEqual(1, customer._rtable_Version, "customer._rtable_Version mismatch");
            Assert.AreEqual(false, customer._rtable_Tombstone, "customer._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, customer._rtable_ViewId, "customer._rtable_ViewId mismatch");
            Assert.AreEqual(newCustomer.PhoneNumber, customer.PhoneNumber, "customer.PhoneNumber mismatch");
            Assert.AreEqual(newCustomer.Email, customer.Email, "customer.Email mismatch");

            // Update the entity
            email = "*****@*****.**";
            phone = "1-800-456-0001";
            newCustomer = new CustomerEntity(firstName, lastName);
            newCustomer.Email = email;
            newCustomer.PhoneNumber = phone;

            // InsertOrReplace
            Console.WriteLine("Calling TableOperation.InsertOrReplace(newCustomer)...");
            operation = TableOperation.InsertOrReplace(newCustomer);
            result = this.repTable.Execute(operation);
            Assert.AreNotEqual(result, null);
            row = (ReplicatedTableEntity)result.Result;

            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "result.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, result.Result, "result.Result = null");
            Assert.AreEqual("2", result.Etag, "result.Etag mismatch");
            Assert.AreEqual(false, row._rtable_RowLock, "row._rtable_RowLock mismatch");
            Assert.AreEqual(2, row._rtable_Version, "row._rtable_Version mismatch");
            Assert.AreEqual(false, row._rtable_Tombstone, "row._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, row._rtable_ViewId, "row._rtable_ViewId mismatch");

            // Retrieve entity
            Console.WriteLine("Calling Retrieve...");
            operation = TableOperation.Retrieve<CustomerEntity>(firstName, lastName);
            retrievedResult = this.repTable.Execute(operation);
            Assert.AreNotEqual(null, retrievedResult, "retrievedResult = null");

            customer = (CustomerEntity)retrievedResult.Result;
            Assert.AreEqual((int)HttpStatusCode.OK, retrievedResult.HttpStatusCode, "retrievedResult.HttpStatusCode mismatch");
            Assert.AreNotEqual(null, retrievedResult.Result, "retrievedResult.Result = null");
            Assert.AreEqual("2", retrievedResult.Etag, "retrievedResult.Etag mismatch");
            Assert.AreEqual(false, customer._rtable_RowLock, "customer._rtable_RowLock mismatch");
            Assert.AreEqual(2, customer._rtable_Version, "customer._rtable_Version mismatch");
            Assert.AreEqual(false, customer._rtable_Tombstone, "customer._rtable_Tombstone mismatch");
            Assert.AreEqual(this.rtableTestConfiguration.RTableInformation.ViewId, customer._rtable_ViewId, "customer._rtable_ViewId mismatch");
            Assert.AreEqual(newCustomer.PhoneNumber, customer.PhoneNumber, "customer.PhoneNumber mismatch");
            Assert.AreEqual(newCustomer.Email, customer.Email, "customer.Email mismatch");
        }
Example #16
0
        public void RTableInsertOrMergeSync()
        {
            // Insert Entity
            ReplicatedTable currentTable = this.repTable;
            DynamicReplicatedTableEntity baseEntity = new DynamicReplicatedTableEntity("merge test02", "foo02");
            baseEntity.Properties.Add("prop1", new EntityProperty("value1"));
            Console.WriteLine("Calling TableOperation.Insert()...");
            TableResult result = currentTable.Execute(TableOperation.Insert(baseEntity));
            Assert.AreNotEqual(null, result, "Insert(): result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "Insert(): result.HttpStatusCode mismatch");

            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag };
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));
            Console.WriteLine("Calling TableOperation.Merge()...");
            result = currentTable.Execute(TableOperation.Merge(mergeEntity));
            Assert.AreNotEqual(null, result, "Merge(): result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "Merge(): result.HttpStatusCode mismatch");

            DynamicReplicatedTableEntity mergeEntity2 = new DynamicReplicatedTableEntity(baseEntity.PartitionKey, baseEntity.RowKey) { ETag = result.Etag };
            mergeEntity2.Properties.Add("prop3", new EntityProperty("value3"));
            Console.WriteLine("Calling TableOperation.InsertOrMerge()...");
            result = currentTable.Execute(TableOperation.InsertOrMerge(mergeEntity2));
            Assert.AreNotEqual(null, result, "InsertOrMerge(): result = null");
            Assert.AreEqual((int)HttpStatusCode.NoContent, result.HttpStatusCode, "InsertOrMerge(): result.HttpStatusCode mismatch");

            // Retrieve Entity & Verify Contents
            Console.WriteLine("Calling TableOperation.Retrieve()...");
            result = currentTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(baseEntity.PartitionKey, baseEntity.RowKey));
            Assert.AreNotEqual(null, result, "Retrieve(): result = null");
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;

            Assert.IsNotNull(retrievedEntity, "retrievedEntity = null");
            Assert.AreEqual(3, retrievedEntity.Properties.Count, "Properties.Count mismatch");
            Assert.AreEqual(baseEntity.Properties["prop1"], retrievedEntity.Properties["prop1"], "Properties[prop1] mismatch");
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"], "Properties[prop2] mismatch");
            Assert.AreEqual(mergeEntity2.Properties["prop3"], retrievedEntity.Properties["prop3"], "Properties[prop3] mismatch");

            // InitDynamicReplicatedTableEntity Insert
            currentTable = this.repTable;
            IDictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
            properties.Add("Name", EntityProperty.GeneratePropertyForString("Cisco-ASR-1006"));
            properties.Add("Description", EntityProperty.GeneratePropertyForString("Cisco ASR 1006 Router"));
            properties.Add("MaxSubInterfaces", EntityProperty.GeneratePropertyForInt(1000));
            properties.Add("MaxTunnelInterfaces", EntityProperty.GeneratePropertyForInt(4000));
            properties.Add("MaxVrfs", EntityProperty.GeneratePropertyForInt(4000));
            properties.Add("MaxBfdSessions", EntityProperty.GeneratePropertyForInt(4000));

            InitDynamicReplicatedTableEntity initEntity = new InitDynamicReplicatedTableEntity("0", "devicetype__Cisco-ASR-1006", null, properties);
            TableOperation insert = TableOperation.Insert(initEntity);
            result = currentTable.Execute(insert);
            Assert.IsTrue(result.HttpStatusCode == (int)HttpStatusCode.NoContent);
        }