File tree Expand file tree Collapse file tree 3 files changed +53
-3
lines changed
MongoDB.Driver.GridFS.Tests Expand file tree Collapse file tree 3 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 1818using System . IO ;
1919using System . Linq ;
2020using System . Text ;
21+ using System . Threading ;
2122using System . Threading . Tasks ;
2223using FluentAssertions ;
2324using MongoDB . Bson ;
@@ -71,6 +72,28 @@ public void CopyTo_should_copy_stream(
7172 }
7273 }
7374
75+ [ Test ]
76+ public void Flush_should_throw(
77+ [ Values ( false , true ) ] bool async)
78+ {
79+ var bucket = CreateBucket( 128 ) ;
80+ var content = CreateContent( ) ;
81+ var id = CreateGridFSFile( bucket , content ) ;
82+ var subject = bucket. OpenDownloadStream ( id ) ;
83+
84+ Action action;
85+ if ( async)
86+ {
87+ action = ( ) => subject . FlushAsync ( CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ; ;
88+ }
89+ else
90+ {
91+ action = ( ) => subject . Flush ( ) ;
92+ }
93+
94+ action . ShouldThrow < NotSupportedException > ( ) ;
95+ }
96+
7497 // private methods
7598 private IGridFSBucket CreateBucket ( int chunkSize )
7699 {
@@ -81,7 +104,7 @@ private IGridFSBucket CreateBucket(int chunkSize)
81104 return new GridFSBucket ( database , bucketOptions ) ;
82105 }
83106
84- private byte [ ] CreateContent ( int contentSize )
107+ private byte [ ] CreateContent ( int contentSize = 0 )
85108 {
86109 return Enumerable. Range ( 0 , contentSize ) . Select ( i => ( byte ) i ) . ToArray ( ) ;
87110 }
Original file line number Diff line number Diff line change 1515
1616using System ;
1717using System . IO ;
18+ using System . Threading ;
1819using FluentAssertions ;
1920using MongoDB . Driver . Tests ;
2021using NUnit . Framework ;
@@ -48,6 +49,26 @@ public void CopyTo_should_throw(
4849 }
4950 }
5051
52+ [ Test ]
53+ public void Flush_should_not_throw(
54+ [ Values ( false , true ) ] bool async)
55+ {
56+ var bucket = CreateBucket( ) ;
57+ var subject = bucket . OpenUploadStream ( "Filename") ;
58+
59+ Action action;
60+ if ( async)
61+ {
62+ action = ( ) => subject . FlushAsync ( CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ; ;
63+ }
64+ else
65+ {
66+ action = ( ) => subject . Flush ( ) ;
67+ }
68+
69+ action . ShouldNotThrow ( ) ;
70+ }
71+
5172 // private methods
5273 private IGridFSBucket CreateBucket ( )
5374 {
Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ namespace MongoDB.Driver.GridFS
2727{
2828 internal class GridFSForwardOnlyUploadStream : GridFSUploadStream
2929 {
30+ #region static
31+ // private static fields
32+ private static readonly Task __completedTask = Task . FromResult ( true ) ;
33+ #endregion
34+
3035 // fields
3136 private bool _aborted ;
3237 private readonly List < string > _aliases ;
@@ -179,12 +184,13 @@ public override void Close(CancellationToken cancellationToken)
179184
180185 public override void Flush ( )
181186 {
182- throw new NotSupportedException ( ) ;
187+ // do nothing
183188 }
184189
185190 public override Task FlushAsync ( CancellationToken cancellationToken )
186191 {
187- throw new NotSupportedException ( ) ;
192+ // do nothing
193+ return __completedTask ;
188194 }
189195
190196 public override int Read ( byte [ ] buffer , int offset , int count )
You can’t perform that action at this time.
0 commit comments