コード例 #1
0
        public void TestContextCreationGetInstance()
        {
            ModelType      outType;
            IList <string> propertyNames = new List <string>();

            propertyNames.Add("Employee Id");
            propertyNames.Add("Location");
            propertyNames.Add("FirstName");
            propertyNames.Add("LastName");
            provider.CreateType(propertyNames, out outType, "TypeName");

            //load a new instance
            string         employeeId     = "1";
            IList <string> instanceValues = new List <string>();

            instanceValues.Add(employeeId);
            instanceValues.Add("23");
            instanceValues.Add("John");
            instanceValues.Add("Doe");
            provider.CreateInstance(outType, instanceValues);
            RowInstance instance = provider.GetInstance(outType, employeeId);

            //now that the type has been created, try to retrieve the type from the context
            ModelInstance contextInstance = ModelContext.Current.GetModelInstance(instance);

            Assert.AreEqual(instance["_Employee_Id"], contextInstance["_Employee_Id"]);
        }
コード例 #2
0
        public void TestSimpleInstanceTranslation()
        {
            ModelType      outType;
            IList <string> propertyNames = new List <string>();

            propertyNames.Add("Employee Id");
            propertyNames.Add("Location");
            propertyNames.Add("FirstName");
            propertyNames.Add("LastName");
            dynamicProvider.CreateType(propertyNames, out outType, "TypeName");

            //load a new instance
            IList <string> instanceValues = new List <string>();

            instanceValues.Add("1");
            instanceValues.Add("23");
            instanceValues.Add("John");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            instanceValues = new List <string>();
            instanceValues.Add("2");
            instanceValues.Add("23");
            instanceValues.Add("Jane");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            string mapping = @"[{PropertyPath : 'firstName',Expression : 'FirstName'}, {PropertyPath : 'lastName',Expression : 'LastName'}, {PropertyPath : 'accountNumber',Expression : 'Employee Id'}]";

            JsonMapping map = new JsonMapping(mapping);
            IEnumerable <ModelInstance> translatedInstances = translator.Translate(ModelContext.Current.GetModelType("Account"), outType, dynamicProvider.GetModelInstances(ModelContext.Current.GetModelType("TypeName")), map);

            Assert.AreEqual(translatedInstances.ElementAt(0)["firstName"], "John");
            Assert.AreEqual(translatedInstances.ElementAt(0)["lastName"], "Doe");
            Assert.AreEqual(translatedInstances.ElementAt(0)["accountNumber"], "1");

            Assert.AreEqual(translatedInstances.ElementAt(1)["firstName"], "Jane");
            Assert.AreEqual(translatedInstances.ElementAt(1)["lastName"], "Doe");
            Assert.AreEqual(translatedInstances.ElementAt(1)["accountNumber"], "2");
        }