public void GetQueueInfoTest() { const string response = @"{""auto_delete"": false, ""exclusive"": false, ""durable"": true, ""arguments"": { ""x-max-priority"": 5 } }"; void validationCallback(HttpRequestMessage req, CancellationToken ct) { Assert.Equal(req.Method, HttpMethod.Get); Assert.Equal("/api/queues/%2f/testQueueName?columns=durable,auto_delete,exclusive,arguments", req.RequestUri.PathAndQuery); } var manager = new RabbitMQApiManager("http://*****:*****@172.21.11.6:8080/api/", "guest", "guest", channelMock.Object, client: GetMockHttpClient( requestHandler: GetHttpRequestHandler(HttpStatusCode.OK, response), callback: validationCallback ) ); var info = manager.GetQueueInfo("testQueueName"); Assert.True(info.Durable); Assert.False(info.AutoDelete); Assert.False(info.Exclusive); Assert.True(info.Arguments.ContainsKey("x-max-priority")); Assert.Equal(5, info.Priority); httpHandlerMock.Protected().Verify("SendAsync", Times.Once(), new object[] { ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() }); }
public void GetUnauthorizedResponseTest() { void validationCallback(HttpRequestMessage req, CancellationToken ct) { Assert.Equal(req.Method, HttpMethod.Get); Assert.Equal("/api/queues/%2f/amazing?columns=durable,auto_delete,exclusive,arguments", req.RequestUri.PathAndQuery); } var manager = new RabbitMQApiManager("http://*****:*****@172.21.11.6:8080/api", "guest", "guest", channelMock.Object, client: GetMockHttpClient( requestHandler: GetHttpRequestHandler(HttpStatusCode.Unauthorized, "This is an error!"), callback: validationCallback ) ); Exception ex = Assert.Throws <HttpRequestException>(() => manager.GetQueueInfo("amazing")); Assert.Equal("Erro ao consultar API do RabbitMQ. Status Unauthorized - This is an error!", ex.Message); }
public void GetNotExistentQueueInfoTest() { void validationCallback(HttpRequestMessage req, CancellationToken ct) { Assert.Equal(req.Method, HttpMethod.Get); Assert.Equal("/api/queues/%2f/amazing?columns=durable,auto_delete,exclusive,arguments", req.RequestUri.PathAndQuery); } var manager = new RabbitMQApiManager("http://*****:*****@172.21.11.6:8080/api", "guest", "guest", channelMock.Object, client: GetMockHttpClient( requestHandler: GetHttpRequestHandler(HttpStatusCode.NotFound, String.Empty), callback: validationCallback ) ); var info = manager.GetQueueInfo("amazing"); Assert.True(info.Durable); Assert.False(info.AutoDelete); Assert.False(info.Exclusive); Assert.Equal(0, info.Arguments.Count); Assert.Equal(0, info.Priority); }