Ejemplo n.º 1
0
        public void It_gets_Dictionary_values()
        {
            Dictionary <string, int> target = new Dictionary <string, int>();

            target["IntKey"] = 123;
            Assert.AreEqual(123, ValueGetter.GetValue(target, "IntKey"));
        }
Ejemplo n.º 2
0
        public void It_gets_method_values()
        {
            ReadWriteInts target = new ReadWriteInts();

            target.IntField = 123;
            Assert.AreEqual(123, ValueGetter.GetValue(target, "IntMethod"));
        }
Ejemplo n.º 3
0
        public void It_gets_Hashtable_values()
        {
            Hashtable target = new Hashtable();

            target["IntKey"] = 123;
            Assert.AreEqual(123, ValueGetter.GetValue(target, "IntKey"));
        }
Ejemplo n.º 4
0
        public void It_gets_NameValueCollection_values()
        {
            NameValueCollection target = new NameValueCollection();

            target["IntKey"] = "123";
            Assert.AreEqual("123", ValueGetter.GetValue(target, "IntKey"));
        }
        public ParamInfo GetParamInfo(IContext context, string dataStr)
        {
            var key      = dataStr.Substring(1, dataStr.Length - 1);
            var keyArray = key.Split('_');
            var str      = keyArray[1];
            var array    = str.Split('.');

            if (array.Count() <= 1)
            {
                throw new ArgumentException(string.Concat("参数", str, "设置错误!"));
            }

            var objectKey = array[0];
            var fields    = array.Skip(1).ToArray();
            var realKey   = string.Concat(objectKey, "_", string.Join("_", fields));

            var queryParams = GetQueryParams(context);

            object outData   = GetDataFromCache(queryParams, realKey);
            var    data      = GetObject(objectKey, context);
            var    valueInfo = ValueGetter.GetValue(fields, data);

            outData = ValueGetter.Builder(valueInfo);
            queryParams.ReplaceOrInsert(realKey, outData);

            return(new ParamInfo
            {
                OriginalData = valueInfo.Data,
                Type = ParamType.Object,
                Name = key,
                Data = outData
            });
        }
Ejemplo n.º 6
0
        public object Fill(ReleatedQuery config, object parent, IEnumerable <object> matchDatas, IValueSetter valueSetter)
        {
            var data        = matchDatas.FirstOrDefault();
            var fieldCount  = config.FillFields.Count();
            var dValueCount = config.DefaultValues.Count();

            if (data == null)
            {
                for (var i = 0; i < fieldCount; i++)
                {
                    var field = config.FillFields.ElementAt(i);
                    if (i >= dValueCount)
                    {
                        break;
                    }

                    var val = config.DefaultValues.ElementAt(i);
                    valueSetter.SetField(parent, val, field);
                }

                return(null);
            }

            for (var i = 0; i < fieldCount; i++)
            {
                var field = config.FillFields.ElementAt(i);
                var val   = ValueGetter.GetValue(field, data).Data;
                valueSetter.SetField(parent, val, field);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public void It_gets_XmlNode_attribute_values()
        {
            XmlDocument target = new XmlDocument();

            target.LoadXml("<doc attr='val'></doc>");
            Assert.AreEqual("val", ValueGetter.GetValue(target.DocumentElement, "@attr"));
        }
Ejemplo n.º 8
0
        public void It_gets_case_insensitive_method_values()
        {
            ReadWriteInts target = new ReadWriteInts();

            target.IntField = 123;
            Assert.AreEqual(123, ValueGetter.GetValue(target, "intmethod"));
        }
Ejemplo n.º 9
0
        public void It_gets_ListValueByIndex_values_from_List()
        {
            List <string> target = new List <string>()
            {
                "hello", "world"
            };

            Assert.AreEqual("hello", ValueGetter.GetValue(target, "0"));
        }
Ejemplo n.º 10
0
        public void It_gets_XmlNode_single_child_element_value_as_a_string()
        {
            XmlDocument target = new XmlDocument();

            target.LoadXml("<doc attr='val'><child>text</child></doc>");
            var value = (string)ValueGetter.GetValue(target.DocumentElement, "child");

            Assert.AreEqual("text", value);
        }
Ejemplo n.º 11
0
        public void It_gets_DataRow_values_using_property_names()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("item", typeof(int));
            dt.Rows.Add(new object[] { 123 });
            var target = dt.Rows[0];

            Assert.AreEqual(123, ValueGetter.GetValue(target, "item"));
        }
Ejemplo n.º 12
0
        public void It_gets_case_insensitive_DataRow_Values()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("IntColumn", typeof(int));
            dt.Rows.Add(new object[] { 123 });
            var target = dt.Rows[0];

            Assert.AreEqual(123, ValueGetter.GetValue(target, "intcolumn"));
        }
