Пример #1
0
        /// <summary>
        /// 准备请求数据
        /// </summary>
        /// <returns></returns>
        private async Task PrepareRequestAsync()
        {
            var apiAction        = this.ApiActionDescriptor;
            var validateProperty = this.HttpApiConfig.UseParameterPropertyValidate;

            foreach (var parameter in apiAction.Parameters)
            {
                ApiValidator.ValidateParameter(parameter, validateProperty);
            }

            foreach (var actionAttribute in apiAction.Attributes)
            {
                await actionAttribute.BeforeRequestAsync(this).ConfigureAwait(false);
            }

            foreach (var parameter in apiAction.Parameters)
            {
                foreach (var parameterAttribute in parameter.Attributes)
                {
                    await parameterAttribute.BeforeRequestAsync(this, parameter).ConfigureAwait(false);
                }
            }

            await apiAction.Return.Attribute.BeforeRequestAsync(this).ConfigureAwait(false);
        }
Пример #2
0
        public void ValidateParameterTest()
        {
            var parameter = TestParameter.Create(null);

            Assert.Throws <ValidationException>(() => ApiValidator.ValidateParameter(parameter, true));

            parameter = TestParameter.Create(new User {
            });
            Assert.Throws <ValidationException>(() => ApiValidator.ValidateParameter(parameter, true));

            parameter = TestParameter.Create(new User {
                Account = "123"
            });
            ApiValidator.ValidateParameter(parameter, true);

            parameter = TestParameter.Create(new User {
                Account = "123456"
            });
            Assert.Throws <ValidationException>(() => ApiValidator.ValidateParameter(parameter, true));
        }