public void Table_IfBoundToICollectorJObject_AddInsertsEntity()
        {
            // Arrange
            const string    expectedValue = "abc";
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

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

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

            // Assert
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable       table  = client.GetTableReference(TableName);

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

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

            AssertPropertyValue(entity, "ValueStr", "abcdef");
            AssertPropertyValue(entity, "ValueNum", 123);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
0
        public void Table_IfBoundToICollectorPoco_AddInsertsEntity()
        {
            // Arrange
            const string    expectedValue = "abc";
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

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

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

            // Assert
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable       table  = client.GetTableReference(TableName);

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

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

            Assert.NotNull(property);
            Assert.Equal(EdmType.String, property.PropertyType);
            Assert.Equal(expectedValue, property.StringValue);
        }
Exemple #5
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);
        }
Exemple #6
0
        public void FlushAfterAdd_PersistsEntity()
        {
            // Arrange
            IStorageAccount     account = CreateFakeStorageAccount();
            IStorageTableClient client  = account.CreateTableClient();
            IStorageTable       table   = client.GetTableReference("Table");

            TableEntityWriter <ITableEntity> product = new TableEntityWriter <ITableEntity>(table);
            const string       partitionKey          = "PK";
            const string       rowKey = "RK";
            DynamicTableEntity entity = new DynamicTableEntity(partitionKey, rowKey);

            product.Add(entity);

            // Act
            product.FlushAsync().GetAwaiter().GetResult();

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

            Assert.NotNull(persisted);
        }
        // Assert the given table has the given entity with PropertyName=ExpectedValue
        void AssertStringProperty(
            IStorageAccount account,
            string propertyName,
            string expectedValue,
            string tableName    = TableName,
            string partitionKey = PartitionKey,
            string rowKey       = RowKey)
        {
            // Assert
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable       table  = client.GetTableReference(tableName);

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

            Assert.NotNull(entity);
            Assert.NotNull(entity.Properties);
            Assert.True(entity.Properties.ContainsKey(propertyName));
            EntityProperty property = entity.Properties[propertyName];

            Assert.NotNull(property);
            Assert.Equal(EdmType.String, property.PropertyType);
            Assert.Equal(expectedValue, property.StringValue);
        }
        public void 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"
                }
            };
            IStorageAccount account      = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue = CreateQueue(account, TriggerQueueName);

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

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

            // Assert
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable       table  = client.GetTableReference(TableName);

            Assert.True(table.Exists());
            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);
        }