我有一个web api,我想测试一下。当我使用浏览器调用它时,它返回一个json,如:
{
message: "An error has occurred.",
exceptionMessage: "Self referencing loop detected with type ......",
exceptionType: "Newtonsoft.Json.JsonSerializationException",
stackTrace: " at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
"
}
但是当我在我的单元测试中使用Owin TestServer
调用它时,它只返回一个没有所有细节的简单json:
{
message: "An error has occurred."
}
在我的单元测试中,我正在调用这样的api:
var response = OwinServer.HttpClient.GetAsync("api/Products/GetAll").Result;
if (response.StatusCode != HttpStatusCode.OK)
{
var errorStr = response.Content.ReadAsStringAsync().Result;
Assert.Fail(errorStr) // this errorStr is not complete enough!
}
我能做些什么有完整的错误,特别是 stackTrace ?