File tree Expand file tree Collapse file tree 2 files changed +68
-1
lines changed Expand file tree Collapse file tree 2 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ public virtual Task StartAsync(CancellationToken cancellationToken = default)
111
111
}
112
112
113
113
/// <summary>
114
- /// This calls StartAsync if it has not previoulsy been called.
114
+ /// This calls StartAsync if it has not previously been called.
115
115
/// It will complete the adapted pipe if it exists.
116
116
/// </summary>
117
117
/// <returns></returns>
@@ -128,6 +128,11 @@ public virtual async Task CompleteAsync()
128
128
return ;
129
129
}
130
130
131
+ if ( ! _started )
132
+ {
133
+ await StartAsync ( ) ;
134
+ }
135
+
131
136
_completed = true ;
132
137
133
138
if ( _pipeWriter != null )
Original file line number Diff line number Diff line change
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+ using System . Buffers ;
5
+ using System . IO ;
6
+ using System . IO . Pipelines ;
7
+ using System . Text ;
8
+ using System . Threading ;
9
+ using System . Threading . Tasks ;
10
+ using Xunit ;
11
+
12
+ namespace Microsoft . AspNetCore . Http . Features
13
+ {
14
+ public class StreamResponseBodyFeatureTests
15
+ {
16
+ [ Fact ]
17
+ public async Task CompleteAsyncCallsStartAsync ( )
18
+ {
19
+ // Arrange
20
+ var stream = new MemoryStream ( ) ;
21
+ var streamResponseBodyFeature = new TestStreamResponseBodyFeature ( stream ) ;
22
+
23
+ // Act
24
+ await streamResponseBodyFeature . CompleteAsync ( ) ;
25
+
26
+ //Assert
27
+ Assert . Equal ( 1 , streamResponseBodyFeature . StartCalled ) ;
28
+ }
29
+
30
+ [ Fact ]
31
+ public async Task CompleteAsyncWontCallsStartAsyncIfAlreadyStarted ( )
32
+ {
33
+ // Arrange
34
+ var stream = new MemoryStream ( ) ;
35
+ var streamResponseBodyFeature = new TestStreamResponseBodyFeature ( stream ) ;
36
+ await streamResponseBodyFeature . StartAsync ( ) ;
37
+
38
+ // Act
39
+ await streamResponseBodyFeature . CompleteAsync ( ) ;
40
+
41
+ //Assert
42
+ Assert . Equal ( 1 , streamResponseBodyFeature . StartCalled ) ;
43
+ }
44
+ }
45
+
46
+ public class TestStreamResponseBodyFeature : StreamResponseBodyFeature
47
+ {
48
+ public TestStreamResponseBodyFeature ( Stream stream )
49
+ : base ( stream )
50
+ {
51
+
52
+ }
53
+
54
+ public override Task StartAsync ( CancellationToken cancellationToken = default )
55
+ {
56
+ StartCalled ++ ;
57
+ return base . StartAsync ( cancellationToken ) ;
58
+ }
59
+
60
+ public int StartCalled { get ; private set ; }
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments