.NET client's test suite assumes there's a RabbitMQ node listening on localhost:5672
(the default settings). SSL tests require a broker listening on the default
SSL port. Connection recovery tests assume rabbitmqctl
at ../rabbitmq-server/scripts/rabbitmqctl
can control the running node: this is the case when all repositories are cloned using
the umbrella repository.
It is possible to use Visual Studio Community Edition .NET Core, and
dotnet.exe
in PATH
, to build the client and run the test suite.
Before this project can be opened in Visual Studio, it's necessary to pull down dependencies and perform protocol encoder/decoder code generation.
On Windows run:
build.bat
On MacOS and linux run:
build.sh
This will complete the code AMQP 0-9-1 protocol code generation and build all projects. After this open the solution in Visual Studio.
Tests can be run from Visual Studio using the NUnit Test Adapter. Note that it may take some time for the adapter to discover tests in the assemblies.
The test suite assumes there's a RabbitMQ node running locally with all
defaults, and the tests will need to be able to run commands against the
rabbitmqctl
tool for that node.
Two options to accomplish this are covered below.
It is possible to install and run a node using any binary build
suitable for the platform. Its CLI tools then must be added to PATH
so that rabbitmqctl
can be
invoked directly without using an absolute file path. Note that this method does not work on Windows.
On Windows, you must run unit tests as follows (replace X.Y.Z
with your RabbitMQ version):
set "RABBITMQ_RABBITMQCTL_PATH=C:\Program Files\RabbitMQ Server\rabbitmq_server-X.Y.Z\sbin\rabbitmqctl.bat"
.\run-test.bat
Team RabbitMQ uses rabbitmq-public-umbrella, which makes it easy to run a RabbitMQ node built from source:
git clone https://github.com/rabbitmq/rabbitmq-public-umbrella umbrella
cd umbrella
make co
cd deps/rabbit
make
make run-broker
rabbitmqctl
location will be computed using a relative path in the umbrella.
It is possible to override the location using RABBITMQ_RABBITMQCTL_PATH
:
RABBITMQ_RABBITMQCTL_PATH=/path/to/rabbitmqctl dotnet test projects/Unit
It is also possible to run a RabbitMQ node in a Docker container. Set the environment variable RABBITMQ_RABBITMQCTL_PATH
to DOCKER:<container_name>
(for example DOCKER:rabbitmq01
). This tells the unit tests to run the rabbitmqctl
commands through Docker, in the format docker exec rabbitmq01 rabbitmqctl <args>
:
docker run -d --hostname rabbitmq01 --name rabbitmq01 -p 15672:15672 -p 5672:5672 rabbitmq:3-management
Then, to run the tests use:
# will run tests on .NET Core and .NET Framework
run-test.bat
On MacOS, Linux, BSD use:
# will only run tests on .NET Core
run-test.sh
Running individual tests and fixtures on Windows is trivial using the Visual Studio test runner. To run a specific tests fixture on MacOS or Linux, use the NUnit filter expressions to select the tests to be run:
dotnet test projects/Unit -f netcoreapp3.1 --filter "Name~TestAmqpUriParseFail"
dotnet test projects/Unit -f netcoreapp3.1 --filter "FullyQualifiedName~RabbitMQ.Client.Unit.TestHeartbeats"
To only run tests on .NET Core:
dotnet test -f netcoreapp3.1 projects/Unit