Exemplo n.º 1
0
        public void PublishNullMessageBody(
            [Values("", "payments", "", "payments")] string exchange,
            [Values("", "", "payments.create", "payments.create")] string routingKey)
        {
            // arrange
            var controller = new amqp_sidecar.Controllers.Controller(this._connectionfactory.CreateConnection(), new HttpClient());

            // act
            ActionResult <string> actionResult = controller.EnqueueMessage(null, exchange, routingKey);

            // assert
            var result = actionResult.Result as BadRequestObjectResult;

            Assert.That(result, Is.Not.Null, "Result is not BadRequestObjectResult");
            Assert.That(result.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest), "Result should be status code 400");
            Assert.That(this._rabbitServer.Exchanges.ContainsKey(exchange), Is.EqualTo(false), "Exchange should not be created");
        }
Exemplo n.º 2
0
        public void PublishMessageValid(
            [Values("payments")] string exchange,
            [Values("payments.create")] string routingKey)
        {
            // arrange
            var controller  = new amqp_sidecar.Controllers.Controller(this._connectionfactory.CreateConnection(), new HttpClient());
            var messageBody = new SubmitPaymentRequest
            {
                AccountNumber = "12345",
                PaymentAmount = 100
            };

            // act
            ActionResult <string> actionResult = controller.EnqueueMessage(messageBody, exchange, routingKey);

            // assert
            var result = actionResult.Result as OkResult;

            Assert.That(result, Is.Not.Null, "Result is not OkResult");
            Assert.That(result.StatusCode, Is.EqualTo((int)HttpStatusCode.OK), "Result should be status code 200");
            Assert.That(this._rabbitServer.Exchanges.ContainsKey(exchange), Is.EqualTo(true), "Exchange should be created");
            Assert.That(this._rabbitServer.Exchanges[exchange].Messages.Count, Is.EqualTo(1), "Expected message in exchange");
        }