Пример #1
0
        public void PropertyHasBeenAdded()
        {
            // Arrange
            IStorageTableClient client = CreateTableClient();
            IStorageTable       table  = client.GetTableReference("table");
            StubTableEntityWriter <DynamicTableEntity> writer = new StubTableEntityWriter <DynamicTableEntity>();
            Type valueType = typeof(TableEntityWriter <DynamicTableEntity>);
            TableEntityCollectorBinder <DynamicTableEntity> product = new TableEntityCollectorBinder <DynamicTableEntity>(table, writer, valueType);

            DynamicTableEntity value = new DynamicTableEntity
            {
                PartitionKey = "PK",
                RowKey       = "RK",
                Properties   = new Dictionary <string, EntityProperty> {
                    { "Item", new EntityProperty("Foo") }
                }
            };

            writer.Add(value);

            // Act
            var parameterLog = product.GetStatus() as TableParameterLog;

            // Assert
            Assert.Equal(1, parameterLog.EntitiesWritten);
            Assert.Equal(0, writer.TimesPartitionFlushed);
        }
Пример #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 TableEntity_IfBoundToExistingDynamicTableEntity_Binds()
        {
            // Arrange
            const string    expectedKey   = "abc";
            const int       expectedValue = 123;
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

            IStorageTable table = CreateTable(account, 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 Task <IValueProvider> BindAsync(BindingContext context)
        {
            string        boundTableName = _path.Bind(context.BindingData);
            IStorageTable table          = _client.GetTableReference(boundTableName);

            return(BindTableAsync(table, context.ValueContext));
        }
        public void PropertyHasBeenAdded()
        {
            // Arrange
            IStorageTableClient            client = new StorageAccount(CloudStorageAccount.DevelopmentStorageAccount).CreateTableClient();
            IStorageTable                  table  = client.GetTableReference("table");
            PocoEntityWriter <SimpleClass> writer = new PocoEntityWriter <SimpleClass>(table);

            writer.TableEntityWriter = new StubTableEntityWriter();
            Type valueType = typeof(PocoEntityWriter <SimpleClass>);
            PocoEntityCollectorBinder <SimpleClass> product = new PocoEntityCollectorBinder <SimpleClass>(table, writer, valueType);

            SimpleClass value = new SimpleClass
            {
                PartitionKey = "PK",
                RowKey       = "RK"
            };

            writer.Add(value);

            // Act
            var parameterLog = product.GetStatus() as TableParameterLog;

            // Assert
            Assert.Equal(1, parameterLog.EntitiesWritten);
        }
Пример #6
0
        public void MaximumBatchSizeFlushes()
        {
            // Arrange
            IStorageTableClient client = new StorageAccount(CloudStorageAccount.DevelopmentStorageAccount).CreateTableClient();
            IStorageTable       table  = client.GetTableReference("table");
            StubTableEntityWriter <DynamicTableEntity> writer = new StubTableEntityWriter <DynamicTableEntity>();
            Type valueType = typeof(TableEntityWriter <DynamicTableEntity>);
            TableEntityCollectorBinder <DynamicTableEntity> product = new TableEntityCollectorBinder <DynamicTableEntity>(table, writer, valueType);

            DynamicTableEntity value = new DynamicTableEntity
            {
                PartitionKey = "PK",
                RowKey       = "RK",
                Properties   = new Dictionary <string, EntityProperty> {
                    { "Item", new EntityProperty("Foo") }
                }
            };

            for (int i = 0; i < TableEntityWriter <ITableEntity> .MaxBatchSize + 1; i++)
            {
                value.RowKey = "RK" + i;
                writer.Add(value);
            }

            // Act
            var parameterLog = product.GetStatus() as TableParameterLog;

            // Assert
            Assert.Equal(TableEntityWriter <ITableEntity> .MaxBatchSize + 1, parameterLog.EntitiesWritten);
            Assert.Equal(1, writer.TimesPartitionFlushed);
        }
            public Task <IValueProvider> BindAsync(IStorageTable value, ValueBindingContext context)
            {
                PocoEntityWriter <TElement> collector = new PocoEntityWriter <TElement>(value);
                IValueProvider provider = new PocoEntityCollectorBinder <TElement>(value, collector, typeof(IAsyncCollector <TElement>));

                return(Task.FromResult(provider));
            }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
        public void TableEntity_IfUpdatesRowKey_Throws()
        {
            // Arrange
            IStorageAccount account      = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

            IStorageTable table = CreateTable(account, 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);
        }
Пример #11
0
        public void TableEntity_IfBoundToExistingPoco_Binds()
        {
            // Arrange
            const string    expectedValue = "abc";
            IStorageAccount account       = CreateFakeStorageAccount();
            IStorageQueue   triggerQueue  = CreateQueue(account, TriggerQueueName);

            triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore"));

            IStorageTable table = CreateTable(account, 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);
        }
Пример #12
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);
        }
