コード例 #1
0
ファイル: CommonTest.cs プロジェクト: aliyun/tea-util
        public void Test_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"
            };
            Dictionary <string, object> dic = model.ToMap();

            Assert.NotNull(dic);
            Assert.IsType <List <object> >(dic["items"]);

            TestRegModel modelEmpty = new TestRegModel();

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

            Assert.Null(dicEmpty["items"]);
            Assert.Null(dicEmpty["subModel"]);
        }
コード例 #2
0
ファイル: CommonTest.cs プロジェクト: aliyun/tea-util
        public void Test_ValidateModel()
        {
            TeaModel modelNull = null;

            Assert.Throws <ArgumentException>(() => { modelNull.Validate(); });

            TestRegModel successModel = new TestRegModel();

            successModel.RequestId   = "reTest";
            successModel.NextMarker  = "nextMarker";
            successModel.testListStr = new List <string> {
                "listStr1"
            };
            successModel.Items = new List <TestRegSubModel> {
                new TestRegSubModel {
                    RequestId = "rTest"
                }
            };
            successModel.subModel = new TestRegSubModel {
                RequestId = "rTest", testInt = 10
            };
            successModel.Validate();

            successModel.testListStr = null;
            successModel.Validate();

            TestRegModel modelRequired = new TestRegModel();

            Assert.Equal("RequestId is required.",
                         Assert.Throws <ArgumentException>(() => { modelRequired.Validate(); }).Message
                         );

            modelRequired.RequestId  = "reTest";
            modelRequired.NextMarker = "nextMarker";
            Assert.Equal("Items is required.",
                         Assert.Throws <ArgumentException>(() => { modelRequired.Validate(); }).Message
                         );

            TestRegModel modelReg = new TestRegModel();

            modelReg.RequestId = "123";
            modelReg.Items     = new List <TestRegSubModel> {
                new TestRegSubModel {
                    RequestId = "rTest"
                }
            };
            modelReg.NextMarker = "nextMarker";
            Assert.Equal("RequestId is not match re",
                         Assert.Throws <ArgumentException>(() => { modelReg.Validate(); }).Message
                         );

            modelReg.RequestId   = "reTest";
            modelReg.testListStr = new List <string> {
                "test"
            };
            Assert.Equal("testListStr is not match listStr",
                         Assert.Throws <ArgumentException>(() => { modelReg.Validate(); }).Message
                         );
        }