private IAsyncCollector <ITableEntity> BuildFromTableAttribute(TableAttribute attribute) { var table = GetTable(attribute); var writer = new TableEntityWriter <ITableEntity>(table); return(writer); }
public async Task FlushAfterAdd_PersistsEntity() { // Arrange var table = Mock.Of <TableClient>(); TableEntityWriter <ITableEntity> product = new TableEntityWriter <ITableEntity>(table); const string partitionKey = "PK"; const string rowKey = "RK"; TableEntity entity = new TableEntity(partitionKey, rowKey); product.Add(entity); // Act product.FlushAsync().GetAwaiter().GetResult(); // Assert TableEntity persisted = await table.GetEntityAsync <TableEntity>(partitionKey, rowKey); Assert.NotNull(persisted); }
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); }
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); }
internal static Document GetDocumentFromEntityProperties(IDictionary <string, EntityProperty> properties, string partitionKey, string rowKey, bool removeSystemGeneratedProperties) { if (properties == null) { throw new ArgumentException("Entity properties should not be null."); } if (string.IsNullOrEmpty(partitionKey) || string.IsNullOrEmpty(rowKey)) { throw new ArgumentException("Partition/row key should not be null"); } if (removeSystemGeneratedProperties) { if (properties.ContainsKey("Timestamp")) { properties.Remove("Timestamp"); } if (properties.ContainsKey("Etag")) { properties.Remove("Etag"); } } using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture)) { using (ITableEntityWriter tableEntityWriter = new TableEntityWriter(stringWriter)) { tableEntityWriter.Start(); foreach (KeyValuePair <string, EntityProperty> property in properties) { if (!property.Value.IsNull) { tableEntityWriter.WriteName(property.Key); switch (property.Value.PropertyType) { case EdmType.String: tableEntityWriter.WriteString(property.Value.StringValue); break; case EdmType.Binary: tableEntityWriter.WriteBinary(property.Value.BinaryValue); break; case EdmType.Boolean: tableEntityWriter.WriteBoolean(property.Value.BooleanValue); break; case EdmType.DateTime: tableEntityWriter.WriteDateTime(property.Value.DateTime); break; case EdmType.Double: tableEntityWriter.WriteDouble(property.Value.DoubleValue); break; case EdmType.Guid: tableEntityWriter.WriteGuid(property.Value.GuidValue); break; case EdmType.Int32: tableEntityWriter.WriteInt32(property.Value.Int32Value); break; case EdmType.Int64: tableEntityWriter.WriteInt64(property.Value.Int64Value); break; default: throw new Exception(string.Format(CultureInfo.CurrentCulture, "Unexpected Edm type '{0}'", (int)property.Value.PropertyType)); } } } tableEntityWriter.End(); } Document document = DeserializeObject <Document>(stringWriter.ToString()); document.Id = rowKey; document.SetPropertyValue("$pk", partitionKey); document.SetPropertyValue("$id", rowKey); return(document); } }