Пример #13
0
        // Get the storage table from the attribute.
        private static IStorageTable GetTable(TableAttribute attribute)
        {
            var           tableClient = ((ResolvedTableAttribute)attribute).Client;
            IStorageTable table       = tableClient.GetTableReference(attribute.TableName);

            return(table);
        }
Пример #14
0
        private IAsyncCollector <ITableEntity> BuildFromTableAttribute(TableAttribute attribute)
        {
            IStorageTable table = GetTable(attribute);

            var writer = new TableEntityWriter <ITableEntity>(table);

            return(writer);
        }
Пример #15
0
        private static IStorageTable CreateTable(IStorageAccount account, string tableName)
        {
            IStorageTableClient client = account.CreateTableClient();
            IStorageTable       table  = client.GetTableReference(tableName);

            table.CreateIfNotExists();
            return(table);
        }
        private void CreateStorageEntries(IStorageTable storageTable)
        {
            StorageCreationCommandDictionary commands = storageTable.GetStorageCreationCommands();

            foreach (StorageCreationCommand cmd in commands.Values)
            {
                cmd.Execute();
            }
        }
 public Task<IValueProvider> BindAsync(IStorageTable value, ValueBindingContext context)
 {
     CloudTable table = null;
     if (value != null)
     {
         table = value.SdkObject;
     }
     return _binding.BindAsync(table, context);
 }
Пример #18
0
            async Task <CloudTable> IAsyncConverter <TableAttribute, CloudTable> .ConvertAsync(TableAttribute attribute, CancellationToken cancellation)
            {
                IStorageTable table = GetTable(attribute);
                await table.CreateIfNotExistsAsync(CancellationToken.None);

                var sdkTable = table.SdkObject;

                return(sdkTable);
            }
Пример #19
0
        public static bool Exists(this IStorageTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            return(table.ExistsAsync(CancellationToken.None).GetAwaiter().GetResult());
        }
Пример #20
0
        public static void CreateIfNotExists(this IStorageTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            table.CreateIfNotExistsAsync(CancellationToken.None).GetAwaiter().GetResult();
        }
            public Task <IValueProvider> BindAsync(IStorageTable value, ValueBindingContext context)
            {
                CloudTable table = null;

                if (value != null)
                {
                    table = value.SdkObject;
                }
                return(_binding.BindAsync(table, context));
            }
        public PocoEntityCollectorBinder(IStorageTable table, PocoEntityWriter <T> value, Type valueType)
        {
            if (value != null && !valueType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException("value is not of the correct type.");
            }

            _table     = table;
            _value     = value;
            _valueType = valueType;
        }
Пример #23
0
        public TableEntityCollectorBinder(IStorageTable table, TableEntityWriter <T> tableWriter, Type valueType)
        {
            if (tableWriter != null && !valueType.IsAssignableFrom(tableWriter.GetType()))
            {
                throw new InvalidOperationException("value is not of the correct type.");
            }

            _table       = table;
            _tableWriter = tableWriter;
            _valueType   = valueType;
        }
        public TableValueProvider(IStorageTable table, object value, Type valueType)
        {
            if (value != null && !valueType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException("value is not of the correct type.");
            }

            _table = table;
            _value = value;
            _valueType = valueType;
        }
Пример #25
0
        public TableValueProvider(IStorageTable table, object value, Type valueType)
        {
            if (value != null && !valueType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException("value is not of the correct type.");
            }

            _table     = table;
            _value     = value;
            _valueType = valueType;
        }
Пример #26
0
        public static void Replace(this IStorageTable table, ITableEntity entity)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            IStorageTableOperation operation = table.CreateReplaceOperation(entity);

            table.ExecuteAsync(operation, CancellationToken.None).GetAwaiter().GetResult();
        }
Пример #27
0
        public Task <IValueProvider> BindAsync(object value, ValueBindingContext context)
        {
            IStorageTable table = null;

            if (!_converter.TryConvert(value, out table))
            {
                throw new InvalidOperationException("Unable to convert value to IStorageTable.");
            }

            return(BindTableAsync(table, context));
        }
Пример #28
0
        public Task <IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string        boundTableName = _path.Bind(context.BindingData);
            IStorageTable table          = _client.GetTableReference(boundTableName);

            return(BindTableAsync(table, context.ValueContext));
        }
Пример #29
0
        public static TElement Retrieve <TElement>(this IStorageTable table, string partitionKey, string rowKey)
            where TElement : ITableEntity, new()
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            IStorageTableOperation operation = table.CreateRetrieveOperation <TElement>(partitionKey, rowKey);
            TableResult            result    = table.ExecuteAsync(operation, CancellationToken.None).GetAwaiter().GetResult();

            return((TElement)result.Result);
        }
Пример #30
0
        public bool TryConvert(object input, out IStorageTable output)
        {
            TInput typedInput = input as TInput;

            if (typedInput == null)
            {
                output = null;
                return(false);
            }

            output = _innerConverter.Convert(typedInput);
            return(true);
        }
        public Task <IValueProvider> BindAsync(BindingContext context)
        {
            TableEntityPath boundPath = _path.Bind(context.BindingData);
            IStorageTable   table     = _client.GetTableReference(boundPath.TableName);

            TableEntityContext entityContext = new TableEntityContext
            {
                Table        = table,
                PartitionKey = boundPath.PartitionKey,
                RowKey       = boundPath.RowKey
            };

            return(BindEntityAsync(entityContext, context.ValueContext));
        }
Пример #32
0
        public void ValueHasNotChanged()
        {
            // Arrange
            IStorageTableClient client = CreateTableClient();
            IStorageTable       table  = client.GetTableReference("table");
            StubTableEntityWriter <DynamicTableEntity> writer = new StubTableEntityWriter <DynamicTableEntity>();
            Type valueType = typeof(TableEntityWriter <DynamicTableEntity>);
            TableEntityCollectorBinder <DynamicTableEntity> product = new TableEntityCollectorBinder <DynamicTableEntity>(table, writer, valueType);

            // Act
            var parameterLog = product.GetStatus() as TableParameterLog;

            // Assert
            Assert.Null(parameterLog);
        }
Пример #33
0
 private Task<IValueProvider> BindTableAsync(IStorageTable value, ValueBindingContext context)
 {
     return _argumentBinding.BindAsync(value, context);
 }
 public Task<IValueProvider> BindAsync(IStorageTable value, ValueBindingContext context)
 {
     IValueProvider valueProvider = new TableValueProvider(value, value, typeof(IStorageTable));
     return Task.FromResult(valueProvider);
 }
 private void CreateStorageEntries(IStorageTable storageTable)
 {
     StorageCreationCommandDictionary commands = storageTable.GetStorageCreationCommands();
     foreach (StorageCreationCommand cmd in commands.Values)
     {
         cmd.Execute();
     }
 }
 public async Task<IValueProvider> BindAsync(IStorageTable value, ValueBindingContext context)
 {
     await value.CreateIfNotExistsAsync(context.CancellationToken);
     return new TableValueProvider(value, value.SdkObject, typeof(CloudTable));
 }