public void Setup()
        {
            var queueName = "permissionsTest";

            path = $@"{RuntimeEnvironment.MachineName}\private$\{queueName}";
            MsmqHelpers.DeleteQueue(path);
            MsmqHelpers.CreateQueue(path);

            queue = new MessageQueue(path);
        }
        static Message DispatchMessage(string queueName, MsmqSettings settings = null, DeliveryConstraint deliveryConstraint = null, Func <IReadOnlyDictionary <string, string>, string> messageLabelGenerator = null)
        {
            if (settings == null)
            {
                settings = new MsmqSettings(null);
            }

            if (messageLabelGenerator == null)
            {
                messageLabelGenerator = _ => string.Empty;
            }

            settings.LabelGenerator = messageLabelGenerator;

            var path = $@".\private$\{queueName}";

            try
            {
                MsmqHelpers.DeleteQueue(path);
                MsmqHelpers.CreateQueue(path);

                var messageSender = new MsmqMessageDispatcher(settings);

                var bytes = new byte[]
                {
                    1
                };
                var headers             = new Dictionary <string, string>();
                var outgoingMessage     = new OutgoingMessage("1", headers, bytes);
                var deliveryConstraints = new List <DeliveryConstraint>();

                if (deliveryConstraint != null)
                {
                    deliveryConstraints.Add(deliveryConstraint);
                }

                var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), DispatchConsistency.Default, deliveryConstraints);

                messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag());

                using (var queue = new MessageQueue(path))
                    using (var message = queue.Receive(TimeSpan.FromSeconds(5)))
                    {
                        return(message);
                    }
            }
            finally
            {
                MsmqHelpers.DeleteQueue(path);
            }
        }
        static async Task <Message> DispatchMessage(string queueName, MsmqTransport settings = null, DispatchProperties dispatchProperties = null, CancellationToken cancellationToken = default)
        {
            if (settings == null)
            {
                settings = new MsmqTransport();
            }

            var path = $@".\private$\{queueName}";

            try
            {
                MsmqHelpers.DeleteQueue(path);
                MsmqHelpers.CreateQueue(path);

                var messageSender = new MsmqMessageDispatcher(settings, "timeouts");

                var bytes = new byte[]
                {
                    1
                };
                var headers         = new Dictionary <string, string>();
                var outgoingMessage = new OutgoingMessage("1", headers, bytes);

                dispatchProperties = dispatchProperties ?? new DispatchProperties();
                var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), dispatchProperties);

                await messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), cancellationToken);

                using (var queue = new MessageQueue(path))
                    using (var message = queue.Receive(TimeSpan.FromSeconds(5)))
                    {
                        return(message);
                    }
            }
            finally
            {
                MsmqHelpers.DeleteQueue(path);
            }
        }