public void TestToBody()
        {
            TeaModel modelNull = new TeaModel();

            Assert.Empty((string)TestHelper.RunInstanceMethod(typeof(BaseClient), "_toXML", baseClient, new object[] { modelNull }));

            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 = (string)TestHelper.RunInstanceMethod(typeof(BaseClient), "_toXML", baseClient, new object[] { model });

            Assert.NotNull(xmlStr);

            Mock <HttpWebResponse> mockHttpWebResponse = new Mock <HttpWebResponse>();

            mockHttpWebResponse.Setup(p => p.StatusCode).Returns(HttpStatusCode.OK);
            mockHttpWebResponse.Setup(p => p.StatusDescription).Returns("StatusDescription");
            mockHttpWebResponse.Setup(p => p.Headers).Returns(new WebHeaderCollection());
            byte[]       array  = Encoding.UTF8.GetBytes(xmlStr);
            MemoryStream stream = new MemoryStream(array);

            mockHttpWebResponse.Setup(p => p.GetResponseStream()).Returns(stream);
            TeaResponse teaResponse             = new TeaResponse(mockHttpWebResponse.Object);
            Dictionary <string, object> xmlBody = (Dictionary <string, object>)TestHelper.RunInstanceMethod(typeof(BaseClient), "_parseXml", baseClient, new object[] { xmlStr, typeof(ToBodyModel) });
            ToBodyModel teaModel = TeaModel.ToObject <ToBodyModel>(xmlBody);

            Assert.NotNull(teaModel);
            Assert.Equal(1, teaModel.listAllMyBucketsResult.TestDouble);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public XmlUtilTest()
        {
            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;
            model.listAllMyBucketsResult.dict         = new Dictionary <string, string> {
                { "key", "value" }
            };
        }