public EntityProperty GetEntityProperty( AzureTableEntity entity, EntityPropertyAccessor propertyAccessor, bool isMergingOperation) { return(propertyAccessor.GetProperty(entity)); }
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); }
public EntityProperty GetEntityProperty( AzureTableEntity entity, EntityPropertyAccessor propertyAccessor, bool isMergingOperation) { return(_getEntityPropertyIsCalled?.Invoke(entity, propertyAccessor, isMergingOperation)); }
public void Test_that_converter_is_used_while_not_null_value_setting() { // Arrange var isConvertedFromStorageEverCalled = false; var converter = new StorageValueConverterMock( v => { isConvertedFromStorageEverCalled = true; return(v); }, v => v); var accessor = new EntityPropertyAccessor( nameof(TestEntity.Property), false, e => null, (e, v) => ((TestEntity)e).Property = (string)v, converter); var entity = new TestEntity(); var value = "Some value"; // Act accessor.SetProperty(entity, EntityProperty.GeneratePropertyForString(value)); // Assert Assert.AreEqual(value, entity.Property); Assert.IsTrue(isConvertedFromStorageEverCalled); }
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()}"); }
public void Test_that_value_type_merging_is_forbidden() { // Arrange var entityPropertyAccessor = new EntityPropertyAccessor( propertyName: "ValueTypeProperty", isValueType: true, getter: e => 123, setter: (e, v) => { }, converter: new PassThroughStorageValueConverter()); // Act/Assert Assert.ThrowsException <InvalidOperationException>(() => _strategy.GetEntityProperty(_entity, entityPropertyAccessor, isMergingOperation: true)); }
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); }
internal static ITranslationRule <TStoreObject, TEntity> MapTo <TStoreObject, TEntity>(this IStoragePropertyAccessor <TStoreObject, ExDateTime> storageTimeAccessor, IStoragePropertyAccessor <TStoreObject, ExTimeZone> storageTimeZoneAccessor, EntityPropertyAccessor <TEntity, ExDateTime> entityTimeAccessor, EntityPropertyAccessor <TEntity, string> entityIntendedTimeZoneIdAccessor, DateTimeHelper dateTimeHelper) where TStoreObject : IStoreObject where TEntity : IPropertyChangeTracker <Microsoft.Exchange.Entities.DataModel.PropertyBags.PropertyDefinition> { return(new StorageTimeZoneSensitiveTimeTranslationRule <TStoreObject, TEntity>(storageTimeAccessor, storageTimeZoneAccessor, entityTimeAccessor, entityIntendedTimeZoneIdAccessor, dateTimeHelper)); }
internal static ITranslationRule <TStoreObject, TEntity> MapTo <TStoreObject, TEntity, TValue>(this IStoragePropertyAccessor <TStoreObject, TValue> storageAccessor, EntityPropertyAccessor <TEntity, TValue> entityAccessor) where TEntity : IPropertyChangeTracker <Microsoft.Exchange.Entities.DataModel.PropertyBags.PropertyDefinition> { return(new PassThruPropertyTranslationRule <TStoreObject, TEntity, Microsoft.Exchange.Data.PropertyDefinition, TValue>(storageAccessor, entityAccessor)); }
internal static ITranslationRule <TStoreObject, TEntity> MapTo <TStoreObject, TEntity, TStorageValue, TEntityValue, TConverter>(this IStoragePropertyAccessor <TStoreObject, TStorageValue> storageAccessor, EntityPropertyAccessor <TEntity, TEntityValue> entityAccessor, TConverter converter) where TStoreObject : IStoreObject where TEntity : IPropertyChangeTracker <Microsoft.Exchange.Entities.DataModel.PropertyBags.PropertyDefinition> { IConverter <TStorageValue, TEntityValue> storageToEntityConverter = converter as IConverter <TStorageValue, TEntityValue>; IConverter <TEntityValue, TStorageValue> entityToStorageConverter = converter as IConverter <TEntityValue, TStorageValue>; return(storageAccessor.MapTo(entityAccessor, storageToEntityConverter, entityToStorageConverter)); }