Inheritance: AbstractMapping
コード例 #1
0
ファイル: JsonMappingSuite.cs プロジェクト: vc3/ExoModel
        public void TestCreation()
        {
            string mapping = @"[{PropertyPath : 'Number',Expression : '[Location #]'}, {PropertyPath : 'ServiceAddress.Line1',Expression : '[Full Service Address]'}, {PropertyPath : 'ServiceAddress.City',Expression : '[Service City]'}]";

            JsonMapping map = new JsonMapping(mapping);
            ExpressionToProperty test = new ExpressionToProperty();
            test.Expression = "[Service City]";
            test.PropertyPath = "ServiceAddress.City";

            Assert.AreEqual(3, map.GetMapping().Count());
            Assert.AreEqual(true, test.Equals(map.GetMapping().ElementAt(2)));
        }
コード例 #2
0
ファイル: JsonTranslatorSuite.cs プロジェクト: vc3/ExoModel
        public void TestTranslationOfExistingDestinationObjectWithIdInMapping()
        {
            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);

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

            JsonMapping map = new JsonMapping(mapping);

            //The test will overwrite the existing account object with new values from the source entity.
            IEnumerable<ModelInstance> translatedInstances = translator.Translate(ModelContext.Current.GetModelType("Account"), outType, dynamicProvider.GetModelInstances(ModelContext.Current.GetModelType("TypeName")), map, (type, instance, id) =>
            {
                return type.Create(id);
            });

            Assert.AreEqual(translatedInstances.ElementAt(0)["firstName"], "John");
            Assert.AreEqual(translatedInstances.ElementAt(0)["lastName"], "User");
            Assert.AreEqual(translatedInstances.ElementAt(0)["accountNumber"], "1234");
        }
コード例 #3
0
ファイル: JsonTranslatorSuite.cs プロジェクト: vc3/ExoModel
        public void TestArrayIndexPropertyPath()
        {
            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);

            ModelType staticType = ModelContext.Current.GetModelType("Payment");
            Assert.AreEqual("Payment", staticType.Name);

            string mapping = @"[{PropertyPath : 'payments[0].amount',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(((ModelInstance)translatedInstances.ElementAt(0).GetList("payments").ElementAt(0))["amount"], "1");
            Assert.AreEqual(((ModelInstance)translatedInstances.ElementAt(1).GetList("payments").ElementAt(0))["amount"], "2");
        }
コード例 #4
0
ファイル: JsonTranslatorSuite.cs プロジェクト: vc3/ExoModel
        public void TestStringManipulationExpressions()
        {
            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 + LastName'},{PropertyPath : 'lastName',Expression : 'FirstName.Contains(\"John\") ? \"MyNameIsJohn\" : \"MyNameIsNotJohn\"'},{PropertyPath : 'accountNumber',Expression : 'FirstName.Substring(0,1).ToLower()'}]";

            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"], "JohnDoe");
            Assert.AreEqual(translatedInstances.ElementAt(0)["lastName"], "MyNameIsJohn");
            Assert.AreEqual(translatedInstances.ElementAt(0)["accountNumber"], "j");
            Assert.AreEqual(translatedInstances.ElementAt(1)["firstName"], "JaneDoe");
            Assert.AreEqual(translatedInstances.ElementAt(1)["lastName"], "MyNameIsNotJohn");
            Assert.AreEqual(translatedInstances.ElementAt(1)["accountNumber"], "j");
        }