Ejemplo n.º 1
0
        private string GetSetObjectPropertyResponse(string address)
        {
            var queries = UrlUtilities.CrackUrl(address);

            PropertyCache cache;

            if (typeof(TObjectProperty) == typeof(ObjectProperty))
            {
                cache = ObjectPropertyParser.GetPropertyInfoViaTypeLookup((Enum)(object)property);
            }
            else if (typeof(TObjectProperty) == typeof(ChannelProperty))
            {
                cache = ObjectPropertyParser.GetPropertyInfoViaPropertyParameter <Channel>((Enum)(object)property);
            }
            else
            {
                throw new NotImplementedException($"Handler for object property type {nameof(TObjectProperty)} is not implemented");
            }

            var queryName = ObjectPropertyParser.GetObjectPropertyNameViaCache((Enum)(object)property, cache);

            if (typeof(TObjectProperty) == typeof(ChannelProperty))
            {
                queryName += "1"; //Channel ID used for tests
            }
            var val = queries[queryName];

            Assert.IsTrue(val == expectedValue, $"The value of property '{property.ToString().ToLower()}' did not match the expected value. Expected '{expectedValue}', received: '{val}'");

            return("OK");
        }
Ejemplo n.º 2
0
        private object DeserializeObjectPropertyInternal(Enum property, string rawValue)
        {
            var cache   = ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property);
            var rawName = ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache);

            return(XmlReflectionSerializerImpl.DeserializeRawPropertyValue(property, rawName, rawValue));
        }
Ejemplo n.º 3
0
        private void ExecuteWithTypeLookupInternal(FakeObjectProperty property, object value, params string[] expected)
        {
            var parameters = new FakeSetObjectPropertyParameters(e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e));

            parameters.AddValue(property, value, true);

            AssertEx.AreEqualLists(parameters.CustomParameters.Select(p => p.ToString()).ToList(), expected.ToList(), "Parameter lists were not equal");
        }
Ejemplo n.º 4
0
        private void TestDeserialization(FakeObjectProperty property, object value, object expected)
        {
            var parser = new DynamicPropertyTypeParser(property, ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property), value);

            var result = parser.DeserializeValue();

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retrieves an object that defines the dynamic parameters of this cmdlet.
        /// </summary>
        /// <returns>An object that defines the dynamic parameters of this cmdlet.</returns>
        public object GetDynamicParameters()
        {
            if (dynamicParams == null)
                dynamicParams = new PropertyDynamicParameterSet<ObjectProperty>(
                    new[] {ParameterSet.Dynamic, ParameterSet.DynamicManual },
                    e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e).Property.PropertyType
                );

            return dynamicParams.Parameters;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Retrieves an object that defines the dynamic parameters of this cmdlet.
        /// </summary>
        /// <returns>An object that defines the dynamic parameters of this cmdlet.</returns>
        public object GetDynamicParameters()
        {
            if (dynamicParams == null)
            {
                dynamicParams = new DynamicParameterSet <ObjectProperty>(
                    ParameterSet.Dynamic,
                    e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e).Property
                    );
            }

            return(dynamicParams.Parameters);
        }
Ejemplo n.º 7
0
        private void TestArrayDeserialization(FakeObjectProperty property, object value, object expected)
        {
            var parser = new DynamicPropertyTypeParser(property, ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property), value);

            var result = parser.DeserializeValue();

            if (result == null)
            {
                Assert.AreEqual(expected, result);
            }
            else
            {
                Assert.IsInstanceOfType(expected, typeof(string[]));
                Assert.IsInstanceOfType(result, typeof(string[]));

                AssertEx.AreEqualLists(((string[])expected).ToList(), (((string[])result).ToList()), "Expected and result were not equal");
            }
        }
Ejemplo n.º 8
0
        private Expression GetCaseBody(Enum property, Expression rawValue)
        {
            var viaObject = false;

            var typeLookup = property.GetEnumAttribute <TypeLookupAttribute>()?.Class; //ObjectPropertyInternal members don't necessarily have a type lookup

            if (typeLookup == null)
            {
                return(null);
            }

            var mappings   = ReflectionCacheManager.Map(typeLookup).Cache;
            var cache      = ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property);
            var xmlElement = cache.GetAttribute <XmlElementAttribute>(); //todo: what if this objectproperty doesnt point to a member with an xmlelementattribute?

            XmlMapping mapping = null;

            if (xmlElement != null)
            {
                mapping = mappings.FirstOrDefault(m => m.AttributeValue[0] == xmlElement.ElementName);
            }
            else
            {
                var mergeAttribute = property.GetEnumAttribute <MergeableAttribute>();

                //If we're a property like LocationName, we don't exist server side - we're only used for constructing requests
                if (mergeAttribute != null)
                {
                    return(null);
                }

                //We have a property like Interval which uses a backing property instead.
                //Get the backing property so that we may extract the real value from the public
                //property
                var rawName     = ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache);
                var elementName = $"{HtmlParser.DefaultPropertyPrefix}{rawName.TrimEnd('_')}";

                mapping = mappings.FirstOrDefault(m => m.AttributeValue[0] == elementName);

                if (mapping != null)
                {
                    viaObject = true;
                }
            }

            if (mapping != null)
            {
                var deserializer = new ValueDeserializer(mapping, null, rawValue);
                var result       = deserializer.Deserialize();

                if (viaObject)
                {
                    //Construct an expression like return new TableSettings { intervalStr = "60|60 seconds" }.Interval;
                    var settingsObj    = Expression.Variable(typeLookup, "obj");
                    var assignObj      = settingsObj.Assign(Expression.New(typeLookup));
                    var internalProp   = Expression.MakeMemberAccess(settingsObj, mapping.PropertyCache.Property);
                    var assignInternal = internalProp.Assign(result);
                    var externalProp   = Expression.MakeMemberAccess(settingsObj, cache.Property);

                    return(Expression.Block(
                               new[] { settingsObj },
                               assignObj,
                               assignInternal,
                               Expression.Convert(externalProp, typeof(object))
                               ));
                }

                return(result);
            }

            //Property is not deserializable
            return(null);
        }
Ejemplo n.º 9
0
 public override PropertyCache GetPropertyCache(Enum property)
 {
     return(ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property));
 }
Ejemplo n.º 10
0
 PropertyCache IPropertyCacheResolver.GetPropertyCache(Enum property)
 {
     return(ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property));
 }
Ejemplo n.º 11
0
        private void ParseValue()
        {
            var prop = ObjectPropertyParser.GetPropertyInfoViaTypeLookup(Property);

            Value = ParseValueIfRequired(prop.Property, Value);
        }
Ejemplo n.º 12
0
        private void ExecuteWithTypeLookupInternal(FakeObjectProperty property, object value)
        {
            var parameters = new FakeSetObjectPropertyParameters(e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e));

            parameters.AddValue(property, value, true);
        }