@@ -87,5 +87,59 @@ public void TestEventingConsumerRegistrationEvents()
8787 Assert . IsNotNull ( unregisteredSender ) ;
8888 Assert . AreEqual ( ec , unregisteredSender ) ;
8989 }
90+
91+ [ Test ]
92+ public void TestEventingConsumerDeliveryEvents ( )
93+ {
94+ string q = Model . QueueDeclare ( ) ;
95+ object o = new Object ( ) ;
96+
97+ bool receivedInvoked = false ;
98+ object receivedSender = null ;
99+
100+ EventingBasicConsumer ec = new EventingBasicConsumer ( Model ) ;
101+ ec . Received += ( s , args ) =>
102+ {
103+ receivedInvoked = true ;
104+ receivedSender = s ;
105+
106+ Monitor . PulseAll ( o ) ;
107+ } ;
108+
109+ Model . BasicConsume ( q , true , ec ) ;
110+ Model . BasicPublish ( "" , q , null , enc . GetBytes ( "msg" ) ) ;
111+
112+ WaitOn ( o ) ;
113+ Assert . IsTrue ( receivedInvoked ) ;
114+ Assert . IsNotNull ( receivedSender ) ;
115+ Assert . AreEqual ( ec , receivedSender ) ;
116+
117+ bool shutdownInvoked = false ;
118+ object shutdownSender = null ;
119+
120+ ec . Shutdown += ( s , args ) =>
121+ {
122+ shutdownInvoked = true ;
123+ shutdownSender = s ;
124+
125+ Monitor . PulseAll ( o ) ;
126+ } ;
127+
128+ Model . Close ( ) ;
129+ WaitOn ( o ) ;
130+
131+ Assert . IsTrue ( shutdownInvoked ) ;
132+ Assert . IsNotNull ( shutdownSender ) ;
133+ Assert . AreEqual ( ec , shutdownSender ) ;
134+ }
135+
136+
137+ protected void WaitOn ( object o )
138+ {
139+ lock ( o )
140+ {
141+ Monitor . Wait ( o , TimeSpan . FromSeconds ( 4 ) ) ;
142+ }
143+ }
90144 }
91145}
0 commit comments