如何为重定向到URL的Web api控制器创建单元测试 [英] How do I create unit test for a web api controller which redirects to a URL
本文介绍了如何为重定向到URL的Web api控制器创建单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为重定向到网址的控制器创建一个单元测试。
我尝试了什么:
public IHttpActionResult RedirectMethod(FormDataCollection collection)
{
...
...
...
...
var url = new Uri(redirectUrl,UriKind.Relative);
return 重定向(网址)
}
解决方案
< blockquote>看看这些测试框架: https://www.slant.co / topics / 10642 / ~framesto-test-rest-server [ ^ ]
失眠看起来很有前途,可以生成代码C#和其他语言: https://www.slant.co/topics/ 7913 / viewpoints / 4 / ~rest-api-clients~失眠 [ ^ ]
I am trying to create a unit test for a controller which redirects to a URL.
What I have tried:
public IHttpActionResult RedirectMethod(FormDataCollection collection)
{
...
...
...
...
var url = new Uri(redirectUrl, UriKind.Relative);
return Redirect(url)
}
解决方案
Take a look at these test frameworks: https://www.slant.co/topics/10642/~frameworks-to-test-rest-server[^]
Insomnia looks very promising and can generate code in C# and other languages: https://www.slant.co/topics/7913/viewpoints/4/~rest-api-clients~insomnia[^]
这篇关于如何为重定向到URL的Web api控制器创建单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文