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 18
18
using System . IO ;
19
19
using System . Linq ;
20
20
using System . Text ;
21
+ using System . Threading ;
21
22
using System . Threading . Tasks ;
22
23
using FluentAssertions ;
23
24
using MongoDB . Bson ;
@@ -71,6 +72,28 @@ public void CopyTo_should_copy_stream(
71
72
}
72
73
}
73
74
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
+
74
97
// private methods
75
98
private IGridFSBucket CreateBucket ( int chunkSize )
76
99
{
@@ -81,7 +104,7 @@ private IGridFSBucket CreateBucket(int chunkSize)
81
104
return new GridFSBucket ( database , bucketOptions ) ;
82
105
}
83
106
84
- private byte [ ] CreateContent ( int contentSize )
107
+ private byte [ ] CreateContent ( int contentSize = 0 )
85
108
{
86
109
return Enumerable. Range ( 0 , contentSize ) . Select ( i => ( byte ) i ) . ToArray ( ) ;
87
110
}
Original file line number Diff line number Diff line change 15
15
16
16
using System ;
17
17
using System . IO ;
18
+ using System . Threading ;
18
19
using FluentAssertions ;
19
20
using MongoDB . Driver . Tests ;
20
21
using NUnit . Framework ;
@@ -48,6 +49,26 @@ public void CopyTo_should_throw(
48
49
}
49
50
}
50
51
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
+
51
72
// private methods
52
73
private IGridFSBucket CreateBucket ( )
53
74
{
Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ namespace MongoDB.Driver.GridFS
27
27
{
28
28
internal class GridFSForwardOnlyUploadStream : GridFSUploadStream
29
29
{
30
+ #region static
31
+ // private static fields
32
+ private static readonly Task __completedTask = Task . FromResult ( true ) ;
33
+ #endregion
34
+
30
35
// fields
31
36
private bool _aborted ;
32
37
private readonly List < string > _aliases ;
@@ -179,12 +184,13 @@ public override void Close(CancellationToken cancellationToken)
179
184
180
185
public override void Flush ( )
181
186
{
182
- throw new NotSupportedException ( ) ;
187
+ // do nothing
183
188
}
184
189
185
190
public override Task FlushAsync ( CancellationToken cancellationToken )
186
191
{
187
- throw new NotSupportedException ( ) ;
192
+ // do nothing
193
+ return __completedTask ;
188
194
}
189
195
190
196
public override int Read ( byte [ ] buffer , int offset , int count )
You can’t perform that action at this time.
0 commit comments