public override void OnActionExecuted(ActionExecutedContext context) { if (context.Result == null) { return; } if (BadActionResultTransformer.IsBadAction(context.Result)) { var transformed = BadActionResultTransformer.Transform(context.Result); context.Result = new ObjectResult(transformed) { StatusCode = transformed.Errors.First().Status }; return; } var responseResult = (ObjectResult)context.Result; var relationshipPaths = FindRelationshipPathsToInclude(context.HttpContext.Request); if (!configuration.ValidateIncludedRelationshipPaths(relationshipPaths, responseResult.Value)) { context.Result = new HttpStatusCodeResult(400); return; } var jsonApiContext = new Context( configuration, new Uri(context.HttpContext.Request.GetDisplayUrl()), relationshipPaths); responseResult.Value = jsonApiTransformer.Transform(responseResult.Value, jsonApiContext); }
public void GIVEN_ABadAction_WHEN_IsBadAction_THEN_True() { // Arrange var objectResult = new HttpNotFoundObjectResult("1234"); // Act var result = BadActionResultTransformer.IsBadAction(objectResult); // Assert Assert.True(result); }
public void GIVEN_AGoodAction_WHEN_IsBadAction_THEN_False() { // Arrange var objectResult = new JsonResult(new Post()); // Act var result = BadActionResultTransformer.IsBadAction(objectResult); // Assert Assert.False(result); }
public void OnResourceExecuted(ResourceExecutedContext context) { if (context.Result == null || context.Result is NoContentResult) { return; } if (BadActionResultTransformer.IsBadAction(context.Result)) { var transformed = BadActionResultTransformer.Transform(context.Result); context.Result = new ObjectResult(transformed) { StatusCode = transformed.Errors.First().Status }; } }