Skip to content
代码片段 群组 项目
未验证 提交 4573f689 编辑于 作者: Kahbazi's avatar Kahbazi 提交者: GitHub
浏览文件

Call StartAsync in CompleteAsync (#24058)

上级 0889a622
No related branches found
No related tags found
无相关合并请求
...@@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Http ...@@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Http
} }
/// <summary> /// <summary>
/// This calls StartAsync if it has not previoulsy been called. /// This calls StartAsync if it has not previously been called.
/// It will complete the adapted pipe if it exists. /// It will complete the adapted pipe if it exists.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
...@@ -128,6 +128,11 @@ namespace Microsoft.AspNetCore.Http ...@@ -128,6 +128,11 @@ namespace Microsoft.AspNetCore.Http
return; return;
} }
if (!_started)
{
await StartAsync();
}
_completed = true; _completed = true;
if (_pipeWriter != null) if (_pipeWriter != null)
......
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Buffers;
using System.IO;
using System.IO.Pipelines;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.AspNetCore.Http.Features
{
public class StreamResponseBodyFeatureTests
{
[Fact]
public async Task CompleteAsyncCallsStartAsync()
{
// Arrange
var stream = new MemoryStream();
var streamResponseBodyFeature = new TestStreamResponseBodyFeature(stream);
// Act
await streamResponseBodyFeature.CompleteAsync();
//Assert
Assert.Equal(1, streamResponseBodyFeature.StartCalled);
}
[Fact]
public async Task CompleteAsyncWontCallsStartAsyncIfAlreadyStarted()
{
// Arrange
var stream = new MemoryStream();
var streamResponseBodyFeature = new TestStreamResponseBodyFeature(stream);
await streamResponseBodyFeature.StartAsync();
// Act
await streamResponseBodyFeature.CompleteAsync();
//Assert
Assert.Equal(1, streamResponseBodyFeature.StartCalled);
}
}
public class TestStreamResponseBodyFeature : StreamResponseBodyFeature
{
public TestStreamResponseBodyFeature(Stream stream)
: base(stream)
{
}
public override Task StartAsync(CancellationToken cancellationToken = default)
{
StartCalled++;
return base.StartAsync(cancellationToken);
}
public int StartCalled { get; private set; }
}
}
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册