|
30 | 30 | //---------------------------------------------------------------------------
|
31 | 31 |
|
32 | 32 | using System;
|
| 33 | +using System.Collections.Generic; |
| 34 | +using System.Diagnostics; |
| 35 | +using System.Text; |
| 36 | +using System.Threading; |
| 37 | +using System.Threading.Tasks; |
| 38 | + |
| 39 | +using RabbitMQ.Client.Events; |
33 | 40 |
|
34 | 41 | using Xunit;
|
35 | 42 |
|
@@ -188,5 +195,44 @@ public void TestProperties_ReplyTo(string replyTo)
|
188 | 195 | Assert.Equal(isReplyToPresent, basicProperties.IsReplyToPresent());
|
189 | 196 | Assert.Equal(replyToAddress, basicProperties.ReplyToAddress?.ToString());
|
190 | 197 | }
|
| 198 | + |
| 199 | + [Fact] |
| 200 | + public void TestPropertiesRountrip_Headers() |
| 201 | + { |
| 202 | + // Arrange |
| 203 | + var subject = new BasicProperties |
| 204 | + { |
| 205 | + Headers = new Dictionary<string, object?>() |
| 206 | + }; |
| 207 | + |
| 208 | + var cf = new ConnectionFactory(); |
| 209 | + using (IConnection c = cf.CreateConnection()) |
| 210 | + using (IModel m = c.CreateModel()) |
| 211 | + { |
| 212 | + QueueDeclareOk q = m.QueueDeclare(); |
| 213 | + var bp = new BasicProperties() { Headers = new Dictionary<string, object>() }; |
| 214 | + bp.Headers["Hello"] = "World"; |
| 215 | + byte[] sendBody = Encoding.UTF8.GetBytes("hi"); |
| 216 | + byte[] consumeBody = null; |
| 217 | + var consumer = new EventingBasicConsumer(m); |
| 218 | + var are = new AutoResetEvent(false); |
| 219 | + string response = null; |
| 220 | + consumer.Received += async (o, a) => |
| 221 | + { |
| 222 | + response = Encoding.UTF8.GetString(a.BasicProperties.Headers["Hello"] as byte[]); |
| 223 | + consumeBody = a.Body.ToArray(); |
| 224 | + are.Set(); |
| 225 | + await Task.Yield(); |
| 226 | + }; |
| 227 | + |
| 228 | + string tag = m.BasicConsume(q.QueueName, true, consumer); |
| 229 | + m.BasicPublish("", q.QueueName, bp, sendBody); |
| 230 | + bool waitResFalse = are.WaitOne(5000); |
| 231 | + m.BasicCancel(tag); |
| 232 | + Assert.True(waitResFalse); |
| 233 | + Assert.Equal(sendBody, consumeBody); |
| 234 | + Assert.Equal("World", response); |
| 235 | + } |
| 236 | + } |
191 | 237 | }
|
192 | 238 | }
|
0 commit comments