public static void Run([QueueTrigger(TriggerQueueName)] CloudQueueMessage message, [Table(TableName)] ICollector <PocoWithAllTypes> table) { PocoWithAllTypes entity = JsonConvert.DeserializeObject <PocoWithAllTypes>(message.AsString); table.Add(entity); }
public static void Run( [Table(TableNameExpression)] ICollector <PocoWithAllTypes> table, PocoWithAllTypes entity) { table.Add(entity); }
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); }
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.UtcNow, 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" } }; // Act await CallAsync <BindToICollectorPocoWithAllTypesProgram>(arguments : new { entity = expected }); // Assert TableEntity entity = await TableClient.GetEntityAsync <TableEntity>(PartitionKey, RowKey); Assert.AreEqual(expected.PartitionKey, entity.PartitionKey); Assert.AreEqual(expected.RowKey, entity.RowKey); AssertNullablePropertyEqual(expected.BooleanProperty, entity, "BooleanProperty"); AssertPropertyNull(entity, "NullableBooleanProperty"); AssertPropertyEqual(expected.ByteArrayProperty, entity, "ByteArrayProperty"); // TODO: behavior change. DateTime was the default type before AssertNullablePropertyEqual(new DateTimeOffset(expected.DateTimeProperty), entity, "DateTimeProperty"); AssertPropertyNull(entity, "NullableDateTimeProperty"); AssertNullablePropertyEqual(expected.DateTimeOffsetProperty, entity, "DateTimeOffsetProperty"); AssertPropertyNull(entity, "NullableDateTimeOffsetProperty"); AssertNullablePropertyEqual(expected.DoubleProperty, entity, "DoubleProperty"); AssertPropertyNull(entity, "NullableDoubleProperty"); AssertNullablePropertyEqual(expected.GuidProperty, entity, "GuidProperty"); AssertPropertyNull(entity, "NullableGuidProperty"); AssertNullablePropertyEqual(expected.Int32Property, entity, "Int32Property"); AssertPropertyNull(entity, "NullableInt32Property"); AssertNullablePropertyEqual(expected.Int64Property, entity, "Int64Property"); AssertPropertyNull(entity, "NullableInt64Property"); AssertPropertyEqual(expected.StringProperty, entity, "StringProperty"); AssertPropertyEqual(JsonConvert.SerializeObject(expected.PocoProperty, Formatting.Indented), entity, "PocoProperty"); }