Ejemplo n.º 13
0
        public void It_gets_DataRowView_values()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("IntColumn", typeof(int));
            dt.Rows.Add(new object[] { 123 });
            DataRowView target = dt.DefaultView[0];

            Assert.AreEqual(123, ValueGetter.GetValue(target, "IntColumn"));
        }
Ejemplo n.º 14
0
        public void It_gets_GenericDictionary_values()
        {
            var mock = new Mock <IDictionary <string, int> >();

            mock.Setup(x => x.ContainsKey("Key")).Returns(true);
            mock.Setup(x => x["Key"]).Returns(123);
            IDictionary <string, int> target = mock.Object;

            Assert.AreEqual(123, ValueGetter.GetValue(target, "Key"));
        }
Ejemplo n.º 15
0
        public void It_gets_XmlNode_single_child_element_values_as_a_list()
        {
            XmlDocument target = new XmlDocument();

            target.LoadXml("<doc attr='val'><child>text</child></doc>");
            XmlNodeList elements = (XmlNodeList)ValueGetter.GetValue(target.DocumentElement, "child");

            Assert.AreEqual(1, elements.Count);
            Assert.AreEqual("text", elements[0].InnerText);
        }
Ejemplo n.º 16
0
        public void It_gets_single_node_values_as_node_by_Index_from_XmlNodeList()
        {
            XmlDocument target = new XmlDocument();

            target.LoadXml(@"<doc attr='val'>
    <child>text1</child>
    <child><grandchild>text2</grandchild></child>
    <child>text3</child>
</doc>");
            var value = (XmlNode)ValueGetter.GetValue(target.DocumentElement.ChildNodes, "1");

            Assert.AreEqual("<grandchild>text2</grandchild>", value.InnerXml);
        }
Ejemplo n.º 17
0
        public void It_gets_single_CDATA_values_as_string_by_Index_from_XmlNodeList()
        {
            XmlDocument target = new XmlDocument();

            target.LoadXml(@"<doc attr='val'>
    <child><![CDATA[text1]]></child>
    <child><![CDATA[text2]]></child>
    <child><![CDATA[text3]]></child>
</doc>");
            var value = (string)ValueGetter.GetValue(target.DocumentElement.ChildNodes, "1");

            Assert.AreEqual("text2", value);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Determines whether the present value matches the value on
        /// the initialSetValue (which can be a single value or a set)
        /// </summary>
        /// <param name="value">Value from the datasource</param>
        /// <param name="initialSetValue">Value from the initial selection set</param>
        /// <param name="propertyOnInitialSet">Optional. Property to obtain the value from</param>
        /// <param name="isMultiple"><c>true</c> if the initial selection is a set</param>
        /// <returns><c>true</c> if it's selected</returns>
        protected internal static bool IsPresent(object value, object initialSetValue,
                                                 ValueGetter propertyOnInitialSet, bool isMultiple)
        {
            if (!isMultiple)
            {
                var valueToCompare = initialSetValue;

                if (propertyOnInitialSet != null)
                {
                    // propertyOnInitialSet.GetValue(initialSetValue, null);
                    valueToCompare = propertyOnInitialSet.GetValue(initialSetValue);
                }

                return(AreEqual(value, valueToCompare));
            }
            else
            {
                foreach (var item in (IEnumerable)initialSetValue)
                {
                    var valueToCompare = item;

                    if (propertyOnInitialSet != null)
                    {
                        // valueToCompare = propertyOnInitialSet.GetValue(item, null);
                        valueToCompare = propertyOnInitialSet.GetValue(item);
                    }

                    if (AreEqual(value, valueToCompare))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected static IEnumerable<object> GetDatas(UpdateContext context, UpdateConfig config, object complexData)
        {
            string field = string.Empty;
            if (config.Config != null && config.Config[BatchFieldPath] != null)
            {
               field = config.Config[BatchFieldPath].ToSingleData<string>(string.Empty);
            }

            bool isArray;
            object inputData;
            if (string.IsNullOrEmpty(field))
            {
                isArray = ReflectUtil.ReflectUtil.IsArray(complexData);
                inputData = complexData;
            }
            else
            {
                var array = field.Split('.');
                var valueInfo = ValueGetter.GetValue(array, complexData);
                isArray = valueInfo.IsArray;
                inputData = valueInfo.Data;
            }

            IEnumerable<object> results;
            if (!isArray)
            {
                results = new object[] { inputData };
            }
            else {
                results = (IEnumerable<object>)inputData;
            }

            var filterEval = config.Config[FilterEval].ToSingleData<string>(string.Empty);
            if (string.IsNullOrEmpty(filterEval) || results.Any() == false)
            {
                return results;
            }

            var action = context.ContentParams.CreateOrGet<string, object, Delegate>(filterEval, eval =>
            {
                return EvalHelper.GetDelegate(context, filterEval, results.First());
            });
            
            results = results.Where(r => (bool)action.DynamicInvoke(r)).ToArray();
            return results;
        }
Ejemplo n.º 20
0
 public void It_returns_NoValue_when_it_cant_get_a_value()
 {
     Assert.AreSame(ValueGetter.NoValue, ValueGetter.GetValue(this, "x"));
 }
Ejemplo n.º 21
0
        public void It_cant_get_values_from_write_only_methods()
        {
            WriteOnlyInts target = new WriteOnlyInts();

            Assert.IsNull(ValueGetter.GetValue(target, "IntMethod"));
        }
Ejemplo n.º 22
0
        public void It_cant_get_values_from_write_only_properties()
        {
            WriteOnlyInts target = new WriteOnlyInts();

            Assert.IsNull(ValueGetter.GetValue(target, "IntProperty"));
        }
Ejemplo n.º 23
0
 public void It_gets_ListValueByIndex_values_from_array()
 {
     string[] target = new[] { "hello", "world" };
     Assert.AreEqual("hello", ValueGetter.GetValue(target, "0"));
 }
Ejemplo n.º 24
0
 public void It_returns_null_when_it_cant_get_a_value()
 {
     Assert.IsNull(ValueGetter.GetValue(this, "x"));
 }
Ejemplo n.º 25
0
 public void It_fails_ListValueByIndex_values_from_List()
 {
     string[] target = new[] { "hello", "world" };
     Assert.AreEqual(ValueGetter.NoValue, ValueGetter.GetValue(target, "2"));
 }
Ejemplo n.º 26
0
		/// <summary>
		/// Determines whether the present value matches the value on 
		/// the initialSetValue (which can be a single value or a set)
		/// </summary>
		/// <param name="value">Value from the datasource</param>
		/// <param name="initialSetValue">Value from the initial selection set</param>
		/// <param name="propertyOnInitialSet">Optional. Property to obtain the value from</param>
		/// <param name="isMultiple"><c>true</c> if the initial selection is a set</param>
		/// <returns><c>true</c> if it's selected</returns>
		protected internal static bool IsPresent(object value, object initialSetValue, 
												 ValueGetter propertyOnInitialSet, bool isMultiple)
		{
			if (!isMultiple)
			{
				object valueToCompare = initialSetValue;
				
				if (propertyOnInitialSet != null)
				{
					// propertyOnInitialSet.GetValue(initialSetValue, null);
					valueToCompare = propertyOnInitialSet.GetValue(initialSetValue); 
				}
				
				return AreEqual(value, valueToCompare);
			}
			else
			{
				foreach(object item in (IEnumerable) initialSetValue)
				{
					object valueToCompare = item;

					if (propertyOnInitialSet != null)
					{
						// valueToCompare = propertyOnInitialSet.GetValue(item, null);
						valueToCompare = propertyOnInitialSet.GetValue(item); 
					}

					if (AreEqual(value, valueToCompare))
					{
						return true;
					}
				}
			}
			
			return false;
		}