Example #1
0
        public void GetPropertyValueTest()
        {
            TestClass theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test"
            };
            var actual = ObjectLookupHelper.GetPropertyValue(theObject, "PropertyString");

            Assert.AreEqual(theObject.PropertyString, actual);
        }
Example #2
0
        /// <summary>
        /// Assemblies the details.
        /// </summary>
        /// <param name="assemblyInfo">The assembly info.</param>
        /// <returns></returns>
        public static IDictionary <string, string> AssemblyDetails(AssemblyInfo assemblyInfo)
        {
            IDictionary <string, string> results = new Dictionary <string, string>();

            foreach (string field in assemblyInfo.DictionaryFields)
            {
                results.Add(field, ObjectLookupHelper.GetPropertyValue(assemblyInfo, field).ToString());
            }
            return(results);
        }
Example #3
0
        public void GetObjectPropertyTest()
        {
            TestClass theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test"
            };
            PropertyInfo expected = theObject.GetType().GetProperty("PropertyString");
            PropertyInfo actual   = ObjectLookupHelper.GetObjectProperty(theObject, "PropertyString");

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void SetPropertyValueTest()
        {
            TestClass theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test"
            };
            const int Expected = 6;

            ObjectLookupHelper.SetPropertyValue(theObject, "PropertyInt", Expected);
            Assert.AreEqual(theObject.PropertyInt, Expected);
        }
 /// <summary>
 /// Calculates the specified metrics.
 /// </summary>
 /// <typeparam name="TR"></typeparam>
 /// <param name="metrics">The metrics.</param>
 /// <param name="results">The results.</param>
 private void Calculate <TR>(IEnumerable <string> metrics, ref TR results)
 {
     if (AnalyticParameters == null)
     {
         throw new ArgumentException("Analytic model parameters must be set before Calculating the analytics");
     }
     foreach (string metric in metrics)
     {
         object value = Calculate(metric);
         ObjectLookupHelper.SetPropertyValue(results, metric, value);
     }
 }
Example #6
0
        public void ObjectPropertyExistsTest()
        {
            TestClass theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test"
            };
            bool actual = ObjectLookupHelper.ObjectPropertyExists(theObject, "PropertyString");

            Assert.IsTrue(actual);

            actual = ObjectLookupHelper.ObjectPropertyExists(theObject, "PropertyString1");
            Assert.IsFalse(actual);
        }
        /// <summary>
        /// Creates the array for item.
        /// </summary>
        /// <typeparam name="TIn">The type of the in.</typeparam>
        /// <typeparam name="TOut">The type of the out.</typeparam>
        /// <param name="itemName">Name of the item.</param>
        /// <param name="terms">The terms.</param>
        /// <returns></returns>
        public static TOut[] CreateArrayForItem <TIn, TOut>(string itemName, TIn[] terms)
        {
            var result = new List <TOut>();

            foreach (TIn streamTerm in terms)
            {
                if (ObjectLookupHelper.ObjectPropertyExists(streamTerm, itemName))
                {
                    result.Add((TOut)ObjectLookupHelper.GetPropertyValue(streamTerm, itemName));
                }
            }
            return(result.ToArray());
        }
Example #8
0
 public static void ResolveBusinessCenters(object objectGraph)
 {
     foreach (BusinessDayAdjustments businessDayAdjustment in GetBusinessDayAdjustments(objectGraph))
     {
         // "NONE" adjustments have neither businessCenters nor businessCentersReference.
         //
         if ((null != businessDayAdjustment) &&
             (null == businessDayAdjustment.businessCenters) &&
             (null != businessDayAdjustment.businessCentersReference) &&
             (!String.IsNullOrEmpty(businessDayAdjustment.businessCentersReference.href)))
         {
             var businessCenters = ObjectLookupHelper.GetById <BusinessCenters>(objectGraph, businessDayAdjustment.businessCentersReference.href);
             var businessCentersCloneWithNoId = BinarySerializerHelper.Clone(businessCenters);
             businessCentersCloneWithNoId.id       = null;
             businessDayAdjustment.businessCenters = businessCentersCloneWithNoId;
         }
     }
 }
Example #9
0
        public void GetObjectPropertiesTest()
        {
            TestClass theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test"
            };

            PropertyInfo[] expected
                = new PropertyInfo[]
                {
                theObject.GetType().GetProperty("PropertyInt"),
                theObject.GetType().GetProperty("PropertyString"),
                theObject.GetType().GetProperty("Sub"),
                theObject.GetType().GetProperty("Subs"),
                };

            PropertyInfo[] actual = ObjectLookupHelper.GetObjectProperties(theObject);
            CollectionAssert.AreEqual(expected, actual);
        }
Example #10
0
        public void GetByIdTest()
        {
            // When Id is set the object is returned
            TestSubClass testSubClass = new TestSubClass {
                id = "theId", name = "theName"
            };
            TestClass theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test", Sub = testSubClass
            };
            TestSubClass actual = ObjectLookupHelper.GetById <TestSubClass>(theObject, testSubClass.id);

            Assert.AreEqual(theObject.Sub, actual);

            // Id is null, returns null
            testSubClass = new TestSubClass {
                id = null, name = "theName"
            };
            theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test", Sub = testSubClass
            };
            actual = ObjectLookupHelper.GetById <TestSubClass>(theObject, testSubClass.id);
            Assert.AreEqual(null, actual);

            // Id is set in Subs, that Sub is returned
            testSubClass = new TestSubClass {
                id = "theId", name = "theName"
            };
            theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test", Sub = null, Subs = new TestSubClass[] { testSubClass }
            };
            actual = ObjectLookupHelper.GetById <TestSubClass>(theObject, testSubClass.id);
            Assert.AreEqual(theObject.Subs[0], actual);

            // This time the Id is not found
            testSubClass = new TestSubClass {
                id = "theId", name = "theName"
            };
            theObject = new TestClass {
                PropertyInt = 7, PropertyString = "Test", Sub = null, Subs = new TestSubClass[] { testSubClass }
            };
            actual = ObjectLookupHelper.GetById <TestSubClass>(theObject, "invalid Id");
            Assert.AreEqual(null, actual);
        }
 /// <summary>
 /// Gets the value.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="bootstrapResults">The bootstrap results.</param>
 /// <returns></returns>
 protected static IPricingStructure GetValue <T>(T bootstrapResults)
 {
     return((IPricingStructure)ObjectLookupHelper.GetPropertyValue(bootstrapResults, "PricingStructure"));
 }
        /// <summary>
        /// Calculates the specified metric.
        /// </summary>
        /// <param name="metric">The metric.</param>
        /// <returns></returns>
        private object Calculate(string metric)
        {
            object value = ObjectLookupHelper.GetPropertyValue(this, metric);

            return(value);
        }