public async Task TableEntity_IfUpdatesRowKey_Throws()
        {
            // Arrange
            StorageAccount account      = CreateFakeStorageAccount();
            CloudQueue     triggerQueue = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage("ignore"));

            CloudTable table = await account.CreateTableAsync(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);
        }
        public async Task TableEntity_IfBoundToExistingPoco_Binds()
        {
            // Arrange
            const string   expectedValue = "abc";
            StorageAccount account       = CreateFakeStorageAccount();
            CloudQueue     triggerQueue  = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage("ignore"));

            CloudTable table = await account.CreateTableAsync(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);
        }
        public async Task TableEntity_IfBoundToExistingDynamicTableEntity_Binds()
        {
            // Arrange
            const string   expectedKey   = "abc";
            const int      expectedValue = 123;
            StorageAccount account       = CreateFakeStorageAccount();
            CloudQueue     triggerQueue  = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage("ignore"));

            CloudTable table = await account.CreateTableAsync(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);
        }
Пример #4
0
        public async Task Table_IfBoundToICollectorJObject_AddInsertsEntity()
        {
            // Arrange
            const string   expectedValue = "abc";
            StorageAccount account       = CreateFakeStorageAccount();
            CloudQueue     triggerQueue  = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage(expectedValue));

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

            // Assert
            CloudTableClient client = account.CreateCloudTableClient();
            CloudTable       table  = client.GetTableReference(TableName);

            Assert.True(await table.ExistsAsync());
            DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey);

            Assert.NotNull(entity);
            Assert.NotNull(entity.Properties);

            AssertPropertyValue(entity, "ValueStr", "abcdef");
            AssertPropertyValue(entity, "ValueNum", 123);
        }
Пример #5
0
        public async Task Table_IfBoundToICollectorPoco_AddInsertsEntity()
        {
            // Arrange
            const string   expectedValue = "abc";
            StorageAccount account       = CreateFakeStorageAccount();
            CloudQueue     triggerQueue  = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage(expectedValue));

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

            // Assert
            await AssertStringPropertyAsync(account, PropertyName, expectedValue);
        }
        public async Task TableEntity_IfBoundUsingRouteParameters_Binds()
        {
            // Arrange
            StorageAccount account      = CreateFakeStorageAccount();
            CloudQueue     triggerQueue = await account.CreateQueueAsync(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
            };
            await triggerQueue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(message)));

            CloudTable table = await account.CreateTableAsync(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);
        }
Пример #7
0
        public async Task Table_IfBoundToCloudTable_BindsAndCreatesTable()
        {
            // Arrange
            StorageAccount account      = CreateFakeStorageAccount();
            CloudQueue     triggerQueue = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage("ignore"));

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

            // Assert
            Assert.NotNull(result);
            Assert.Equal(TableName, result.Name);
            CloudTableClient client = account.CreateCloudTableClient();
            CloudTable       table  = client.GetTableReference(TableName);

            Assert.True(await table.ExistsAsync());
        }
        public async Task TableEntity_IfUpdatesPoco_Persists()
        {
            // Arrange
            const string   originalValue = "abc";
            const string   expectedValue = "def";
            StorageAccount account       = CreateFakeStorageAccount();
            CloudQueue     triggerQueue  = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage(expectedValue));

            CloudTable table = await account.CreateTableAsync(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);
        }
        public async Task TableEntity_IfUpdatesPoco_PersistsUsingNativeTableTypes()
        {
            // Arrange
            byte[]         originalValue = new byte[] { 0x12, 0x34 };
            byte[]         expectedValue = new byte[] { 0x56, 0x78 };
            StorageAccount account       = CreateFakeStorageAccount();
            CloudQueue     triggerQueue  = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(CloudQueueMessage.CreateCloudQueueMessageFromByteArray(expectedValue));

            CloudTable table = await account.CreateTableAsync(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);
        }
