首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从TestServer启动OWIN TestServer

从TestServer启动OWIN TestServer
EN

Stack Overflow用户
提问于 2016-10-12 13:17:29
回答 1查看 199关注 0票数 0

我有一个工作单元测试,它设置一个TestServer,创建请求并验证响应。

当我从运行这些单元测试时,它们工作得很好。设置TestServer,发出请求并返回正确的响应。

当我从命令行(在我们的CI服务器上)运行相同的代码时,TestServer总是返回"Not“的状态代码。没有其他例外。在从命令行启动OWIN时,是否需要添加特定的命令?

MSTest.exe命令如下所示:

代码语言:javascript
复制
MSTest.exe /testcontainer:myTests.dll /resultsfile:testresults.trx

我的测试方法如下所示:

代码语言:javascript
复制
[TestMethod]
public async Task GetToken()
{
   using (var server = TestServer.Create<TestStartupConfiguration>())
   {
      var response = await server.CreateRequest("/TokenUrl").And(x => x.Content = new FormUrlEncodedContent(new[]
       {
           new KeyValuePair<string, string>("username", user.UserName),
           new KeyValuePair<string, string>("password", user.Password),
           new KeyValuePair<string, string>("grant_type", "password")
        })).PostAsync();

       response.IsSuccessStatusCode.Should().BeTrue("this is the expected return value of an Access Token request");
       var responseString = await response.Content.ReadAsStringAsync();
       responseString.Should().NotBeNullOrWhiteSpace("the response of an Access Token request should not be empty");
    }
}

而且,正如我所说的,测试在中运行得很好。所有其他单元测试都按预期从命令行执行。

非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-09 04:31:23

我找到了解决问题的办法。出现NotFound错误是因为我想测试的OAuth配置在作为单元测试运行时将AllowInsecureHttp属性设置为false。我确保AllowInsecureHttp不仅在DEBUG模式下是true,而且在单元测试运行时也是如此。

现在它工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39999625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档