1- using System . Threading . Tasks ;
1+ using System . IO ;
2+ using System . Threading . Tasks ;
23using Microsoft . AspNetCore . Http ;
34using Moq ;
45using NUnit . Framework ;
56using Simplify . Web . Http . ResponseWriting ;
67using Simplify . Web . Modules . Context ;
78using Simplify . Web . Responses ;
8- using Stream = System . IO . Stream ;
9+ using File = Simplify . Web . Responses . File ;
910
1011namespace Simplify . Web . Tests . Responses ;
1112
@@ -83,10 +84,9 @@ public async Task Process_Stream_StreamSentAndDisposed()
8384 {
8485 // Arrange
8586
86- var stream = new Mock < Stream > { CallBase = false } ;
87- stream . SetupGet ( x => x . CanRead ) . Returns ( true ) ;
87+ var stream = new DisposableMemoryStream ( ) ;
8888
89- var file = new Mock < File > ( stream . Object , "application/example" , null ! ,
89+ var file = new Mock < File > ( stream , "application/example" , null ! ,
9090 ContentDispositionType . Inline , null ! , null ! , 200 )
9191 { CallBase = true } ;
9292
@@ -101,11 +101,26 @@ public async Task Process_Stream_StreamSentAndDisposed()
101101 Assert . That ( result , Is . EqualTo ( ResponseBehavior . RawOutput ) ) ;
102102 Assert . That ( _headerDictionary [ "Content-Disposition" ] , Is . EqualTo ( "inline" ) ) ;
103103
104- _responseWriter . Verify ( x => x . WriteAsync ( It . IsAny < HttpResponse > ( ) , It . Is < Stream > ( s => s == stream . Object ) ) ) ;
105- #if NETFRAMEWORK
106- stream . Verify ( x => x . Dispose ( ) ) ;
107- #else
108- stream . Verify ( x => x . DisposeAsync ( ) ) ;
104+ _responseWriter . Verify ( x => x . WriteAsync ( It . IsAny < HttpResponse > ( ) , It . Is < Stream > ( s => s == stream ) ) ) ;
105+ Assert . That ( stream . Disposed , Is . True ) ;
106+ }
107+
108+ private class DisposableMemoryStream : MemoryStream
109+ {
110+ public bool Disposed { get ; private set ; }
111+
112+ protected override void Dispose ( bool disposing )
113+ {
114+ Disposed = true ;
115+ base . Dispose ( disposing ) ;
116+ }
117+
118+ #if ! NETSTANDARD2_0
119+ public override async ValueTask DisposeAsync ( )
120+ {
121+ Disposed = true ;
122+ await base . DisposeAsync ( ) ;
123+ }
109124#endif
110125 }
111- }
126+ }
0 commit comments