public TableEntityValueBinder(TableEntityContext entityContext, ITableEntity entity, Type valueType)
 {
     _entityContext = entityContext;
     _value = entity;
     _valueType = valueType;
     _originalProperties = DeepClone(entity.WriteEntity(null));
 }
예제 #2
0
 public TableEntityValueBinder(TableEntityContext entityContext, ITableEntity entity, Type valueType)
 {
     _entityContext      = entityContext;
     _value              = entity;
     _valueType          = valueType;
     _originalProperties = DeepClone(entity.WriteEntity(null));
 }
예제 #3
0
 public PocoEntityValueBinder(TableEntityContext entityContext, string eTag, TElement value)
 {
     _entityContext      = entityContext;
     _eTag               = eTag;
     _value              = value;
     _originalProperties =
         TableEntityValueBinder.DeepClone(_converter.Convert(value).WriteEntity(operationContext: null));
 }
예제 #4
0
        public bool TryConvert(object input, out TableEntityContext output)
        {
            TInput typedInput = input as TInput;

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

            output = _innerConverter.Convert(typedInput);
            return(true);
        }
        public Task <IValueProvider> BindAsync(object value, ValueBindingContext context)
        {
            TableEntityContext entityContext = null;

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

            TableClient.ValidateAzureTableKeyValue(entityContext.PartitionKey);
            TableClient.ValidateAzureTableKeyValue(entityContext.RowKey);

            return(BindEntityAsync(entityContext, context));
        }
        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));
        }
예제 #7
0
        public async Task <IValueProvider> BindAsync(TableEntityContext value, ValueBindingContext context)
        {
            var         table    = value.Table;
            var         retrieve = table.CreateRetrieveOperation <TElement>(value.PartitionKey, value.RowKey);
            TableResult result   = await table.ExecuteAsync(retrieve, context.CancellationToken);

            TElement entity = (TElement)result.Result;

            if (entity == null)
            {
                return(new NullEntityValueProvider <TElement>(value));
            }

            return(new TableEntityValueBinder(value, entity, typeof(TElement)));
        }
        public void HasChanged_ReturnsFalse_IfValueHasNotChanged()
        {
            // Arrange
            TableEntityContext entityContext = new TableEntityContext();
            SimpleTableEntity value = new SimpleTableEntity { Item = "Foo" };
            Type valueType = typeof(SimpleTableEntity);
            PocoEntityValueBinder<SimpleTableEntity> product = new PocoEntityValueBinder<SimpleTableEntity>(
                entityContext, "etag", value);

            // Act
            bool hasChanged = product.HasChanged;

            // Assert
            Assert.False(hasChanged);
        }
예제 #9
0
        public async Task <IValueProvider> BindAsync(TableEntityContext value, ValueBindingContext context)
        {
            IStorageTable          table    = value.Table;
            IStorageTableOperation retrieve = table.CreateRetrieveOperation <DynamicTableEntity>(
                value.PartitionKey, value.RowKey);
            TableResult result = await table.ExecuteAsync(retrieve, context.CancellationToken);

            DynamicTableEntity entity = (DynamicTableEntity)result.Result;

            if (entity == null)
            {
                return(new NullEntityValueProvider <TElement>(value));
            }

            TElement userEntity = Converter.Convert(entity);

            return(new PocoEntityValueBinder <TElement>(value, entity.ETag, userEntity));
        }
예제 #10
0
        public Task <IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            TableEntityPath boundPath = _path.Bind(context.BindingData);
            var             table     = _client.GetTableReference(boundPath.TableName);

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

            return(BindEntityAsync(entityContext, context.ValueContext));
        }
        public void HasChanged_ReturnsFalse_IfValueHasNotChanged()
        {
            // Arrange
            TableEntityContext entityContext = new TableEntityContext();
            DynamicTableEntity value = new DynamicTableEntity
            {
                PartitionKey = "PK",
                RowKey = "RK",
                Properties = new Dictionary<string, EntityProperty> { { "Item", new EntityProperty("Foo") } }
            };
            Type valueType = typeof(DynamicTableEntity);
            TableEntityValueBinder product = new TableEntityValueBinder(entityContext, value, valueType);

            // Act
            bool hasChanged = product.HasChanged;

            // Assert
            Assert.False(hasChanged);
        }
        public Task<IValueProvider> BindAsync(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("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);
        }
        public void HasChanged_ReturnsTrue_IfMutuableValueHasBeenMutated()
        {
            // Arrange
            TableEntityContext entityContext = new TableEntityContext();
            byte[] bytes = new byte[] { 0x12 };
            DynamicTableEntity value = new DynamicTableEntity
            {
                PartitionKey = "PK",
                RowKey = "RK",
                Properties = new Dictionary<string, EntityProperty> { { "Item", new EntityProperty(bytes) } }
            };
            Type valueType = typeof(DynamicTableEntity);
            TableEntityValueBinder product = new TableEntityValueBinder(entityContext, value, valueType);

            bytes[0] = 0xFE;

            // Act
            bool hasChanged = product.HasChanged;

            // Assert
            Assert.True(hasChanged);
        }
 private Task <IValueProvider> BindEntityAsync(TableEntityContext entityContext, ValueBindingContext context)
 {
     return(_argumentBinding.BindAsync(entityContext, context));
 }
 private Task<IValueProvider> BindEntityAsync(TableEntityContext entityContext, ValueBindingContext context)
 {
     return _argumentBinding.BindAsync(entityContext, context);
 }
예제 #16
0
 public NullEntityValueProvider(TableEntityContext entityContext)
 {
     _entityContext = entityContext;
 }