public void SerializablePropertyValueAccessorSetWithComplexFieldsTest(ISerializer serializer) { // Arrange var fieldInfo = typeof(EntityWithSerializableField).GetField(nameof(EntityWithSerializableField.DecimalValue)); var valueAccessor = new SerializableValueAccessor <EntityWithSerializableField>(fieldInfo, serializer); var entity = new EntityWithSerializableField(); // Act valueAccessor.SetValue(entity, new EntityProperty(serializer.Serialize(5))); // Assert Assert.Equal(5, entity.DecimalValue); }
public void SerializablePropertyValueAccessorGetWithComplexFieldsTest(ISerializer serializer) { //Arrange var fieldInfo = typeof(EntityWithSerializableField).GetField(nameof(EntityWithSerializableField.DecimalValue)); var valueAccessor = new SerializableValueAccessor <EntityWithSerializableField>(fieldInfo, serializer); var entity = new EntityWithSerializableField { DecimalValue = 5 }; // Act EntityProperty entityProperty = valueAccessor.GetValue(entity); // Assert Assert.NotNull(entityProperty.StringValue); Assert.Equal(entity.DecimalValue, serializer.Deserialize <decimal>(entityProperty.StringValue)); }
public void SerializablePropertyValueAccessorSetWithComplexPropertiesTest(ISerializer serializer) { // Arrange PropertyInfo propertyInfo = typeof(EntityWithSerializableProperty).GetProperty(nameof(EntityWithSerializableProperty.SerializableEntity)); var valueAccessor = new SerializableValueAccessor <EntityWithSerializableProperty>(propertyInfo, serializer); var entity = new EntityWithSerializableProperty(); // Act valueAccessor.SetValue(entity, new EntityProperty(serializer.Serialize(new SerializableEntity() { DecimalValue = 5 }))); // Assert Assert.Equal(5, entity.SerializableEntity.DecimalValue); }
public void SerializablePropertyValueAccessorGetWithComplexPropertiesTest(ISerializer serializer) { //Arrange PropertyInfo propertyInfo = typeof(EntityWithSerializableProperty).GetProperty(nameof(EntityWithSerializableProperty.SerializableEntity)); var valueAccessor = new SerializableValueAccessor <EntityWithSerializableProperty>(propertyInfo, serializer); var entity = new EntityWithSerializableProperty { SerializableEntity = new SerializableEntity() { DecimalValue = 2 } }; // Act EntityProperty entityProperty = valueAccessor.GetValue(entity); // Assert Assert.NotNull(entityProperty.StringValue); Assert.Equal(entity.SerializableEntity.DecimalValue, serializer.Deserialize <SerializableEntity>(entityProperty.StringValue).DecimalValue); }
/// <summary> /// Constructor. /// </summary> /// <param name="member">Entity member.</param> /// <param name="name">Member name.</param> /// <param name="serializer">Serializer.</param> internal SerializableProperty(MemberInfo member, string name, ISerializer serializer) { if (member == null) { throw new ArgumentNullException(nameof(member)); } if (serializer == null) { throw new ArgumentNullException(nameof(serializer)); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } IValueAccessor <T> accessor = new SerializableValueAccessor <T>(member, serializer); _getValue = accessor.GetValue; _setValue = accessor.SetValue; _memberName = name; }