@@ -143,6 +143,32 @@ public void Enqueue_DuplicateEntry()
143143 queue . Should ( ) . HaveTopic ( "a" , providedBy : Items ( entryA0 , entryA1 ) ) ;
144144 }
145145
146+ [ Test ]
147+ public void Enqueue_Ending ( )
148+ {
149+ var entry = Entry ( "a" ) ;
150+
151+ using var queue = Queue ( ) ;
152+
153+ queue . SetEnding ( ) ;
154+
155+ // Allowed but not very useful
156+ queue . Enqueue ( entry ) ;
157+ }
158+
159+ [ Test ]
160+ public void Enqueue_Disposed ( )
161+ {
162+ var entry = Entry ( "a" ) ;
163+
164+ var queue = Queue ( ) ;
165+ queue . Dispose ( ) ;
166+
167+ queue
168+ . Invoking ( q => q . Enqueue ( entry ) )
169+ . Should ( ) . Throw < ObjectDisposedException > ( ) ;
170+ }
171+
146172 [ Test ]
147173 public void Validate_Empty ( )
148174 {
@@ -208,6 +234,28 @@ public void Validate_Cycle_Indirect()
208234 ) ;
209235 }
210236
237+ [ Test ]
238+ public void Validate_Ending ( )
239+ {
240+ using var queue = Queue ( ) ;
241+
242+ queue . SetEnding ( ) ;
243+
244+ // Allowed but not very useful
245+ queue . Validate ( ) . Should ( ) . BeEmpty ( ) ;
246+ }
247+
248+ [ Test ]
249+ public void Validate_Disposed ( )
250+ {
251+ var queue = Queue ( ) ;
252+ queue . Dispose ( ) ;
253+
254+ queue
255+ . Invoking ( q => q . Validate ( ) )
256+ . Should ( ) . Throw < ObjectDisposedException > ( ) ;
257+ }
258+
211259 [ Test ]
212260 public void TryDequeue_NotValidated ( )
213261 {
@@ -247,6 +295,19 @@ public void TryDequeue_Ending()
247295 queue . Should ( ) . HaveTopic ( "a" , providedBy : Items ( entry ) ) ;
248296 }
249297
298+ [ Test ]
299+ public void TryDequeue_Disposed ( )
300+ {
301+ var entry = Entry ( "a" ) ;
302+
303+ var queue = Queue ( entry ) ;
304+ queue . Dispose ( ) ;
305+
306+ queue
307+ . Invoking ( q => q . TryDequeue ( ) )
308+ . Should ( ) . Throw < ObjectDisposedException > ( ) ;
309+ }
310+
250311 [ Test ]
251312 public void TryDequeue_Ok ( )
252313 {
@@ -437,6 +498,19 @@ public async Task TryDequeueAsync_Ending()
437498 queue . Should ( ) . HaveTopic ( "a" , providedBy : Items ( entry ) ) ;
438499 }
439500
501+ [ Test ]
502+ public async Task TryDequeueAsync_Disposed ( )
503+ {
504+ var entry = Entry ( "a" ) ;
505+
506+ var queue = Queue ( entry ) ;
507+ queue . Dispose ( ) ;
508+
509+ await queue
510+ . Awaiting ( q => q . TryDequeueAsync ( ) )
511+ . Should ( ) . ThrowAsync < ObjectDisposedException > ( ) ;
512+ }
513+
440514 [ Test ]
441515 public async Task TryDequeueAsync_Ok ( )
442516 {
@@ -609,8 +683,50 @@ public void Complete_NullEntry()
609683 . Where ( e => e . ParamName == "entry" ) ;
610684 }
611685
612- // TODO: Do we need to test more of Complete, specifically what it does
613- // to the Topics and ReadEvents collections?
686+ [ Test ]
687+ public void Complete_Ending ( )
688+ {
689+ var entry = Entry ( "a" ) ;
690+
691+ using var queue = Queue ( entry ) ;
692+ queue . Validate ( ) ;
693+ queue . TryDequeue ( ) . Should ( ) . BeSameAs ( entry ) ;
694+ queue . SetEnding ( ) ;
695+
696+ // Allowed but not very useful
697+ queue . Complete ( entry ) ;
698+ }
699+
700+ [ Test ]
701+ public void Complete_Disposed ( )
702+ {
703+ var entry = Entry ( "a" ) ;
704+
705+ var queue = Queue ( entry ) ;
706+ queue . Validate ( ) ;
707+ queue . TryDequeue ( ) . Should ( ) . BeSameAs ( entry ) ;
708+ queue . Dispose ( ) ;
709+
710+ queue
711+ . Invoking ( q => q . Complete ( entry ) )
712+ . Should ( ) . Throw < ObjectDisposedException > ( ) ;
713+ }
714+
715+ // TODO: Need to test more of Complete, specifically what it does to the
716+ // Topics and ReadEvents collections? Or what happens when completing an
717+ // entry that wasn't dequeued? Or completing the same entry twice? Or
718+ // completing an entry that was never enqueued?
719+
720+ [ Test ]
721+ public void Run_NullWorker ( )
722+ {
723+ using var queue = Queue ( ) ;
724+
725+ queue
726+ . Invoking ( q => q . Run ( null ! , new Data ( ) , parallelism : 0 ) )
727+ . Should ( ) . Throw < ArgumentNullException > ( )
728+ . WithParameterName ( "worker" ) ;
729+ }
614730
615731 [ Test ]
616732 public void Run_NotValidated ( )
@@ -624,6 +740,19 @@ public void Run_NotValidated()
624740 . Should ( ) . ThrowExactly < InvalidOperationException > ( ) ;
625741 }
626742
743+ [ Test ]
744+ public void Run_Disposed ( )
745+ {
746+ static void WorkerMain ( Context_ _ ) { } ;
747+
748+ var queue = Queue ( ) ;
749+ queue . Dispose ( ) ;
750+
751+ queue
752+ . Invoking ( q => q . Run ( WorkerMain , new Data ( ) , parallelism : 0 ) )
753+ . Should ( ) . Throw < ObjectDisposedException > ( ) ;
754+ }
755+
627756 [ Test ]
628757 public void Run_InvalidParallelism ( )
629758 {
@@ -689,7 +818,18 @@ void WorkerMain(Context_ context)
689818 }
690819
691820 [ Test ]
692- public async Task RunAsync_NotValidatedAsync ( )
821+ public async Task RunAsync_NullWorker ( )
822+ {
823+ using var queue = Queue ( ) ;
824+
825+ await queue
826+ . Awaiting ( q => q . RunAsync ( null ! , new Data ( ) , parallelism : 0 ) )
827+ . Should ( ) . ThrowAsync < ArgumentNullException > ( )
828+ . WithParameterName ( "worker" ) ;
829+ }
830+
831+ [ Test ]
832+ public async Task RunAsync_NotValidated ( )
693833 {
694834 static Task WorkerMain ( Context_ _ ) => Task . CompletedTask ;
695835
@@ -701,7 +841,20 @@ await queue
701841 }
702842
703843 [ Test ]
704- public async Task RunAsync_InvalidParallelismAsync ( )
844+ public async Task RunAsync_Disposed ( )
845+ {
846+ static Task WorkerMain ( Context_ _ ) => Task . CompletedTask ;
847+
848+ var queue = Queue ( ) ;
849+ queue . Dispose ( ) ;
850+
851+ await queue
852+ . Awaiting ( q => q . RunAsync ( WorkerMain , new Data ( ) , parallelism : 0 ) )
853+ . Should ( ) . ThrowAsync < ObjectDisposedException > ( ) ;
854+ }
855+
856+ [ Test ]
857+ public async Task RunAsync_InvalidParallelism ( )
705858 {
706859 static Task WorkerMain ( Context_ _ ) => Task . CompletedTask ;
707860
0 commit comments