Exemplo n.º 1
0
        public void TestQueueService_DeleteMany()
        {
            var qa = new QueueAddressModel()
            {
                Name = "company.queues.finance6", ExchangeName = "Test.Exchange"
            };
            var qa1 = new QueueAddressModel()
            {
                Name = "company.queues.finance7", ExchangeName = "Test.Exchange"
            };

            var q = new QueueDeleteModel()
            {
                Name = "company.queues.finance6"
            };
            var q1 = new QueueDeleteModel()
            {
                Name = "company.queues.finance7"
            };

            List <QueueDeleteModel> qs = new List <QueueDeleteModel>()
            {
                q, q1
            };
            List <QueueAddressModel> qas = new List <QueueAddressModel>()
            {
                qa, qa1
            };

            BaseQueueService.DeclareMany(qas);

            // Assert
            Assert.DoesNotThrow(() => { BaseQueueService.DeleteMany(qs); });
        }
 /// <summary>
 /// Creates a single queue
 /// </summary>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ServiceException"></exception>
 /// <exception cref="ValidationException"></exception>
 /// <param name="queue"></param>
 public void Declare(QueueAddressModel queue)
 {
     try
     {
         Validate(queue, "Queue to declare cannot be null");
         // Declare the queue
         Channel.QueueDeclare(queue.Name, queue.Durable, queue.Exclusive, queue.AutoDelete, queue.Arguments);
         // Apply any bindings
         if (!string.IsNullOrWhiteSpace(queue.ExchangeName))
         {
             // Check if this queue will be bound using multiple routing keya
             if (queue.HasRoutingKeys())
             {
                 foreach (var key in queue.RoutingKeys)
                 {
                     Bind(queue.ExchangeName, queue.Name, key);
                 }
             }
             else
             {
                 // Just bind the queue without a routing key
                 Bind(queue.ExchangeName, queue.Name, "");
             }
         }
     }
     catch (Exception ex) when(ex is ArgumentNullException || ex is ServiceException || ex is ValidationException)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
         throw new ServiceException("Queue Service Exception: please see log for more details.");
     }
 }
Exemplo n.º 3
0
 public void TestQueueService_DeclareQueue_ServiceChannelClosed()
 {
     Assert.That(() =>
     {
         var exchange = new QueueService(ClosedChannel);
         var addr     = new QueueAddressModel()
         {
             Name         = "Test.Exchange",
             ExchangeName = "TEST"
         };
         exchange.Declare(addr);
     }, Throws.TypeOf <ServiceException>());
 }
        public void TestQueueAddress_MissingQueueName()
        {
            QueueAddressModel ex = new QueueAddressModel()
            {
                ExchangeName = "anexchange",
                Name         = ""
            };

            var errorMessage = "";

            if (ex.TryValidate(out errorMessage))
            {
                Assert.Fail("Should have failed");
            }
            Assert.Pass(errorMessage);
        }