public void when_failing_transiently_then_retries()
        {
            int  endCounts = 0;
            bool?success   = null;
            var  stopwatch = Stopwatch.StartNew();

            BrokeredMessageExtensions
            .SafeMessagingActionAsync(
                c => c(Mock.Of <IAsyncResult>()),
                ar => { if (++endCounts < 2)
                        {
                            throw new TimeoutException();
                        }
                },
                new BrokeredMessage(),
                s => success = s,
                "error: '{0}' '{1}' '{2}' '{3}' '{4}' '{5}' '{6}'",
                "message id",
                "sub",
                5000,
                1000,
                stopwatch);

            Assert.Equal(2, endCounts);
            Assert.True(success.HasValue);
            Assert.True(success.Value);
            Assert.False(stopwatch.IsRunning);
        }
Beispiel #2
0
        public void Given_Null_Parameters_When_ValidateAsync_Invoked_Then_It_Should_Throw_Exception()
        {
            var validator = new Mock <ISchemaValidator>();

            using (var message = new BrokeredMessage())
            {
                var func = default(Func <Task>);

                func = async() => await BrokeredMessageExtensions.ValidateAsync((BrokeredMessage)null, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await BrokeredMessageExtensions.ValidateAsync(message, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await BrokeredMessageExtensions.ValidateAsync(message, validator.Object, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await BrokeredMessageExtensions.ValidateAsync(Task.FromResult(message), null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await BrokeredMessageExtensions.ValidateAsync(Task.FromResult(message), validator.Object, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();
            }
        }
Beispiel #3
0
        public async Task Given_Message_When_BeforeMessageSend_Invoked_Then_It_Should_Return_Result(string body, string path)
        {
            var validator = new Mock <ISchemaValidator>();

            validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
                using (var message = new BrokeredMessage(stream))
                {
                    message.Properties.Add("schemaPath", path);

                    var result = await BrokeredMessageExtensions.ValidateAsync(message, validator.Object).ConfigureAwait(false);

                    result.Should().Be(message);
                }

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
                using (var message = new BrokeredMessage(stream))
                {
                    message.Properties.Add("schemaPath", path);

                    var result = await BrokeredMessageExtensions.ValidateAsync(Task.FromResult(message), validator.Object).ConfigureAwait(false);

                    result.Should().Be(message);
                }
        }
Beispiel #4
0
        public void Given_Validation_Error_When_ValidateAsync_Invoked_Then_It_Should_Throw_Exception(string body, string path)
        {
            var exception = new SchemaValidationException();
            var validator = new Mock <ISchemaValidator>();

            validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ThrowsAsync(exception);

            var func = default(Func <Task>);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
                using (var message = new BrokeredMessage(stream))
                {
                    message.Properties.Add("schemaPath", path);

                    func = async() => await BrokeredMessageExtensions.ValidateAsync(message, validator.Object).ConfigureAwait(false);

                    func.Should().Throw <SchemaValidationException>();
                }

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
                using (var message = new BrokeredMessage(stream))
                {
                    message.Properties.Add("schemaPath", path);

                    func = async() => await BrokeredMessageExtensions.ValidateAsync(Task.FromResult(message), validator.Object).ConfigureAwait(false);

                    func.Should().Throw <SchemaValidationException>();
                }
        }
Beispiel #5
0
        public void Given_Message_With_Empty_SchemaPath_When_ValidateAsync_Invoked_Then_It_Should_Throw_Exception(string body)
        {
            var validator = new Mock <ISchemaValidator>();
            var func      = default(Func <Task>);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
                using (var message = new BrokeredMessage(stream))
                {
                    message.Properties.Add("schemaPath", string.Empty);

                    func = async() => await BrokeredMessageExtensions.ValidateAsync(message, validator.Object).ConfigureAwait(false);

                    func.Should().Throw <SchemaPathNotExistException>();
                }

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
                using (var message = new BrokeredMessage(stream))
                {
                    message.Properties.Add("schemaPath", string.Empty);

                    func = async() => await BrokeredMessageExtensions.ValidateAsync(Task.FromResult(message), validator.Object).ConfigureAwait(false);

                    func.Should().Throw <SchemaPathNotExistException>();
                }
        }
Beispiel #6
0
        public void Given_Empty_Body_When_ValidateAsync_Invoked_Then_It_Should_Throw_Exception()
        {
            var validator = new Mock <ISchemaValidator>();
            var func      = default(Func <Task>);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty)))
                using (var message = new BrokeredMessage(stream))
                {
                    func = async() => await BrokeredMessageExtensions.ValidateAsync(message, validator.Object).ConfigureAwait(false);

                    func.Should().Throw <MessageBodyZeroLengthException>();
                }

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty)))
                using (var message = new BrokeredMessage(stream))
                {
                    func = async() => await BrokeredMessageExtensions.ValidateAsync(Task.FromResult(message), validator.Object).ConfigureAwait(false);

                    func.Should().Throw <MessageBodyZeroLengthException>();
                }
        }