Пример #1
0
        public EntityProperty GetEntityProperty(
            AzureTableEntity entity,
            EntityPropertyAccessor propertyAccessor,
            bool isMergingOperation)
        {
            if (!(isMergingOperation && propertyAccessor.IsValueType))
            {
                // It's not a merging operation or it's a reference type property

                return(propertyAccessor.GetProperty(entity));
            }

            // It's merging operation and it's value type property

            if (_dirtyProperties.ContainsKey(propertyAccessor.PropertyName))
            {
                // Property was changed, so update it in the storage

                return(propertyAccessor.GetProperty(entity));
            }

            // Property wasn't changed, so preserve storage value

            return(NullProperty);
        }
Пример #2
0
 public EntityProperty GetEntityProperty(
     AzureTableEntity entity,
     EntityPropertyAccessor propertyAccessor,
     bool isMergingOperation)
 {
     return(propertyAccessor.GetProperty(entity));
 }
        public void Test_that_converter_is_used_while_not_null_value_getting()
        {
            // Arrange
            var isConvertedToStorageEverCalled = false;
            var converter = new StorageValueConverterMock(
                v => v,
                v =>
            {
                isConvertedToStorageEverCalled = true;

                return(v);
            });
            var accessor = new EntityPropertyAccessor(
                nameof(TestEntity.Property),
                false,
                e => ((TestEntity)e).Property,
                (e, v) => ((TestEntity)e).Property = (string)v,
                converter);
            var entity = new TestEntity
            {
                Property = "Some value"
            };

            // Act
            var entityProperty = accessor.GetProperty(entity);

            // Assert
            Assert.IsNotNull(entityProperty);
            Assert.AreEqual(entity.Property, entityProperty.StringValue);
            Assert.IsTrue(isConvertedToStorageEverCalled);
        }
        public EntityProperty GetEntityProperty(
            AzureTableEntity entity,
            EntityPropertyAccessor propertyAccessor,
            bool isMergingOperation)
        {
            if (!(isMergingOperation && propertyAccessor.IsValueType))
            {
                return(propertyAccessor.GetProperty(entity));
            }

            throw new InvalidOperationException($"Merging of value types is forbidden. If you added value type property and do merging operation not accidentally, select different value type merging strategy for the entity type {entity.GetType()}");
        }
Пример #5
0
        public void Test_that_value_type_not_merging_operations_is_granted()
        {
            // Arrange
            var entityPropertyAccessor = new EntityPropertyAccessor(
                propertyName: "ValueTypeProperty",
                isValueType: true,
                getter: e => 123,
                setter: (e, v) => { },
                converter: new PassThroughStorageValueConverter());
            var expectedEntityProperty = entityPropertyAccessor.GetProperty(_entity);

            // Act
            var entityProperty = _strategy.GetEntityProperty(_entity, entityPropertyAccessor, isMergingOperation: false);

            // Assert
            Assert.AreEqual(expectedEntityProperty, entityProperty);
        }
        public void Test_that_reference_type_merging_is_passes_entity_property_through()
        {
            // Arrange
            var entityPropertyAccessor = new EntityPropertyAccessor(
                propertyName: "ReferenceTypeProperty",
                isValueType: false,
                getter: e => "123",
                setter: (e, v) => { },
                converter: new PassThroughStorageValueConverter());
            var expectedEntityProperty = entityPropertyAccessor.GetProperty(_entity);

            // Act
            var entityProperty = _strategy.GetEntityProperty(_entity, entityPropertyAccessor, isMergingOperation: true);

            // Assert
            Assert.AreEqual(expectedEntityProperty, entityProperty);
        }
        public void Test_that_not_dirty_value_type_property_merging_is_returns_null_entity_property()
        {
            // Arrange
            var entityPropertyAccessor = new EntityPropertyAccessor(
                propertyName: "ValueTypeProperty",
                isValueType: true,
                getter: e => 123,
                setter: (e, v) => { },
                converter: new PassThroughStorageValueConverter());
            var originalEntityProperty = entityPropertyAccessor.GetProperty(_entity);

            // Act
            var entityProperty = _strategy.GetEntityProperty(_entity, entityPropertyAccessor, isMergingOperation: true);

            // Assert
            Assert.IsNotNull(entityProperty);
            Assert.IsNull(entityProperty.PropertyAsObject);
            Assert.IsNotNull(originalEntityProperty);
        }