private static Exception ConvertToException(int statusCode, string statusDescription) { Exception messagingException; if (!Enum.IsDefined(typeof(HttpStatusCode), statusCode)) { messagingException = new MessagingException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription)); } else { HttpStatusCode httpStatusCode = (HttpStatusCode)statusCode; if (httpStatusCode == HttpStatusCode.BadRequest) { messagingException = new ArgumentException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription)); } else if (httpStatusCode == HttpStatusCode.NotFound) { messagingException = new MessagingEntityNotFoundException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription)); } else { messagingException = new MessagingException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription)); } } return(messagingException); }
public async Task ServiceBusEndToEnd_RestrictedAccess() { try { // Try running the tests using jobs that declare restricted access // levels. We expect a failure. MessagingEntityNotFoundException expectedException = null; try { await ServiceBusEndToEndInternal(typeof(ServiceBusTestJobs_RestrictedAccess)); } catch (MessagingEntityNotFoundException e) { expectedException = e; } Assert.NotNull(expectedException); // Now create the service bus entities string queueName = ResolveName(QueueNamePrefix + "1"); _namespaceManager.CreateQueue(queueName); string topicName = ResolveName(TopicName); _namespaceManager.CreateTopic(topicName); string subscription1 = ResolveName(QueueNamePrefix + "topic-1"); _namespaceManager.CreateSubscription(topicName, subscription1); string subscription2 = ResolveName(QueueNamePrefix + "topic-2"); _namespaceManager.CreateSubscription(topicName, subscription2); // Test should now succeed await ServiceBusEndToEndInternal(typeof(ServiceBusTestJobs_RestrictedAccess), verifyLogs : false); } finally { Cleanup(); } }