Ejemplo n.º 1
0
        public void LocalRegistedDataKeyDictionaryVariable()
        {
            DataContext dc       = new DataContext();
            string      expected = AccountTestData.viewerName;


            GenericExpressionEvalWrapper wrappedPerson = new GenericExpressionEvalWrapper(AccountTestData.Viewer);

            string val = wrappedPerson.ResolveExpressionValue("displayName") as string;
            Dictionary <string, string> dict = new Dictionary <string, string>();

            string dictKey   = "foo";
            string localKey  = "mydict";
            string globalKey = "vwr";


            dict.Add(dictKey, AsKey(globalKey));

            dc.RegisterDataItem(globalKey, wrappedPerson);

            dc.RegisterLocalValue(localKey, dict, true);

            string expr = AsKey(String.Format("{0}.{1}.displayName", new object[] { localKey, dictKey }));

            string result = dc.GetVariableValue(expr);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 2
0
        public void AutoWrappedObjectTests()
        {
            DataContext dc = new DataContext();

            AnObject unwrapped = new AnObject
            {
                PropVal  = "fooProp",
                FieldVal = "fooField"
            };

            GenericExpressionEvalWrapper wrapped = new GenericExpressionEvalWrapper(unwrapped);

            dc.RegisterDataItem("wrapped", wrapped);
            dc.RegisterDataItem("unwrapped", unwrapped);

            Assert.IsFalse(string.IsNullOrEmpty(dc.CalculateVariableValue("${wrapped.PropVal}")));
            Assert.IsFalse(string.IsNullOrEmpty(dc.CalculateVariableValue("${wrapped.FieldVal}")));

            Assert.AreEqual(unwrapped.PropVal, dc.CalculateVariableValue("${wrapped.PropVal}"));
            Assert.AreEqual(unwrapped.PropVal, dc.CalculateVariableValue("${unwrapped.PropVal}"));
            string val = dc.CalculateVariableValue("${unwrapped.PropVal}");

            Assert.AreEqual(unwrapped.FieldVal, dc.CalculateVariableValue("${wrapped.FieldVal}"));
            Assert.AreEqual(unwrapped.FieldVal, dc.CalculateVariableValue("${unwrapped.FieldVal}"));
        }
Ejemplo n.º 3
0
        public void PropertyObjectInvokersLoad()
        {
            GenericExpressionEvalWrapper.ClearRegisteredTypes();
            string      valExpr = "MyString";
            DataContext context = new DataContext();

            string           testString = "Test String";
            SimpleDataObject data       = new SimpleDataObject(1, testString, 2.2);

            GenericExpressionEvalWrapper wrapper = new GenericExpressionEvalWrapper(data, false);

            object rslt = wrapper.ResolveExpressionValue(valExpr);

            Assert.IsNotNull(rslt, "Result is null");
            string result = rslt.ToString();

            Assert.AreEqual(testString, result, "Direct ResolveExpressionValue call failed");
            Assert.AreEqual(result, WrapperUtility.ResolveExpressionValue(valExpr, data, GenericExpressionEvalWrapper.GetDataPropertyEvaluator(data.GetType())));

            DataContext dc = new DataContext();

            dc.RegisterDataItem("foo", wrapper);

            string dcResult = dc.CalculateVariableValue("${foo." + valExpr + "}");

            Assert.AreEqual(testString, dcResult, "DataContext gave incorrect result");
        }
Ejemplo n.º 4
0
        public void PropertyDataObjectRecognized()
        {
            GenericExpressionEvalWrapper.ClearRegisteredTypes();
            string           testString = "Test String";
            SimpleDataObject data       = new SimpleDataObject(1, testString, 2.2);

            GenericExpressionEvalWrapper wrapper = new GenericExpressionEvalWrapper(data);

            int invokerCount = GenericExpressionEvalWrapper.GetDataFieldEvaluator(data.GetType()).Count;

            Assert.AreEqual(invokerCount, 0);

            Assert.Less(0, GenericExpressionEvalWrapper.GetDataPropertyEvaluator(data.GetType()).Count, "Property invokers not loaded");
        }
Ejemplo n.º 5
0
        public void TestRenderFromMarkup()
        {
            //Assert.IsTrue(true);


            Person viewer = ControlTestHelper.CreatePerson(vUid, vname, null);

            OsmlName    control = new OsmlName(baseTag);
            DataContext dc      = control.MyDataContext;
            GenericExpressionEvalWrapper wrapper = new GenericExpressionEvalWrapper(viewer);

            dc.RegisterDataItem("Viewer", wrapper);

            Assert.IsTrue(AssertRenderResultsEqual(control, expectedTag));
        }
Ejemplo n.º 6
0
        public void FieldAndPropertyContractWorks()
        {
            GenericExpressionEvalWrapper.ClearRegisteredTypes();
            string testString       = "Test String";
            string propNameValue    = "Steve";
            string fieldZodiacValue = "Aquarius";
            Person data             = new Person();

            data.DisplayName = propNameValue;
            data.ZodiacSign  = fieldZodiacValue;            //field value


            GenericExpressionEvalWrapper wrapper = new GenericExpressionEvalWrapper(data);

            Assert.AreEqual(fieldZodiacValue, wrapper.ResolveExpressionValue("msZodiacSign"), "Field failed evaluation");
            Assert.AreEqual(propNameValue, wrapper.ResolveExpressionValue("displayName"), "Property failed evaluation");
        }
Ejemplo n.º 7
0
        public static void ResolveDataControlValues(DataContext dataContext, Person viewer, Person owner, List <Person> viewerFriends)
        {
            GenericExpressionEvalWrapper v = new GenericExpressionEvalWrapper(viewer);
            GenericExpressionEvalWrapper o = new GenericExpressionEvalWrapper(owner);

            foreach (KeyValuePair <string, DataItem> item in dataContext.MasterData)
            {
                if (item.Value.DataControl is OsViewerRequest)
                {
                    item.Value.Data = v;
                    item.Value.DataControl.Value = v;
                }
                if (item.Value.DataControl is OsOwnerRequest)
                {
                    item.Value.Data = o;
                    item.Value.DataControl.Value = o;
                }
                if (item.Value.DataControl is OsPeopleRequest)
                {
                    item.Value.Data = viewerFriends;
                    item.Value.DataControl.Value = new GenericExpressionEvalWrapper(viewerFriends);
                }
            }
        }