public void GetBy_输入类型参数_返回存储的类型一致() { //arrange Type t = typeof(UnifiedOrderRequest); //act RequestEntityInfo r = RequestEntityManager.GetBy(t); //assert Assert.IsTrue(t == r.RequestType); }
public void Generate_输入类型参数_返回的RequestEntityInfo对象内部信息正确() { //arrange Type type = typeof(UnifiedOrderRequest); //act RequestEntityInfo target = RequestEntityProvider.Generate(type); //assert Assert.IsTrue(target.RequestParameterDict.Count == 16); Assert.IsTrue(target.RequestIndexDict.Count == 16); }
/// <summary> /// 检验参数是否为必填项 /// </summary> public virtual void Validate() { RequestEntityInfo requestEntityInfo = RequestEntityManager.GetBy(this.GetType()); foreach (var item in requestEntityInfo.RequestParameterDict) { string propertyName = item.Key; RequestParameterAttribute parameterAttritube = item.Value; if (parameterAttritube.IsRequire) { int piIndex = requestEntityInfo.RequestIndexDict[propertyName]; object o = requestEntityInfo.PiArray[piIndex].GetValue(this, null); if (o == null || o.ToString() == string.Empty) { throw new RequestParameterIsRequireException(propertyName); } } } }
/// <summary> /// 获取请求参数字典集合 /// </summary> /// <returns></returns> public virtual Dictionary <string, string> GetParameterDict() { Dictionary <string, string> result = new Dictionary <string, string>(); RequestEntityInfo requestEntityInfo = RequestEntityManager.GetBy(this.GetType()); foreach (var item in requestEntityInfo.RequestParameterDict) { string propertyName = item.Key; RequestParameterAttribute parameterAttritube = item.Value; string parameterName = parameterAttritube.Name; int piIndex = requestEntityInfo.RequestIndexDict[propertyName]; object value = requestEntityInfo.PiArray[piIndex].GetValue(this, null); if (value != null && value.ToString() != string.Empty) { result.Add(parameterName, value.ToString()); } } return(result); }