-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
Tests/Test.SpecifyMessagesProperties/CustomBasicPropertiesTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using Microsoft.Extensions.Logging; | ||
using NanoRabbit; | ||
using NanoRabbit.Connection; | ||
using RabbitMQ.Client; | ||
|
||
namespace Test.SpecifyMessagesProperties | ||
{ | ||
[TestClass] | ||
public class CustomBasicPropertiesTest | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
|
||
var logger = Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance; | ||
|
||
var rabbitHelper = new RabbitHelper(rabbitConfig: new RabbitConfiguration | ||
{ | ||
HostName = "localhost", | ||
Port = 5672, | ||
VirtualHost = "/", | ||
UserName = "admin", | ||
Password = "admin", | ||
Producers = new List<ProducerOptions> { | ||
new ProducerOptions { | ||
ProducerName = "FooProducer", | ||
ExchangeName = "amq.topic", | ||
RoutingKey = "foo.key" | ||
} | ||
}, | ||
Consumers = new List<ConsumerOptions> { | ||
new ConsumerOptions { | ||
ConsumerName= "FooConsumer", | ||
QueueName = "foo-queue" | ||
} | ||
} | ||
}, logger); | ||
|
||
IBasicProperties props = rabbitHelper.CreateBasicProperties(); | ||
props.ContentType = "text/plain"; | ||
props.DeliveryMode = 2; | ||
|
||
rabbitHelper.Publish<string>("FooProducer", "Hello from NanoRabbit", props); | ||
} | ||
|
||
[TestMethod] | ||
public void TestMethod2() | ||
{ | ||
var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
|
||
var logger = Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance; | ||
|
||
var rabbitHelper = new RabbitHelper(rabbitConfig: new RabbitConfiguration | ||
{ | ||
HostName = "localhost", | ||
Port = 5672, | ||
VirtualHost = "/", | ||
UserName = "admin", | ||
Password = "admin", | ||
Producers = new List<ProducerOptions> { | ||
new ProducerOptions { | ||
ProducerName = "FooProducer", | ||
ExchangeName = "amq.topic", | ||
RoutingKey = "foo.key" | ||
} | ||
}, | ||
Consumers = new List<ConsumerOptions> { | ||
new ConsumerOptions { | ||
ConsumerName= "FooConsumer", | ||
QueueName = "foo-queue" | ||
} | ||
} | ||
}, logger); | ||
|
||
IBasicProperties props = rabbitHelper.CreateBasicProperties(); | ||
props.ContentType = "text/plain"; | ||
props.DeliveryMode = 2; | ||
props.Headers = new Dictionary<string, object>(); | ||
props.Headers.Add("latitude", 51.5252949); | ||
props.Headers.Add("longitude", -0.0905493); | ||
|
||
rabbitHelper.Publish<string>("FooProducer", "Hello from NanoRabbit", props); | ||
} | ||
|
||
[TestMethod] | ||
public void TestMethod3() | ||
{ | ||
var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
|
||
var logger = Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance; | ||
|
||
var rabbitHelper = new RabbitHelper(rabbitConfig: new RabbitConfiguration | ||
{ | ||
HostName = "localhost", | ||
Port = 5672, | ||
VirtualHost = "/", | ||
UserName = "admin", | ||
Password = "admin", | ||
Producers = new List<ProducerOptions> { | ||
new ProducerOptions { | ||
ProducerName = "FooProducer", | ||
ExchangeName = "amq.topic", | ||
RoutingKey = "foo.key" | ||
} | ||
}, | ||
Consumers = new List<ConsumerOptions> { | ||
new ConsumerOptions { | ||
ConsumerName= "FooConsumer", | ||
QueueName = "foo-queue" | ||
} | ||
} | ||
}, logger); | ||
|
||
IBasicProperties props = rabbitHelper.CreateBasicProperties(); | ||
props.ContentType = "text/plain"; | ||
props.DeliveryMode = 2; | ||
props.Expiration = "36000000"; | ||
|
||
rabbitHelper.Publish<string>("FooProducer", "Hello from NanoRabbit", props); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Tests/Test.SpecifyMessagesProperties/Test.SpecifyMessagesProperties.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Src\NanoRabbit\NanoRabbit.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; |