예제 #1
0
        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);
        }
예제 #2
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);
        }
예제 #3
0
        public void Table_IfBoundToCloudTable_BindsAndCreatesTable()
        {
            // Arrange
            IStorageAccount account = CreateFakeStorageAccount();
            IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName);
            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

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

            // Assert
            Assert.NotNull(result);
            Assert.Equal(TableName, result.Name);
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable table = client.GetTableReference(TableName);
            Assert.True(table.Exists());
        }
예제 #4
0
        public void Table_IfBoundToIQueryableDynamicTableEntityAndDoesNotExist_BindsAndDoesNotCreateTable()
        {
            // Arrange
            IStorageAccount account = CreateFakeStorageAccount();
            IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName);
            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

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

            // Assert
            Assert.NotNull(result);
            Assert.Empty(result);
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable table = client.GetTableReference(TableName);
            Assert.False(table.Exists());
        }
예제 #5
0
        // 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);
        }
예제 #6
0
        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);
        }