示例#1
0
        public void SetValue_IfInstanceIsNull_Throws()
        {
            // Arrange
            IPropertySetter <Poco, PocoProperty> product = CreateProductUnderTest <Poco, PocoProperty>(
                typeof(Poco).GetProperty("Value"));
            Poco         instance = null;
            PocoProperty value    = new PocoProperty();

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => product.SetValue(ref instance, value), "instance");
        }
        public TOutput Convert(ITableEntity input)
        {
            if (input == null)
            {
                return(default(TOutput));
            }

            TOutput result = new TOutput();

            if (_partitionKeySetter != null)
            {
                _partitionKeySetter.SetValue(ref result, input.PartitionKey);
            }

            if (_rowKeySetter != null)
            {
                _rowKeySetter.SetValue(ref result, input.RowKey);
            }

            if (_timestampSetter != null)
            {
                _timestampSetter.SetValue(ref result, input.Timestamp);
            }

            IDictionary <string, EntityProperty> properties = input.WriteEntity(operationContext: null);

            if (properties != null)
            {
                foreach (KeyValuePair <string, IPropertySetter <TOutput, EntityProperty> > pair in _otherPropertySetters)
                {
                    string propertyName = pair.Key;

                    if (properties.ContainsKey(propertyName))
                    {
                        IPropertySetter <TOutput, EntityProperty> setter = pair.Value;
                        Debug.Assert(setter != null);
                        EntityProperty propertyValue = properties[propertyName];
                        setter.SetValue(ref result, propertyValue);
                    }
                }
            }

            if (_eTagSetter != null)
            {
                _eTagSetter.SetValue(ref result, input.ETag);
            }

            return(result);
        }
示例#3
0
        public void SetValue_IfPrivateProperty_UpdatesValue()
        {
            // Arrange
            IPropertySetter <Poco, PocoProperty> product = CreateProductUnderTest <Poco, PocoProperty>(
                typeof(Poco).GetProperty("PrivateValue", BindingFlags.NonPublic | BindingFlags.Instance));
            Poco         instance = new Poco();
            PocoProperty expected = new PocoProperty();

            // Act
            product.SetValue(ref instance, expected);

            // Assert
            PocoProperty actual = instance.PrivateValueAsPublic;

            Assert.Same(expected, actual);
        }
示例#4
0
        public void SetValue_UpdatesValue()
        {
            // Arrange
            IPropertySetter <Poco, PocoProperty> product = CreateProductUnderTest <Poco, PocoProperty>(
                typeof(Poco).GetProperty("Value"));
            Poco         instance = new Poco();
            PocoProperty expected = new PocoProperty();

            // Act
            product.SetValue(ref instance, expected);

            // Assert
            PocoProperty actual = instance.Value;

            Assert.Same(expected, actual);
        }
示例#5
0
        public void SetValue(object instance, PropertyInfo property, string value)
        {
            var targetType = property.PropertyType;
            var thing      = assemblies.SelectMany(a => a.GetTypes())
                             .Select(t => new
            {
                Type      = t,
                Attribute = GetTypeConverterAttributeOrNull(t)
            })
                             .Where(t => t.Attribute != null && IsTheRightConverter(t.Type, targetType))
                             .FirstOrDefault();

            if (thing != null)
            {
                var typeConverterType = thing.Type;
                var typeConverter     = objectActivator.GetInstance(typeConverterType);

                try
                {
                    property.SetValue(instance, typeConverterType.GetMethod("Convert")
                                      .Invoke(typeConverter, new object[] { value }), null);
                }
                catch (Exception e)
                {
                    throw new FeatureExecutionException(e,
                                                        "Unhandled exception while attempting to convert {0} to {1} using {2}",
                                                        value,
                                                        targetType.FullName,
                                                        typeConverterType.FullName);
                }
            }
            else
            {
                fallbackPropertySetter.SetValue(instance, property, value);
            }
        }
示例#6
0
 private void MakeChange(SyncSession session, IPropertySetter setter, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj)
 {
     setter.SetValue(session, mapping, srcValues, targetObj);
 }
示例#7
0
 private void MakeChange(SyncSession session, IPropertySetter setter, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj)
 {
     setter.SetValue(session, mapping, srcValues, targetObj);
 }
示例#8
0
        public void SetValue(ref TReflected instance, TConvertedProperty value)
        {
            TProperty propertyValue = _converter.Convert(value);

            _propertySetter.SetValue(ref instance, propertyValue);
        }