ivaylokenov/MyTested.AspNetCore.Mvc

Assertion error when testing .NET Core WebApi

boojongmin opened this issue · 2 comments

hi, I'm .net core newbie.
I have trouble when ok assertion

my test code

image

error message

 Message: 
    MyTested.AspNetCore.Mvc.Exceptions.InvocationResultAssertionException : When calling GetTodoItems action in TodoItemsController expected result to be OkResult, but instead received List<TodoItem>.

controller source

image

thank you :)

You are returning a List of TodoItem and not an OK result. You need to use the .Result API:

.ShouldReturn()
.ResultOfType<List<TodoItem>>();

OMG!!

spring framework does response 200 status when return object without throw exception.
I was think asp.net core also same that.

sorry I do close this isuue