Reputation: 414
I have Controller whit some endpoints Task<IActionResult> MyCustomEndpoint
which is returning return Ok(CustomDataType)
. Returned datas are in JSON fromat.
Now I want to call that Endpoint from other Controller like var resp = myController.MyCustomEndpoint
, where resp becomes IActionResult
. The problem is that resp
now doesn't return only datas anymore, but all of those fields as seen on image.
My question is, how to access and return only Value
field, because resp.Value
is not working.
Thanks for help.
Upvotes: 4
Views: 8437
Reputation: 435
You have to convert to as ObjectResult
public async Task GetFormSummary_ItShouldReturnSingleForm_NotNull()
{
var formId = new Guid("5EF685E7-1167-4226-7F5E-08D9009544A3");
var mockFormService = new Mock<IFormService>();
mockFormService.Setup(x => x.GetAsync(formId).Result)
.Returns(GetTestForm());
// Inject
var formController = new FormController(_logger, mockFormService.Object);
// Act
var result = (await formController.GetAsync(formId)) as ObjectResult;
// Assert
Assert.IsAssignableFrom<FormViewModel>(result.Value);
}
Upvotes: 1