Пример #10
0
        public async Task Table_IfBoundToICollectorPoco_AddInsertsUsingNativeTableTypes()
        {
            // Arrange
            PocoWithAllTypes expected = new PocoWithAllTypes
            {
                PartitionKey                   = PartitionKey,
                RowKey                         = RowKey,
                BooleanProperty                = true,
                NullableBooleanProperty        = null,
                ByteArrayProperty              = new byte[] { 0x12, 0x34 },
                DateTimeProperty               = DateTime.Now,
                NullableDateTimeProperty       = null,
                DateTimeOffsetProperty         = DateTimeOffset.MaxValue,
                NullableDateTimeOffsetProperty = null,
                DoubleProperty                 = 3.14,
                NullableDoubleProperty         = null,
                GuidProperty                   = Guid.NewGuid(),
                NullableGuidProperty           = null,
                Int32Property                  = 123,
                NullableInt32Property          = null,
                Int64Property                  = 456,
                NullableInt64Property          = null,
                StringProperty                 = "abc",
                PocoProperty                   = new Poco
                {
                    PartitionKey = "def",
                    RowKey       = "ghi",
                    Property     = "jkl"
                }
            };
            StorageAccount account      = CreateFakeStorageAccount();
            CloudQueue     triggerQueue = await account.CreateQueueAsync(TriggerQueueName);

            await triggerQueue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(expected)));

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

            // Assert
            CloudTableClient client = account.CreateCloudTableClient();
            CloudTable       table  = client.GetTableReference(TableName);

            Assert.True(await table.ExistsAsync());
            DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey);

            Assert.Equal(expected.PartitionKey, entity.PartitionKey);
            Assert.Equal(expected.RowKey, entity.RowKey);
            IDictionary <string, EntityProperty> properties = entity.Properties;

            AssertNullablePropertyEqual(expected.BooleanProperty, EdmType.Boolean, properties, "BooleanProperty",
                                        (p) => p.BooleanValue);
            AssertPropertyNull(EdmType.Boolean, properties, "NullableBooleanProperty", (p) => p.BooleanValue);
            AssertPropertyEqual(expected.ByteArrayProperty, EdmType.Binary, properties, "ByteArrayProperty",
                                (p) => p.BinaryValue);
            AssertNullablePropertyEqual(expected.DateTimeProperty, EdmType.DateTime, properties, "DateTimeProperty",
                                        (p) => p.DateTime);
            AssertPropertyNull(EdmType.DateTime, properties, "NullableDateTimeProperty", (p) => p.DateTime);
            AssertNullablePropertyEqual(expected.DateTimeOffsetProperty, EdmType.DateTime, properties,
                                        "DateTimeOffsetProperty", (p) => p.DateTime);
            AssertPropertyNull(EdmType.DateTime, properties, "NullableDateTimeOffsetProperty",
                               (p) => p.DateTimeOffsetValue);
            AssertNullablePropertyEqual(expected.DoubleProperty, EdmType.Double, properties, "DoubleProperty",
                                        (p) => p.DoubleValue);
            AssertPropertyNull(EdmType.Double, properties, "NullableDoubleProperty", (p) => p.DoubleValue);
            AssertNullablePropertyEqual(expected.GuidProperty, EdmType.Guid, properties, "GuidProperty",
                                        (p) => p.GuidValue);
            AssertPropertyNull(EdmType.Guid, properties, "NullableGuidProperty", (p) => p.GuidValue);
            AssertNullablePropertyEqual(expected.Int32Property, EdmType.Int32, properties, "Int32Property",
                                        (p) => p.Int32Value);
            AssertPropertyNull(EdmType.Int32, properties, "NullableInt32Property", (p) => p.Int32Value);
            AssertNullablePropertyEqual(expected.Int64Property, EdmType.Int64, properties, "Int64Property",
                                        (p) => p.Int64Value);
            AssertPropertyNull(EdmType.Int64, properties, "NullableInt64Property", (p) => p.Int64Value);
            AssertPropertyEqual(expected.StringProperty, EdmType.String, properties, "StringProperty",
                                (p) => p.StringValue);
            AssertPropertyEqual(JsonConvert.SerializeObject(expected.PocoProperty, Formatting.Indented), EdmType.String,
                                properties, "PocoProperty", (p) => p.StringValue);
        }