我有后端端点Task<ActionResult> Post(IFormFile csvFile)
,我需要从 HttpClient 调用这个端点。目前我得到Unsupported media type error
. 这是我的代码:
var filePath = Path.Combine("IntegrationTests", "file.csv");
var gg = File.ReadAllBytes(filePath);
var byteArrayContent = new ByteArrayContent(gg);
var postResponse = await _client.PostAsync("offers", new MultipartFormDataContent
{
{byteArrayContent }
});
Run Code Online (Sandbox Code Playgroud) 我已经AsyncPageable<T>
并且只想获得列表中的第一个结果。
MS 文档建议使用await foreach
// call a service method, which returns AsyncPageable<T>
AsyncPageable<SecretProperties> allSecretProperties = client.GetPropertiesOfSecretsAsync();
await foreach (SecretProperties secretProperties in allSecretProperties)
{
Console.WriteLine(secretProperties.Name);
}
Run Code Online (Sandbox Code Playgroud)
有没有什么有效的方法可以只得到第一个结果?就像是FirstOrDefaultAsync()
?
目前我正在使用这段代码来获得第一个结果。
var enumerator = response.Value.GetResultsAsync().GetAsyncEnumerator();
await enumerator.MoveNextAsync();
var result = enumerator.Current;
Run Code Online (Sandbox Code Playgroud) 我正在寻找 .Net 框架中的 trie 内置实现。.Net数据结构中有类似Trie的东西吗?
在 asp.net core 2.1 中,我可以这样创建IHostingEnvironment
:
public IHostingEnvironment CreateHostingEnvironment()
{
var hosting = new HostingEnvironment()
{
EnvironmentName = "IntegrationTests"
};
return hosting;
}
Run Code Online (Sandbox Code Playgroud)
在 Asp.net core 3.1 中,它已更改为IWebHostEnvironment
但我需要以类似的方式创建它。可能的目标是创建此对象并设置环境名称。
public IWebHostEnvironment CreateWebHostEnvironment()
{
var host = new WebHostEnvironment(); // ???
}
Run Code Online (Sandbox Code Playgroud) 我看到这些方法如何转换为 sql:
FirstOrDefault()
->Select TOP(1) ...
SingleOrDefault()
->Select TOP(2) ...
所以我有两个问题:
SingleOrDefault()
扫描整个表并且比 慢大约 2 倍FirstOrDefault()
?PK
并确定只有一个结果时?我以这种方式添加 chrome 选项,如果我使用代理 ip 身份验证,它就可以工作。
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument('--proxy-server=92.128.165.143:3399')
driver = uc.Chrome(options=options)
Run Code Online (Sandbox Code Playgroud)
但是,我有一个具有以下格式身份验证的代理:
http://username:password@91.92.128.165.143:3399
如果我添加它就像
options.add_argument('--proxy-server=http://username:password@91.92.128.165.143:3399')
Run Code Online (Sandbox Code Playgroud)
它不起作用。我如何使用用户名/密码添加它?这仅适用于未检测到的 Chrome 驱动程序。
proxy selenium selenium-chromedriver undetected-chromedriver
我终于设法通过以下命令在 bitbucket 管道中制作测试报告:
- dotnet test MyTests --logger "trx;LogFileName=test-reports/results.xml"
Run Code Online (Sandbox Code Playgroud)
构建拆解 说:
Found matching test report file MyPath/test-reports/results.xml
Finished scanning for test reports. Found 1 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.
Run Code Online (Sandbox Code Playgroud)
但是,我在 bitbucket 中看不到这些测试结果文件。我知道管道窗口中应该有一个新选项卡或类似的东西。有什么建议如何在漂亮的展示窗口中看到它们吗?
没有找到任何文档或文章。
testing automated-tests bitbucket .net-core bitbucket-pipelines
我正在为单元测试创建 SQLite In Memory 数据库:
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
try
{
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseSqlite(connection)
.Options;
// Create the schema in the database
using (var context = new BloggingContext(options))
{
context.Database.EnsureCreated();
}
// Run the test against one instance of the context
using (var context = new BloggingContext(options))
{
var service = new BlogService(context);
service.Add("http://sample.com");
}
// Use a separate instance of the context to verify correct data was saved to database
using (var context = …
Run Code Online (Sandbox Code Playgroud) 我已经在 Asp.net core 应用程序中设置了应用程序见解。我的所有 Web API 请求都会在应用程序洞察中进行跟踪,如果我遇到任何失败,我可以简单地在Failures
部分中找到它们。
但是,我还运行了 Hangfire 后台作业,如果它们失败,我无法在应用程序洞察中找到它们。另外,我有警报规则Whenever the total http server errors is greater than or equal to 1 count
,我不确定在这种情况下是否会出现hangfire 5xx 错误。
那么有什么方法可以跟踪 Hangfire 作业失败并获得相关通知吗?
我正在使用带有 git 集成的 Visual Studio Team Explorer 进行源代码控制。它工作得很好,但有时我需要运行一些更高级的 git 命令,所以我要去文件资源管理器并打开 git bash。我可以在 Visual Studio 中运行 git 命令吗?
使用 Visual Studio 19。
我正在用一个命令从解决方案级别运行所有测试项目:
dotnet test
运行所有测试项目如何使所有测试项目(程序集)并行运行?
在Visual Studio中,有一个简单的按钮“并行运行测试”,它可以正常工作,但是我需要对CI使用dotnet core测试命令。
c# ×5
.net ×4
asp.net-core ×4
.net-core ×2
testing ×2
appinsights ×1
async-await ×1
bitbucket ×1
ef-core-2.0 ×1
ef-core-2.1 ×1
git ×1
hangfire ×1
http ×1
post ×1
proxy ×1
selenium ×1
sql-server ×1
sqlite ×1
telemetry ×1
trie ×1
xunit ×1
xunit2 ×1