【发布时间】:2017-02-02 11:04:20
【问题描述】:
我正在运行一些集成测试,我希望在我的 ASPNETUsers 表中创建一个“假”用户。
我正在尝试执行以下操作,但没有运气。
所以我的设置如下:-
[SetUp]
public void Setup()
{
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var projectPath = Path.GetFullPath(Path.Combine(basePath, "../../../../SportsStore2.Tests"));
var server = new TestServer(Utils.GetHostBuilder(new string[] { })
.UseContentRoot(projectPath)
.UseEnvironment("Development")
.UseStartup<Startup>());
_client = server.CreateClient();
}
然后插入如下:-
var registerViewModel = new RegisterViewModel
{
Email = "test@test.com",
ConfirmPassword = "testing12345?",
Password = "testing12345?"
};
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var postResponseASPNETUser = await _client.PostAsJsonAsync("http://localhost:49406/Account/Register", registerViewModel);
var createdASPNETUser = await postResponseASPNETUser.Content.ReadAsStringAsync();
但是我收到 400 响应,错误请求。
任何想法我做错了什么?
感谢您的帮助和时间。
【问题讨论】:
-
响应不包含错误请求之外的更多详细信息吗?
-
这就是我得到的:-- RequestMessage {方法:POST,RequestUri:'localhost:49406/Account/Register',版本:1.1,内容:System.Net.Http.ObjectContent`1[SportsStore2. API.Models.AccountViewModels.RegisterViewModel],标题:{ 接受:application/json 主机:localhost:49406 内容类型:application/json; charset=utf-8 }} System.Net.Http.HttpRequestMessage
-
没有什么突出的
标签: c# asp.net asp.net-mvc asp.net-core integration-testing