我有一个 Web-API .NET Core 2.2 项目,我正在尝试对其进行集成测试。
我遵循了Microsoft的指南。从测试运行器和命令行启动它们时,测试通过,它们应该正确配置,我可以通过 WebApplicationFactory - HTTP 客户端调用控制器。我已经通过 xunit.runner.json 禁用了卷影复制 到目前为止一切顺利。
我正在尝试使用 Azure DevOps 来部署我的项目,在发布步骤中,我添加了一个测试步骤,该步骤获取构建工件、下载它并运行测试。基本上,在本地计算机上复制,这将转换为:
dotnet publish testProject.csproj <path_on_disk>
cd <path_on_disk>
vstest.console.exe testProject.dll
Run Code Online (Sandbox Code Playgroud)
从已发布的文件夹运行测试时,出现以下错误
Failed wInvoiceIntegrationTests.Controllers.Authentication.AuthenticationControllerTests.AuthenticationController_Register_InputDoesNotRespectsModel_DoesNotRegistersUser(email: "abcd@@.com", password: "Abcdefgh1")
Error Message:
System.InvalidOperationException : Solution root could not be located using application root C:\Users\mihai\Desktop\publish\.
Stack Trace:
at Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(IWebHostBuilder builder, String solutionRelativePath, String applicationBasePath, String solutionName)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.SetContentRoot(IWebHostBuilder builder)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
Run Code Online (Sandbox Code Playgroud)
我没有需要服务也不想提供的静态文件,我只是想测试控制器。路径是正确的,这就是测试 dll 所在的位置,并且还包含项目 dll。
与此同时,我已经设法让测试在构建阶段通过 azure 运行
ls *Tests*/*.csproj | xargs …
Run Code Online (Sandbox Code Playgroud) 我使用 VS code(这是一个非常强大的轻量级文本编辑器)启动了一个 asp.net core 项目。我想将单元测试项目添加到我已有的项目中。在 Visual Studio 中,我通过在我的解决方案下创建一个新项目来做到这一点。在 vs code 中我只能创建一个新目录,我应该如何添加单元测试项目?
我需要填写appsetting.json
ASP.NET Core 2.2 中的以下信息。
"SiteSetting": {
"JwtSetting": {
"SecretKey": "LongerThan-16Char-SecretKey",
"Issuer": "MyWebsite",
"Audience": "MyWebsite",
"NotBeforeMinutes": "0",
"ExpirationMinutes": "60"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的SiteSetting
课:
public class SiteSetting
{
public JwtSetting JwtSettings { get; set; }
}
public class JwtSetting
{
public string SecretKey { get; set; }
public string Issuer { get; set; }
public string Audience { get; set; }
public int NotBeforeMinutes { get; set; }
public int ExpirationMinutes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这段代码来Startup.cs
填充 …
我试图在visual studio中创建一个项目,我在选择WebApi项目后选择了个人用户帐户选项,现在在VS 2019中它似乎与以前有很大不同,现在要求了一些参数,谁能给我一些例子如何配置它?
它在询问:
Domain Name
Application ID
Sign-up or Sign-in Policy
Run Code Online (Sandbox Code Playgroud)
默认情况下,它像唯一的选项一样被选中:
Connect to an existing user store in the cloud
Run Code Online (Sandbox Code Playgroud) 我正在使用 Linux,更具体地说是 Xubuntu。我已经在我的机器上安装了 SQL Server Express。我目前正在制作一个网络应用程序,但我的连接似乎无法正常工作,或者我对所有内容都不太了解?
我得到的输出是:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有我可能找到的方法,但没有任何效果。这可能是因为缺乏 Linux 用户的信息,但我仍然无法弄清楚。
通常,我正在尝试使用 EF 核心在我的控制台应用程序中使用连接字符串连接到我的本地 SQL 服务器。像这样:
internal const string CONNECTION_STRING =
"Server = .\\SQLEXPRESS; Database = Questionnaires; Integrated Security = True"; …
Run Code Online (Sandbox Code Playgroud) c# linux entity-framework entity-framework-core asp.net-core
我必须强制这些变量重复使用我想要使用的每一个,这让我很难.我需要创建一个类来定义这些变量并在整个程序中使用它们.我怎样才能做到这一点?
string RootFolderName = "Uplaod";
string ProductPictureFolder = "ProductPictureFolder";
string ProductMainPictureFolder = "ProductMainPicture";
string WebRootPath = _hostingEnvironment.WebRootPath;
string RootPath = Path.Combine(WebRootPath, RootFolderName);
string ProductPicturePath = Path.Combine(WebRootPath, RootFolderName, ProductPictureFolder);
string ProductMainPicturePath = Path.Combine(WebRootPath, RootFolderName, ProductPictureFolder, ProductMainPictureFolder);
string newPath = Path.Combine(WebRootPath, ProductMainPicturePath);
Run Code Online (Sandbox Code Playgroud) I am working on an API which can return a list of Users:
"users": [
{
"userId": 1,
"name": "John Smith"
"address": {
"countryCode": "gb",
"street": "Orford Street 20",
"locality": "London"
}
"skills": [
{ "skillId": 1, "name": "design" },
{ "skillId": 2, "name": "logotype" }
]
}
]
Run Code Online (Sandbox Code Playgroud)
Consider I need to create a User with address and skills.
Which body format is more commonly used? Something kind of flatten:
"users": [
{
"name": "John Smith"
"addressCountryCode": "gb",
"addressStreet": …
Run Code Online (Sandbox Code Playgroud) asp.net-core ×7
c# ×2
.net ×1
api ×1
api-design ×1
asp.net ×1
azure-devops ×1
linux ×1
login ×1
testing ×1
unit-testing ×1
xunit.net ×1