小编Dei*_*kis的帖子

如何使用 HttpClient 发布表单数据 IFormFile?

我有后端端点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)

c# post http multipartform-data asp.net-core

18
推荐指数
3
解决办法
2万
查看次数

AsyncPageable&lt;T&gt; 异步获取第一个结果

我已经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)

c# async-await

9
推荐指数
2
解决办法
7787
查看次数

EF核心一对多关系:ICollection或哈希集?

我正在阅读乔恩·史密斯(Jon P Smith)的“ Entity Framework Core in Action”。那里说:

在此处输入图片说明

当Hashet是适当的集合类型时,您能否提供一些示例?又为什么呢?

.net entity-framework entity-framework-core asp.net-core

7
推荐指数
1
解决办法
616
查看次数

.NET 中是否有等效的 Trie 数据结构?

我正在寻找 .Net 框架中的 trie 内置实现。.Net数据结构中有类似Trie的东西吗?

.net c# trie data-structures

7
推荐指数
0
解决办法
1505
查看次数

手动创建 IWebHostEnvironment asp.net core 3.1

在 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)

.net c# asp.net-core asp.net-core-3.1

7
推荐指数
1
解决办法
4165
查看次数

EF Core:FirstOrDefault() 与 SingleOrDefault() 性能比较

我看到这些方法如何转换为 sql:

  • FirstOrDefault()->Select TOP(1) ...
  • SingleOrDefault()->Select TOP(2) ...

所以我有两个问题:

  • 我们是否可以假设在仅一种现有结果场景中SingleOrDefault()扫描整个表并且比 慢大约 2 倍FirstOrDefault()
  • 有什么建议应该使用哪种方法吗?例如,当我们查询PK并确定只有一个结果时?

sql-server entity-framework-core

6
推荐指数
1
解决办法
3172
查看次数

未检测到的 chromedriver 如何使用用户名/密码添加代理?

我以这种方式添加 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

6
推荐指数
1
解决办法
6322
查看次数

无法查看.Net Core bitbucket pipelines 测试结果

我终于设法通过以下命令在 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

5
推荐指数
1
解决办法
2379
查看次数

内存中的 EF Core SQLite 异常:SQLite 错误 1:“接近“MAX”:语法错误”

我正在为单元测试创​​建 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)

c# sqlite entity-framework-core ef-core-2.0 ef-core-2.1

5
推荐指数
1
解决办法
2863
查看次数

通过应用洞察跟踪hangfire后台作业

我已经在 Asp.net core 应用程序中设置了应用程序见解。我的所有 Web API 请求都会在应用程序洞察中进行跟踪,如果我遇到任何失败,我可以简单地在Failures部分中找到它们。

应用洞察

但是,我还运行了 Hangfire 后台作业,如果它们失败,我无法在应用程序洞察中找到它们。另外,我有警报规则Whenever the total http server errors is greater than or equal to 1 count,我不确定在这种情况下是否会出现hangfire 5xx 错误。

那么有什么方法可以跟踪 Hangfire 作业失败并获得相关通知吗?

telemetry hangfire asp.net-core appinsights

5
推荐指数
2
解决办法
2122
查看次数

我可以在 Visual Studio 中运行 Git 命令吗?

我正在使用带有 git 集成的 Visual Studio Team Explorer 进行源代码控制。它工作得很好,但有时我需要运行一些更高级的 git 命令,所以我要去文件资源管理器并打开 git bash。我可以在 Visual Studio 中运行 git 命令吗?

使用 Visual Studio 19。

git visual-studio visual-studio-2019

5
推荐指数
3
解决办法
1万
查看次数

“ dotnet测试”:如何并行运行xunit测试项目?

我正在用一个命令从解决方案级别运行所有测试项目: dotnet test运行所有测试项目如何使所有测试项目(程序集)并行运行?

在Visual Studio中,有一个简单的按钮“并行运行测试”,它可以正常工作,但是我需要对CI使用dotnet core测试命令。

.net testing xunit .net-core xunit2

4
推荐指数
1
解决办法
3470
查看次数