Exemplo n.º 1
0
        public void CreateExceptionForResponseWithUnknownTimeout()
        {
            var description  = "NOT_KNOWN";
            var resourceName = "TestHub";

            using var response             = AmqpMessage.Create();
            response.ApplicationProperties = new ApplicationProperties();
            response.ApplicationProperties.Map[AmqpResponse.ErrorCondition]    = AmqpErrorCode.NotFound;
            response.ApplicationProperties.Map[AmqpResponse.StatusDescription] = description;

            Exception exception = AmqpError.CreateExceptionForResponse(response, resourceName);

            Assert.That(exception, Is.Not.Null, "An exception should have been created");
            Assert.That(exception, Is.TypeOf <EventHubsCommunicationException>(), "The exception should match");
            Assert.That(exception.Message, Is.SupersetOf(description), "The exception message should contain the description");
        }
Exemplo n.º 2
0
        public void CreateExceptionForResponseWithTimeoutConditionAndPattern()
        {
            var description  = GetNotFoundExpression().ToString().Replace("*.", "some value");
            var resourceName = "TestHub";

            using var response             = AmqpMessage.Create();
            response.ApplicationProperties = new ApplicationProperties();
            response.ApplicationProperties.Map[AmqpResponse.ErrorCondition]    = AmqpErrorCode.NotFound;
            response.ApplicationProperties.Map[AmqpResponse.StatusDescription] = description;

            Exception exception = AmqpError.CreateExceptionForResponse(response, resourceName);

            Assert.That(exception, Is.Not.Null, "An exception should have been created");
            Assert.That(exception, Is.TypeOf <EventHubsResourceNotFoundException>(), "The exception should match");
            Assert.That(exception.Message, Is.SupersetOf(description), "The exception message should contain the description");
        }
Exemplo n.º 3
0
        public void CreateExceptionForResponseWithTimeoutConditionAndStatusDescription()
        {
            var description  = $"This has { GetNotFoundStatusText() } embedded in it";
            var resourceName = "TestHub";

            using var response             = AmqpMessage.Create();
            response.ApplicationProperties = new ApplicationProperties();
            response.ApplicationProperties.Map[AmqpResponse.ErrorCondition]    = AmqpErrorCode.NotFound;
            response.ApplicationProperties.Map[AmqpResponse.StatusDescription] = description;

            Exception exception = AmqpError.CreateExceptionForResponse(response, resourceName);

            Assert.That(exception, Is.Not.Null, "An exception should have been created");
            Assert.That(exception, Is.TypeOf <EventHubsResourceNotFoundException>(), "The exception should match");
            Assert.That(exception.Message, Is.SupersetOf(description), "The exception message should contain the description");
        }
Exemplo n.º 4
0
        public void CreateExceptionForResponseWithUnmappedStatus()
        {
            var description  = "Some description";
            var resourceName = "TestHub";

            using var response             = AmqpMessage.Create();
            response.ApplicationProperties = new ApplicationProperties();
            response.ApplicationProperties.Map[AmqpResponse.StatusCode]        = int.MaxValue;
            response.ApplicationProperties.Map[AmqpResponse.StatusDescription] = description;

            Exception exception = AmqpError.CreateExceptionForResponse(response, resourceName);

            Assert.That(exception, Is.Not.Null, "An exception should have been created");
            Assert.That(exception, Is.TypeOf <EventHubsException>(), "The exception should match");
            Assert.That(exception.Message, Is.SupersetOf(description), "The exception message should contain the description");
        }
Exemplo n.º 5
0
        public void CreateExceptionForResponseWithCondition(AmqpSymbol condition,
                                                            Type exceptionType)
        {
            var description  = "This is a test description.";
            var resourceName = "TestHub";

            using var response             = AmqpMessage.Create();
            response.ApplicationProperties = new ApplicationProperties();
            response.ApplicationProperties.Map[AmqpResponse.ErrorCondition]    = condition;
            response.ApplicationProperties.Map[AmqpResponse.StatusDescription] = description;

            var exception = AmqpError.CreateExceptionForResponse(response, resourceName);

            Assert.That(exception, Is.Not.Null, "An exception should have been created");
            Assert.That(exception, Is.TypeOf(exceptionType), "The exception should be the proper type");
            Assert.That(exception.Message, Is.SupersetOf(description), "The exception message should contain the description");

            if (exception is EventHubsException)
            {
                Assert.That(((EventHubsException)exception).ResourceName, Is.EqualTo(resourceName), "The exception should report the proper resource");
            }
        }
Exemplo n.º 6
0
        public void CreateExceptionForResponseWitStatus(AmqpResponseStatusCode statusCode,
                                                        Type exceptionType,
                                                        EventHubsException.FailureReason?reason)
        {
            var description  = "This is a test description.";
            var resourceName = "TestHub";

            using var response             = AmqpMessage.Create();
            response.ApplicationProperties = new ApplicationProperties();
            response.ApplicationProperties.Map[AmqpResponse.StatusCode]        = (int)statusCode;
            response.ApplicationProperties.Map[AmqpResponse.StatusDescription] = description;

            Exception exception = AmqpError.CreateExceptionForResponse(response, resourceName);

            Assert.That(exception, Is.Not.Null, "An exception should have been created");
            Assert.That(exception, Is.TypeOf(exceptionType), "The exception should be the proper type");
            Assert.That(exception.Message, Is.SupersetOf(description), "The exception message should contain the description");

            if (exception is EventHubsException)
            {
                Assert.That(((EventHubsException)exception).Reason, Is.EqualTo(reason), "The proper failure reason should be specified");
                Assert.That(((EventHubsException)exception).EventHubName, Is.EqualTo(resourceName), "The exception should report the proper resource");
            }
        }