Ejemplo n.º 1
0
        public void TableEntity_IfUpdatesPoco_Persists()
        {
            // Arrange
            const string    originalValue = "abc";
            const string    expectedValue = "def";
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedValue));

            IStorageTable table = CreateTable(account, TableName);
            Dictionary <string, EntityProperty> originalProperties = new Dictionary <string, EntityProperty>
            {
                { "Value", new EntityProperty(originalValue) }
            };

            table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: originalProperties));

            // Act
            RunTrigger(account, typeof(UpdatePocoProgram));

            // Assert
            DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey);

            Assert.NotNull(entity);
            IDictionary <string, EntityProperty> properties = entity.Properties;

            Assert.NotNull(properties);
            Assert.True(properties.ContainsKey("Value"));
            EntityProperty property = properties["Value"];

            Assert.NotNull(property);
            Assert.Equal(EdmType.String, property.PropertyType);
            Assert.Equal(expectedValue, property.StringValue);
        }
Ejemplo n.º 2
0
        public void TableEntity_IfBoundToExistingPoco_Binds()
        {
            // Arrange
            const string    expectedValue = "abc";
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

            IStorageTable table = CreateTable(account, TableName);
            Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>
            {
                { "Value", new EntityProperty(expectedValue) }
            };

            table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: properties));

            // Act
            Poco result = RunTrigger <Poco>(account, typeof(BindToPocoProgram),
                                            (s) => BindToPocoProgram.TaskSource = s);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedValue, result.Value);
        }
Ejemplo n.º 3
0
        public void TableEntity_IfBoundToExistingDynamicTableEntity_Binds()
        {
            // Arrange
            const string    expectedKey   = "abc";
            const int       expectedValue = 123;
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

            IStorageTable table = CreateTable(account, TableName);
            Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>
            {
                { expectedKey, new EntityProperty(expectedValue) }
            };

            table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: properties));

            // Act
            DynamicTableEntity result = RunTrigger <DynamicTableEntity>(account, typeof(BindToDynamicTableEntityProgram),
                                                                        (s) => BindToDynamicTableEntityProgram.TaskSource = s);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(PartitionKey, result.PartitionKey);
            Assert.Equal(RowKey, result.RowKey);
            Assert.NotNull(result.Properties);
            Assert.True(result.Properties.ContainsKey(expectedKey));
            EntityProperty property = result.Properties[expectedKey];

            Assert.NotNull(property);
            Assert.Equal(EdmType.Int32, property.PropertyType);
            Assert.Equal(expectedValue, property.Int32Value);
        }
Ejemplo n.º 4
0
        public void TableEntity_IfUpdatesRowKey_Throws()
        {
            // Arrange
            IStorageAccount account      = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

            IStorageTable table = CreateTable(account, TableName);

            table.Insert(new DynamicTableEntity(PartitionKey, RowKey));

            // Act
            Exception exception = RunTriggerFailure(account, typeof(UpdatePocoRowKeyProgram));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidOperationException>(exception);
            Assert.Equal("Error while handling parameter entity after function returned:", exception.Message);
            Exception innerException = exception.InnerException;

            Assert.NotNull(innerException);
            Assert.IsType <InvalidOperationException>(innerException);
            Assert.Equal("When binding to a table entity, the row key must not be changed.", innerException.Message);
        }
Ejemplo n.º 5
0
        public void TableEntity_IfUpdatesPoco_PersistsUsingNativeTableTypes()
        {
            // Arrange
            byte[]          originalValue = new byte[] { 0x12, 0x34 };
            byte[]          expectedValue = new byte[] { 0x56, 0x78 };
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedValue));

            IStorageTable table = CreateTable(account, TableName);
            Dictionary <string, EntityProperty> originalProperties = new Dictionary <string, EntityProperty>
            {
                { "Value", new EntityProperty(originalValue) }
            };

            table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: originalProperties));

            // Act
            RunTrigger(account, typeof(UpdatePocoWithByteArrayValueProgram));

            // Assert
            DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey);

            Assert.NotNull(entity);
            IDictionary <string, EntityProperty> properties = entity.Properties;

            Assert.NotNull(properties);
            Assert.True(properties.ContainsKey("Value"));
            EntityProperty property = properties["Value"];

            Assert.NotNull(property);
            Assert.Equal(EdmType.Binary, property.PropertyType);
            Assert.Equal(expectedValue, property.BinaryValue);
        }
Ejemplo n.º 6
0
        public void TableEntity_IfBoundUsingRouteParameters_Binds()
        {
            // Arrange
            IStorageAccount    account      = CreateFakeStorageAccount();
            IStorageQueue      triggerQueue = CreateQueue(account, TriggerQueueName);
            const string       tableName    = TableName + "B";
            const string       partitionKey = PartitionKey + "B";
            const string       rowKey       = RowKey + "B";
            TableEntityMessage message      = new TableEntityMessage
            {
                TableName    = tableName,
                PartitionKey = partitionKey,
                RowKey       = rowKey
            };

            triggerQueue.AddMessage(triggerQueue.CreateMessage(JsonConvert.SerializeObject(message)));

            IStorageTable table = CreateTable(account, tableName);
            Dictionary <string, EntityProperty> originalProperties = new Dictionary <string, EntityProperty>
            {
                { "Value", new EntityProperty(123) }
            };

            table.Insert(new DynamicTableEntity(partitionKey, rowKey, etag: null, properties: originalProperties));

            // Act
            RunTrigger(account, typeof(BindUsingRouteParametersProgram));

            // Assert
            DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(partitionKey, rowKey);

            Assert.NotNull(entity);
            IDictionary <string, EntityProperty> properties = entity.Properties;

            Assert.NotNull(properties);
            Assert.True(properties.ContainsKey("Value"));
            EntityProperty property = properties["Value"];

            Assert.NotNull(property);
            Assert.Equal(EdmType.Int32, property.PropertyType);
            Assert.True(property.Int32Value.HasValue);
            Assert.Equal(456, property.Int32Value.Value);
        }
Ejemplo n.º 7
0
        public void Table_IfBoundToIQueryableDynamicTableEntityAndExists_Binds()
        {
            // Arrange
            Guid            expectedValue = Guid.NewGuid();
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable       table  = client.GetTableReference(TableName);

            table.CreateIfNotExists();
            Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>
            {
                { PropertyName, new EntityProperty(expectedValue) }
            };

            table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: properties));

            // Act
            IQueryable <DynamicTableEntity> result = RunTrigger <IQueryable <DynamicTableEntity> >(account,
                                                                                                   typeof(BindToIQueryableDynamicTableEntityProgram),
                                                                                                   (s) => BindToIQueryableDynamicTableEntityProgram.TaskSource = s);

            // Assert
            Assert.NotNull(result);
            DynamicTableEntity[] entities = result.ToArray();
            Assert.Equal(1, entities.Length);
            DynamicTableEntity entity = entities[0];

            Assert.NotNull(entity);
            Assert.Equal(PartitionKey, entity.PartitionKey);
            Assert.Equal(RowKey, entity.RowKey);
            Assert.NotNull(entity.Properties);
            Assert.True(entity.Properties.ContainsKey(PropertyName));
            EntityProperty property = entity.Properties[PropertyName];

            Assert.NotNull(property);
            Assert.Equal(EdmType.Guid, property.PropertyType);
            Assert.Equal(expectedValue, property.GuidValue);
        }