使用:NETCore.App 1.1,xunit 2.2.0-beta4-build3444,Moq 4.6.38-alpha.
我试图测试一个ASP.Net核心控制器,它需要一个名为"X-ClientID"的标头出现在请求中.我现在写了我的测试函数如下:
[Fact]
public void Test1()
{
var controller = new GraphController(this.positiveAuthorizer, this.loggerFactory, this.elasticsearchSettings);
controller.Request.Headers.Add("X-ClientID", "1234");
var result = controller.Get("calls", "year", "day", "1", "sliding", new DateTime(2016, 11, 1)).Result;
// TODO: Write assert statements on result
}
Run Code Online (Sandbox Code Playgroud)
positiveAuthorizer,loggerFactory并且elasticsearchSettings是使用Moq的模拟类,它们在控制器内按预期工作.
不过controller.Request是null.此外,controller.Request是get-only,所以我无法将其设置为新值.
如何在调用控制器之前设置X-Client标头?
我有一个asp.net核心网络API,可启用tts请求。您基本上要求http://server.url/Whatever you want it to say.mp3获得带有tts语音文本的mp3。
但是问题是,400 - The request URL is invalid如果我传递一个长字符串,它将返回a 。好像服务器正在达到某种最大URL长度限制。我可以找到有关如何解决此问题的信息,这是“经典” asp.net web.config,而在asp.net核心中却找不到如何解决此问题。
在asp.net核心中增加最大URL长度的正确方法是什么?
更新:
确切的网址例如是:
它是URL编码的。我将尝试找出确切的最大值。
我无法使用POST,因为要利用它的工具仅支持mp3文件的网址(因此,在控制器中使用了.mp3扩展名)。
更新2
它接受的最长请求包含397个字符,这似乎不太合逻辑。如果再添加一个,它将返回代码400。
更新3
事实证明,仅当将其部署在服务器上(使用IIS),在本地运行时,它才支持更长的字符串(我还没有看到它返回代码400)。我将不得不调查IIS,看看它出了什么问题。
我的 gitlab-ci.yml 中有这个:
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_HOST: "tcp://docker:2375"
determine version:
stage: preparation
tags:
- docker
image: gittools/gitversion
script:
- pwd
- echo $(pwd)
- gitversion /output json /showvariable FullSemVer > version.txt
- cat version.txt
artifacts:
paths:
- version.txt
expire_in: 1 hr
Run Code Online (Sandbox Code Playgroud)
当它在我的跑步者上运行时,我得到这个:
1 Running with gitlab-runner 12.6.0 (ac8e767a)
2 on gitlab-runner-01 efEDOrEf
3
Using Docker executor with image gittools/gitversion ...
4 Pulling docker image gittools/gitversion ...
5 Using docker image sha256:2d1d36c0807eaeedc8d4a81b72ae3ee16f7c6a1d25bdce22c8e1983ac6c98dcb for gittools/gitversion ...
7
Running on runner-efEDOrEf-project-475-concurrent-0 …Run Code Online (Sandbox Code Playgroud)