Example #1
0
        public void Test_ToBody()
        {
            TeaModel modelNull = new TeaModel();

            Assert.Empty(Client.ToXML(modelNull.ToMap()));

            ToBodyModel            model  = new ToBodyModel();
            ListAllMyBucketsResult result = new ListAllMyBucketsResult();
            Buckets buckets = new Buckets();

            buckets.bucket = new List <Bucket>();
            buckets.bucket.Add(new Bucket {
                CreationDate = "2015-12-17T18:12:43.000Z", ExtranetEndpoint = "oss-cn-shanghai.aliyuncs.com", IntranetEndpoint = "oss-cn-shanghai-internal.aliyuncs.com", Location = "oss-cn-shanghai", Name = "app-base-oss", StorageClass = "Standard"
            });
            buckets.bucket.Add(new Bucket {
                CreationDate = "2014-12-25T11:21:04.000Z", ExtranetEndpoint = "oss-cn-hangzhou.aliyuncs.com", IntranetEndpoint = "oss-cn-hangzhou-internal.aliyuncs.com", Location = "oss-cn-hangzhou", Name = "atestleo23", StorageClass = "IA"
            });
            buckets.bucket.Add(null);
            result.buckets = buckets;
            Owner owner = new Owner {
                ID = 512, DisplayName = "51264"
            };

            result.owner = owner;
            model.listAllMyBucketsResult             = result;
            model.listAllMyBucketsResult.testStrList = new List <string> {
                "1", "2"
            };
            model.listAllMyBucketsResult.owners = new List <Owner>();
            model.listAllMyBucketsResult.owners.Add(owner);
            model.listAllMyBucketsResult.TestDouble   = 1;
            model.listAllMyBucketsResult.TestFloat    = 2;
            model.listAllMyBucketsResult.TestLong     = 3;
            model.listAllMyBucketsResult.TestShort    = 4;
            model.listAllMyBucketsResult.TestUInt     = 5;
            model.listAllMyBucketsResult.TestULong    = 6;
            model.listAllMyBucketsResult.TestUShort   = 7;
            model.listAllMyBucketsResult.TestBool     = true;
            model.listAllMyBucketsResult.TestNull     = null;
            model.listAllMyBucketsResult.TestListNull = null;
            string xmlStr = Client.ToXML(model.ToMap());

            Assert.NotNull(xmlStr);

            Dictionary <string, object> xmlBody = (Dictionary <string, object>)Client.ParseXml(xmlStr, typeof(ToBodyModel));
            ToBodyModel teaModel = TeaModel.ToObject <ToBodyModel>(xmlBody);

            Assert.NotNull(teaModel);
            Assert.Equal(1, teaModel.listAllMyBucketsResult.TestDouble);
        }
Example #2
0
        private static IDictionary <string, object> GetTeaModelMap(TeaModel teaModel)
        {
            IDictionary <string, object> result      = new Dictionary <string, object>();
            IDictionary <string, object> teaModelMap = teaModel.ToMap();

            foreach (var pair in teaModelMap)
            {
                if (pair.Value is TeaModel)
                {
                    result.Add(pair.Key, GetTeaModelMap((TeaModel)pair.Value));
                }
                else
                {
                    result.Add(pair.Key, pair.Value);
                }
            }
            return(result);
        }
Example #3
0
 /// <summary>
 /// Model transforms to map[string]any
 /// </summary>
 /// <param name="model"></param>
 /// <returns>map[string]any</returns>
 public static Dictionary <string, object> ToMap(TeaModel model)
 {
     return(model.ToMap());
 }
Example #4
0
        public void TestToMap()
        {
            TeaModel modelNull = null;

            Assert.Null(modelNull.ToMap());

            TestRegModel model = new TestRegModel();

            model.RequestId = "requestID";
            model.Items     = new List <TestRegSubModel> {
                new TestRegSubModel {
                    RequestId = "sub"
                }, null
            };
            model.NextMarker  = "next";
            model.testNoAttr  = "noAttr";
            model.subModel    = new TestRegSubModel();
            model.testListStr = new List <string> {
                "str"
            };
            model.bytes = Encoding.UTF8.GetBytes("test");
            TestRegSubModel dicSubModel = new TestRegSubModel
            {
                RequestId = "requestDic"
            };
            Dictionary <string, TestRegSubModel> dicSub = new Dictionary <string, TestRegSubModel>
            {
                { "subDic", dicSubModel },
                { "subNull", null }
            };
            var dicMap = new Dictionary <string, Dictionary <string, TestRegSubModel> >
            {
                { "map", dicSub }
            };
            Dictionary <string, string> map = new Dictionary <string, string>
            {
                { "test", "test" }
            };
            List <IDictionary> list = new List <IDictionary>();

            list.Add(map);
            List <List <IDictionary> > listNestedList = new List <List <IDictionary> >();

            listNestedList.Add(list);
            model.dicNestDic = dicMap;
            model.listIDic   = listNestedList;
            Dictionary <string, object> dic = model.ToMap();

            Assert.NotNull(dic);

            var from = TeaModel.ToObject <TestRegModel>(dic);

            Assert.Equal("test", from.listIDic[0][0]["test"]);
            Assert.Equal("requestDic", from.dicNestDic["map"]["subDic"].RequestId);

            TestRegModel modelEmpty = new TestRegModel();

            modelEmpty.RequestId = "1";
            Dictionary <string, object> dicEmpty = modelEmpty.ToMap();

            Assert.Null(dicEmpty["items"]);
            Assert.Null(dicEmpty["subModel"]);
        }