Ejemplo n.º 1
0
        public void TestValidator()
        {
            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.bytes = Encoding.UTF8.GetBytes("test");
            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
                         );
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Validate model
 /// </summary>
 /// <param name="model"></param>
 public static void ValidateModel(TeaModel model)
 {
     model.Validate();
 }