Skip to content

Commit

Permalink
Add [Collection("IntegrationFixture")] to test class that needs it,…
Browse files Browse the repository at this point in the history
… move test to an integration fixture class
  • Loading branch information
lukebakken committed Oct 16, 2023
1 parent 2ce0470 commit 450dc71
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
39 changes: 0 additions & 39 deletions projects/Unit/TestBasicProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,44 +192,5 @@ public void TestProperties_ReplyTo(string replyTo)
Assert.Equal(isReplyToPresent, basicProperties.IsReplyToPresent());
Assert.Equal(replyToAddress, basicProperties.ReplyToAddress?.ToString());
}

[Fact]
public void TestPropertiesRountrip_Headers()
{
// Arrange
var subject = new BasicProperties
{
Headers = new Dictionary<string, object>()
};

var cf = new ConnectionFactory();
using (IConnection c = cf.CreateConnection())
using (IChannel m = c.CreateChannel())
{
QueueDeclareOk q = m.QueueDeclare();
var bp = new BasicProperties() { Headers = new Dictionary<string, object>() };
bp.Headers["Hello"] = "World";
byte[] sendBody = Encoding.UTF8.GetBytes("hi");
byte[] consumeBody = null;
var consumer = new EventingBasicConsumer(m);
var are = new AutoResetEvent(false);
string response = null;
consumer.Received += async (o, a) =>
{
response = Encoding.UTF8.GetString(a.BasicProperties.Headers["Hello"] as byte[]);
consumeBody = a.Body.ToArray();
are.Set();
await Task.Yield();
};

string tag = m.BasicConsume(q.QueueName, true, consumer);
m.BasicPublish("", q.QueueName, bp, sendBody);
bool waitResFalse = are.WaitOne(5000);
m.BasicCancel(tag);
Assert.True(waitResFalse);
Assert.Equal(sendBody, consumeBody);
Assert.Equal("World", response);
}
}
}
}
40 changes: 40 additions & 0 deletions projects/Unit/TestBasicPublish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
//---------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -252,5 +253,44 @@ public void TestMaxMessageSize()
}
}
}

[Fact]
public void TestPropertiesRountrip_Headers()
{
// Arrange
var subject = new BasicProperties
{
Headers = new Dictionary<string, object>()
};

var cf = new ConnectionFactory();
using (IConnection c = cf.CreateConnection())
using (IChannel m = c.CreateChannel())
{
QueueDeclareOk q = m.QueueDeclare();
var bp = new BasicProperties() { Headers = new Dictionary<string, object>() };
bp.Headers["Hello"] = "World";
byte[] sendBody = Encoding.UTF8.GetBytes("hi");
byte[] consumeBody = null;
var consumer = new EventingBasicConsumer(m);
var are = new AutoResetEvent(false);
string response = null;
consumer.Received += async (o, a) =>
{
response = Encoding.UTF8.GetString(a.BasicProperties.Headers["Hello"] as byte[]);
consumeBody = a.Body.ToArray();
are.Set();
await Task.Yield();
};

string tag = m.BasicConsume(q.QueueName, true, consumer);
m.BasicPublish("", q.QueueName, bp, sendBody);
bool waitResFalse = are.WaitOne(5000);
m.BasicCancel(tag);
Assert.True(waitResFalse);
Assert.Equal(sendBody, consumeBody);
Assert.Equal("World", response);
}
}
}
}
1 change: 1 addition & 0 deletions projects/Unit/TestConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace RabbitMQ.Client.Unit
{
[Collection("IntegrationFixture")]
public class TestConnectionFactory
{
[Fact]
Expand Down

0 comments on commit 450dc71

Please sign in to comment.