Skip to content

Commit

Permalink
Add custom properties test unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ifgris committed Aug 2, 2024
1 parent b201bef commit 2ccd935
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
9 changes: 8 additions & 1 deletion NanoRabbit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exmaple.ServiceInConsumer",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exmaple.TaskInMessageHandler", "Example\Exmaple.TaskInMessageHandler\Exmaple.TaskInMessageHandler.csproj", "{C98D8769-5CB8-47EC-83B7-287550F769BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Logger", "Tests\Test.Logger\Test.Logger.csproj", "{0F12CA12-6649-45F2-BFAB-3F2521FB01D7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Logger", "Tests\Test.Logger\Test.Logger.csproj", "{0F12CA12-6649-45F2-BFAB-3F2521FB01D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.SpecifyMessagesProperties", "Tests\Test.SpecifyMessagesProperties\Test.SpecifyMessagesProperties.csproj", "{9C846F9B-E2B0-4844-944D-883B66278497}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -94,6 +96,10 @@ Global
{0F12CA12-6649-45F2-BFAB-3F2521FB01D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F12CA12-6649-45F2-BFAB-3F2521FB01D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F12CA12-6649-45F2-BFAB-3F2521FB01D7}.Release|Any CPU.Build.0 = Release|Any CPU
{9C846F9B-E2B0-4844-944D-883B66278497}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C846F9B-E2B0-4844-944D-883B66278497}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C846F9B-E2B0-4844-944D-883B66278497}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C846F9B-E2B0-4844-944D-883B66278497}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -114,6 +120,7 @@ Global
{DE4C1826-A072-4087-A4B1-272C8FD9DF56} = {D187C758-604D-4325-9FEF-912DB32D6131}
{C98D8769-5CB8-47EC-83B7-287550F769BE} = {D187C758-604D-4325-9FEF-912DB32D6131}
{0F12CA12-6649-45F2-BFAB-3F2521FB01D7} = {324E2D97-6266-4F03-8A62-2E8A31313A59}
{9C846F9B-E2B0-4844-944D-883B66278497} = {324E2D97-6266-4F03-8A62-2E8A31313A59}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6EE19DFD-83A9-4A48-B245-5A1344E7865A}
Expand Down
132 changes: 132 additions & 0 deletions Tests/Test.SpecifyMessagesProperties/CustomBasicPropertiesTest.cs
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);
}
}
}
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>
1 change: 1 addition & 0 deletions Tests/Test.SpecifyMessagesProperties/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;

0 comments on commit 2ccd935

Please sign in to comment.