public void WrapperSuccess_MoreCustomerModel() { var originalData = "dududu"; CustomWrapperModel customWrapperModel = new CustomWrapperModel(); customWrapperModel.AddProperty("Name", s => "Name"); customWrapperModel.AddProperty("Person", s => "Person"); customWrapperModel.AddProperty("Old", s => "1"); CustomWrapperModel customWrapperModel2 = new CustomWrapperModel(); customWrapperModel2.AddProperty("DiDiDi", s => "DiDiDi"); var costomConfigs = new Dictionary <Range, CustomWrapperModel>(); costomConfigs.Add(200..201, customWrapperModel); costomConfigs.Add(300..401, customWrapperModel2); DataWrapperOptions options = new DataWrapperOptions() { UseCustomModel = true, CustomModelConfig = costomConfigs }; DataWrapperContext context = new DataWrapperContext(new ObjectResult(originalData), CreateFakeHttpContext("Get", 200), options); var result = _dataWrapperExecutor.WrapSuccesfullysResult(originalData, context); Assert.NotNull(result.GetType().GetProperty("Name").Name); DataWrapperContext context2 = new DataWrapperContext(new ObjectResult(originalData), CreateFakeHttpContext("Get", 300), options); var result2 = _dataWrapperExecutor.WrapSuccesfullysResult(originalData, context2); Assert.NotNull(result2.GetType().GetProperty("DiDiDi").Name); }
public void WrapperSuccess_OneCustomerModel_InRange() { var originalData = "dududu"; CustomWrapperModel customWrapperModel = new CustomWrapperModel(); customWrapperModel.AddProperty("Name", s => "Name"); customWrapperModel.AddProperty("Person", s => "Person"); customWrapperModel.AddProperty("Old", s => "1"); var costomConfigs = new Dictionary <Range, CustomWrapperModel>(); costomConfigs.Add(200..300, customWrapperModel); DataWrapperOptions options = new DataWrapperOptions() { UseCustomModel = true, CustomModelConfig = costomConfigs }; DataWrapperContext context = new DataWrapperContext(new ObjectResult(originalData), CreateFakeHttpContext("Get", 200), options); var result = _dataWrapperExecutor.WrapSuccesfullysResult(originalData, context); Assert.NotNull(result); Assert.IsAssignableFrom <IResultDataWrapper>(result); }
private static CustomWrapperModel CreateCustomModel() { CustomWrapperModel result = new CustomWrapperModel("MiCakeCustomModel"); result.AddProperty("company", s => "MiCake"); result.AddProperty("statusCode", s => (s.ResultData as ObjectResult).StatusCode ?? s.HttpContext.Response.StatusCode); result.AddProperty("result", s => (s.ResultData as ObjectResult).Value); return(result); }