Skip to content

Commit 48584ba

Browse files
Initial test for EventingBasicConsumer
1 parent d8daaa2 commit 48584ba

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

projects/client/RabbitMQ.Client/src/client/events/EventingBasicConsumer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ namespace RabbitMQ.Client.Events
5151
///</remarks>
5252
public class EventingBasicConsumer : DefaultBasicConsumer
5353
{
54+
55+
///<summary>Constructor which sets the Model property to the
56+
///given value.</summary>
57+
public EventingBasicConsumer(IModel model) : base(model) {}
58+
5459
///<summary>Fires the Unregistered event.</summary>
5560
public override void HandleBasicCancelOk(string consumerTag)
5661
{
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (C) 2007-2013 GoPivotal, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is GoPivotal, Inc.
38+
// Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using NUnit.Framework;
42+
43+
using System;
44+
using System.Text;
45+
using System.Threading;
46+
using System.Diagnostics;
47+
48+
using RabbitMQ.Client.Events;
49+
50+
namespace RabbitMQ.Client.Unit {
51+
[TestFixture]
52+
public class TestEventingConsumer : IntegrationFixture {
53+
54+
UTF8Encoding enc = new UTF8Encoding();
55+
56+
[Test]
57+
public void TestEventingConsumerRegistrationEvents()
58+
{
59+
string q = Model.QueueDeclare();
60+
61+
bool registeredInvoked = false;
62+
object registeredSender = null;
63+
bool unregisteredInvoked = false;
64+
object unregisteredSender = null;
65+
66+
EventingBasicConsumer ec = new EventingBasicConsumer(Model);
67+
ec.Registered += (s, args) =>
68+
{
69+
registeredInvoked = true;
70+
registeredSender = s;
71+
};
72+
73+
ec.Unregistered += (s, args) =>
74+
{
75+
unregisteredInvoked = true;
76+
unregisteredSender = s;
77+
};
78+
79+
string tag = Model.BasicConsume(q, true, ec);
80+
81+
Assert.IsTrue(registeredInvoked);
82+
Assert.IsNotNull(registeredSender);
83+
Assert.AreEqual(ec, registeredSender);
84+
85+
Model.BasicCancel(tag);
86+
Assert.IsTrue(unregisteredInvoked);
87+
Assert.IsNotNull(unregisteredSender);
88+
Assert.AreEqual(ec, unregisteredSender);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)