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 ExceptionDataWrapperFilter( IOptions <MiCakeAspNetOptions> options, IDataWrapperExecutor wrapperExecutor) { _wrapperExecutor = wrapperExecutor; _options = options.Value?.DataWrapperOptions; }
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); }
public ExceptionHandlerMiddleware( RequestDelegate next, IOptions <MiCakeAspNetOptions> options) { _next = next; _wrapOptions = options.Value?.DataWrapperOptions; _useWrapper = options.Value?.UseDataWrapper ?? false; }
public void WrapperSuccess_NormalData_ShouldReturnApiResponse(object originalData) { DataWrapperOptions options = new DataWrapperOptions(); DataWrapperContext context = new DataWrapperContext(new ObjectResult(originalData), CreateFakeHttpContext("Get", 200), options); var result = _dataWrapperExecutor.WrapSuccesfullysResult(originalData, context); Assert.NotNull(result); Assert.IsType <ApiResponse>(result); }
public void WrapperSuccess_OriginalIsProblemDetail_WrapProblemDetailsIsFalse() { DataWrapperOptions options = new DataWrapperOptions(); var originalProblemDetail = new BadRequestObjectResult(new ProblemDetails() { Title = "This is ProblemDetail" }); DataWrapperContext context = new DataWrapperContext(originalProblemDetail, CreateFakeHttpContext("Get", 400), options); var result = _dataWrapperExecutor.WrapSuccesfullysResult(originalProblemDetail.Value, context); Assert.NotNull(result); Assert.Same(originalProblemDetail.Value, result); }
public void WrapperSuccess_OriginalIsCustomerWrapperData() { var originalData = new TestResultDataWrapper() { CompanyName = "MiCake" }; DataWrapperOptions options = new DataWrapperOptions(); DataWrapperContext context = new DataWrapperContext(new ObjectResult(originalData), CreateFakeHttpContext("Get", 200), options); var result = _dataWrapperExecutor.WrapSuccesfullysResult(originalData, context); Assert.NotNull(result); Assert.Same(originalData, result); }
public void WrapperSuccess_CustomerModel_NullConfig() { var originalData = "dududu"; DataWrapperOptions options = new DataWrapperOptions() { UseCustomModel = true, CustomModelConfig = null }; DataWrapperContext context = new DataWrapperContext(new ObjectResult(originalData), CreateFakeHttpContext("Get", 200), options); var result = _dataWrapperExecutor.WrapSuccesfullysResult(originalData, context); Assert.Same(originalData, result); }
public MiCakeAspNetOptions() { UnitOfWork = new MiCakeAspNetUowOption(); DataWrapperOptions = new DataWrapperOptions(); }