public void Given_Null_Message_When_BeforeMessageSend_Invoked_Then_It_Should_Throw_Exception()
        {
            var instance = new SchemaValidatorPlugin();

            Func <Task> func = async() => await instance.BeforeMessageSend(null).ConfigureAwait(false);

            func.Should().Throw <ArgumentNullException>();
        }
        public void Given_Message_Without_SchemaPath_When_BeforeMessageSend_Invoked_Then_It_Should_Throw_Exception(string body)
        {
            var bytes    = Encoding.UTF8.GetBytes(body);
            var message  = new Message(bytes);
            var instance = new SchemaValidatorPlugin();

            Func <Task> func = async() => await instance.BeforeMessageSend(message).ConfigureAwait(false);

            func.Should().Throw <KeyNotFoundException>();
        }
        public void Given_Empty_Message_When_BeforeMessageSend_Invoked_Then_It_Should_Throw_Exception()
        {
            var body     = Array.Empty <byte>();
            var message  = new Message(body);
            var instance = new SchemaValidatorPlugin();

            Func <Task> func = async() => await instance.BeforeMessageSend(message).ConfigureAwait(false);

            func.Should().Throw <MessageBodyZeroLengthException>();
        }
        public void Given_Message_With_Empty_SchemaPath_When_BeforeMessageSend_Invoked_Then_It_Should_Throw_Exception(string body)
        {
            var bytes   = Encoding.UTF8.GetBytes(body);
            var message = new Message(bytes);

            message.UserProperties.Add("schemaPath", string.Empty);

            var instance = new SchemaValidatorPlugin();

            Func <Task> func = async() => await instance.BeforeMessageSend(message).ConfigureAwait(false);

            func.Should().Throw <SchemaPathNotExistException>();
        }
        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);

            var bytes   = Encoding.UTF8.GetBytes(body);
            var message = new Message(bytes);

            message.UserProperties.Add("schemaPath", path);

            var instance = new SchemaValidatorPlugin()
                           .WithValidator(validator.Object);

            var result = await instance.BeforeMessageSend(message).ConfigureAwait(false);

            result.Should().Be(message);
        }
        public void Given_Validation_Error_When_BeforeMessageSend_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 bytes   = Encoding.UTF8.GetBytes(body);
            var message = new Message(bytes);

            message.UserProperties.Add("schemaPath", path);

            var instance = new SchemaValidatorPlugin()
                           .WithValidator(validator.Object);

            Func <Task> func = async() => await instance.BeforeMessageSend(message).ConfigureAwait(false);

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