Help to build a properly formatted fluent error message.
Example #1
0
        /// <summary>
        /// Builds an error message in.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>A <see cref="FluentMessage"/> instance.</returns>
        public FluentMessage BuildMessage(string message)
        {
            var result = FluentMessage.BuildMessage(message);

            result.On(this.Value);
            return(result);
        }
Example #2
0
        /// <summary>
        /// Builds an error message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>A <see cref="FluentMessage"/> instance.</returns>
        public FluentMessage BuildShortMessage(string message)
        {
            var result = FluentMessage.BuildMessage(message);

            if (!string.IsNullOrEmpty(this.sutLabel))
            {
                result.For(this.sutLabel);
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBlock"/> class.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="type">
        /// The tested type.
        /// </param>
        /// <param name="label">
        /// The block label.
        /// </param>
        internal MessageBlock(FluentMessage message, Type type, GenericLabelBlock label)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            this.value   = new InstanceBlock(type);
            this.message = message;
            this.block   = label;
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="test">
 /// The tested object.
 /// </param>
 /// <param name="block">
 /// The block attribute.
 /// </param>
 /// <param name="forceArray">test is an enumeration.</param>>
 /// <param name="index">The index for enumerable types</param>
 internal MessageBlock(FluentMessage message, object test, GenericLabelBlock block, long index = 0, bool forceArray = false)
     : this(message, test.GetTypeWithoutThrowingException(), block)
 {
     if (!(test is string) && (forceArray || (test is IEnumerable)))
     {
         this.value = new EnumerationBlock((IEnumerable)test, index);
     }
     else
     {
         this.value = new ValueBlock(test);
     }
 }
Example #5
0
        public void BlockTest()
        {
            var message = new FluentMessage("test");
            var x = 4;
            var block = new FluentMessage.MessageBlock(message, x, string.Empty);

            Assert.AreEqual("The  value:\n\t[4]", block.GetMessage());

            block.WithHashCode().WithType();

            Assert.AreEqual("The  value:\n\t[4] of type: [int] with HashCode: [4]", block.GetMessage());
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="test">
 /// The tested object.
 /// </param>
 /// <param name="block">
 /// The block attribute.
 /// </param>
 /// <param name="index">The index for enumerable types</param>
 internal MessageBlock(FluentMessage message, object test, GenericLabelBlock block, int index = 0)
     : this(message, test.GetTypeWithoutThrowingException(), block)
 {
     if (!(test is string) && (test is IEnumerable))
     {
         this.value = new EnumerationBlock((IEnumerable) test, index);
     }
     else
     {
         this.value = new ValueBlock(test);
     }
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="test">
 /// The tested object.
 /// </param>
 /// <param name="index">Index to focus on.</param>
 /// <param name="block">
 /// The block attribute.
 /// </param>
 internal MessageBlock(FluentMessage message, IEnumerable test, int index, GenericLabelBlock block)
     : this(message, test.GetTypeWithoutThrowingException(), block)
 {
     if (!(test is string))
     {
         this.value = new EnumerationBlock(test, index);
     }
     else
     {
         this.value = new ValueBlock(test);
     }
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="test">
 /// The tested object.
 /// </param>
 /// <param name="block">
 /// The block attribute.
 /// </param>
 internal MessageBlock(FluentMessage message, object test, GenericLabelBlock block)
     : this(message, test.GetTypeWithoutThrowingException(), block)
 {
     if (!(test is string) && (test is IEnumerable))
     {
         this.value = new EnumerationBlock(test as IEnumerable, 0);
     }
     else
     {
         this.value = new ValueBlock(test);
     }
 }
Example #9
0
            /// <summary>
            /// Initializes a new instance of the <see cref="MessageBlock"/> class.
            /// </summary>
            /// <param name="message">The message.</param>
            /// <param name="type">The tested type.</param>
            /// <param name="attribute">The block attribute.</param>
            public MessageBlock(FluentMessage message, Type type, string attribute)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                this.message     = message;
                this.test        = null;
                this.type        = type;
                this.anyInstance = true;
                this.attribute   = attribute;
            }
Example #10
0
        internal static MessageBlock Build <T>(FluentMessage message, T value, GenericLabelBlock block, long index = 0,
                                               bool forceArray = false)
        {
            var result = new MessageBlock(message, block);

            if (value.IsAnEnumeration(forceArray))
            {
                result.value = new EnumerationBlock <IEnumerable>(value as IEnumerable, index);
            }
            else
            {
                result.value = new ValueBlock <T>(value);
            }
            return(result);
        }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="test">The tested object.</param>
 /// <param name="attribute">The block attribute.</param>
 public MessageBlock(FluentMessage message, object test, string attribute) : this(message, test.GetTypeWithoutThrowingException(), attribute)
 {
     this.test = test;
     this.anyInstance = false;
 }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBlock"/> class.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="type">
        /// The tested type.
        /// </param>
        /// <param name="label">
        /// The block label.
        /// </param>
        internal MessageBlock(FluentMessage message, Type type, GenericLabelBlock label)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            this.value = new InstanceBlock(type);
            this.message = message;
            this.block = label;
        }
Example #13
0
 internal MessageBlock(FluentMessage message, GenericLabelBlock block)
 {
     this.And   = message;
     this.block = block;
 }
Example #14
0
        /// <summary>
        /// Builds an error message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>A <see cref="FluentMessage"/> instance.</returns>
        public FluentMessage BuildShortMessage(string message)
        {
            var result = FluentMessage.BuildMessage(message);

            return(result);
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="type">
 /// The tested type.
 /// </param>
 /// <param name="label">
 /// The block label.
 /// </param>
 internal MessageBlock(FluentMessage message, Type type, GenericLabelBlock label)
 {
     this.value   = new InstanceBlock(type);
     this.message = message;
     this.block   = label;
 }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageBlock"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="test">The tested object.</param>
 /// <param name="attribute">The block attribute.</param>
 public MessageBlock(FluentMessage message, object test, string attribute) : this(message, test.GetTypeWithoutThrowingException(), attribute)
 {
     this.test        = test;
     this.anyInstance = false;
 }
Example #17
0
            /// <summary>
            /// Initializes a new instance of the <see cref="MessageBlock"/> class.
            /// </summary>
            /// <param name="message">The message.</param>
            /// <param name="test">The tested object.</param>
            /// <param name="attribute">The block attribute.</param>
            public MessageBlock(FluentMessage message, object test, string attribute)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                this.message = message;
                this.test = test;
                this.type = test.GetTypeWithoutThrowingException();
                this.attribute = attribute;
            }
Example #18
0
            /// <summary>
            /// Initializes a new instance of the <see cref="MessageBlock"/> class.
            /// </summary>
            /// <param name="message">The message.</param>
            /// <param name="type">The tested type.</param>
            /// <param name="attribute">The block attribute.</param>
            public MessageBlock(FluentMessage message, Type type, string attribute)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                this.message = message;
                this.test = null;
                this.type = type;
                this.anyInstance = true;
                this.attribute = attribute;
            }