public void Assign_WithMixedTokensSixArguments_CountAsExpected(String formats, Int32 expected)
        {
            IEnumerable <BaseToken> tokens = this.CreateTokens(formats);

            Object[] arguments = new Object[] { 111111, 222222, 333333, 444444, 555555, 666666 };

            IArgumentRelations actual = RelationsAssigner.Assign(tokens, arguments);

            Assert.That(actual.Count, Is.EqualTo(expected));
        }
        public void Assign_TokensEmpty_ResultAsExpected()
        {
            IEnumerable <BaseToken> tokens = new List <BaseToken>();

            Object[] arguments = new Object[] { "argument1" };

            IArgumentRelations actual = RelationsAssigner.Assign(tokens, arguments);

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Count, Is.Zero);
        }
        public void Assign_ArgumentsEmpty_ResultAsExpected()
        {
            IEnumerable <BaseToken> tokens = new List <BaseToken>()
            {
                new TextToken(0, new StringBuilder("sometext"))
            };

            Object[] arguments = new Object[0];

            IArgumentRelations actual = RelationsAssigner.Assign(tokens, arguments);

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Count, Is.Zero);
        }
        public void Assign_OneHoleTokenWithFormatThreeArguments_ResultIsOne()
        {
            IEnumerable <BaseToken> tokens = new List <BaseToken>()
            {
                new HoleToken(0, 1, new StringBuilder("{fmt}"))
            };

            Object[] arguments = new Object[]
            {
                "someargument", 42, Guid.NewGuid()
            };

            IArgumentRelations actual = RelationsAssigner.Assign(tokens, arguments);

            Assert.That(actual.Count, Is.EqualTo(1));
        }
        public void Assign_ThreeHoleTokensWithFormatOneArgument_ResultIsThree()
        {
            IEnumerable <BaseToken> tokens = new List <BaseToken>()
            {
                new HoleToken(0, 1, new StringBuilder("{fmt}")),
                new HoleToken(0, 2, new StringBuilder("{fmt}")),
                new HoleToken(0, 3, new StringBuilder("{fmt}"))
            };

            Object[] arguments = new Object[]
            {
                "someargument"
            };

            IArgumentRelations actual = RelationsAssigner.Assign(tokens, arguments);

            Assert.That(actual.Count, Is.EqualTo(3));
        }
        /// <summary>
        /// Formats the list of <paramref name="arguments"/> into the <paramref name="format"/> string using
        /// given <paramref name="options"/>.
        /// </summary>
        /// <remarks>
        /// This method formats the list of <paramref name="arguments"/> into the <paramref name="format"/>
        /// string using given <paramref name="options"/>.
        /// </remarks>
        /// <param name="discard">
        /// This parameter is only for internal handling and tells the method to resolve relation assignments
        /// or not.
        /// </param>
        /// <param name="options">
        /// An instance of class <see cref="Options"/> with detailed formatting instructions.
        /// </param>
        /// <param name="relations">
        /// When this method returns, this parameter contains a list of Label-Value relations consisting
        /// of the labels taken from <paramref name="format"/> and the <paramref name="arguments"/> as
        /// their values.
        /// </param>
        /// <param name="format">
        /// A string containing formatting instructions, either for index-based formatting, like
        /// <c>"{0}, {1}, ..."</c>, or for template-based formatting, like <c>"{name1}, {name2}, ..."</c>).
        /// </param>
        /// <param name="arguments">
        /// The optional list of arguments to be used.
        /// </param>
        /// <returns>
        /// A copy of <paramref name="format"/> with the format elements replaced by the string representation
        /// of the corresponding objects in <paramref name="arguments"/>.
        /// </returns>
        private static String Format(Boolean discard, Options options, out IArgumentRelations relations, String format, params Object[] arguments)
        {
            relations = RelationsAssigner.Default;

            if (format == null || format.Length == 0)
            {
                return(String.Empty);
            }

            StringBuilder output = new StringBuilder(512);

            IEnumerable <BaseToken> tokens = TemplateParser.Parse(format);

            arguments = arguments.ExpandArguments();

            TemplateWeaver.Weave(options, tokens, output, arguments);

            if (!discard)
            {
                relations = RelationsAssigner.Assign(tokens, arguments);
            }

            return(Template.Truncate(options, output).ToString());
        }
        public void ArgumentRelations_ArrayOperatorLabelIsValid_ResultIsNotNull(String label, Int32 count)
        {
            IArgumentRelations actual = this.CreateInstance(count);

            Assert.That(actual[label], Is.Not.Null);
        }
        public void ArgumentRelations_ArrayOperatorIndexIsValid_ResultIsNotNull(Int32 index, Int32 count)
        {
            IArgumentRelations actual = this.CreateInstance(count);

            Assert.That(actual[index], Is.Not.Null);
        }
        public void ArgumentRelations_DefaultConstruction_PropertiesAsExpected()
        {
            IArgumentRelations actual = this.CreateInstance(0);

            Assert.That(actual.Count, Is.Zero);
        }
        public void ToArray_WithDifferentCounts_ItemsAsExpected(Int32 count)
        {
            IArgumentRelations instance = this.CreateInstance(count);

            (String Label, Object Value)[] actual = instance.ToArray();
        public void ToArray_WithDifferentCounts_LengthAsExpected(Int32 count, Int32 expected)
        {
            IArgumentRelations actual = this.CreateInstance(count);

            Assert.That(actual.ToArray().Length, Is.EqualTo(expected));
        }
        public void IndexOf_LabelAsProvided_IndexAsExpected(String label, Int32 count, Int32 expected)
        {
            IArgumentRelations actual = this.CreateInstance(count);

            Assert.That(actual.IndexOf(label), Is.EqualTo(expected));
        }
 /// <summary>
 /// Formats the list of <paramref name="arguments"/> into the <paramref name="format"/> string using
 /// given <paramref name="options"/>.
 /// </summary>
 /// <remarks>
 /// This method formats the list of <paramref name="arguments"/> into the <paramref name="format"/>
 /// string using given <paramref name="options"/>.
 /// </remarks>
 /// <param name="options">
 /// An instance of class <see cref="Options"/> with detailed formatting instructions.
 /// </param>
 /// <param name="relations">
 /// When this method returns, this parameter contains a list of Label-Value relations consisting
 /// of the labels taken from <paramref name="format"/> and the <paramref name="arguments"/> as
 /// their values.
 /// </param>
 /// <param name="format">
 /// A string containing formatting instructions, either for index-based formatting, like
 /// <c>"{0}, {1}, ..."</c>, or for template-based formatting, like <c>"{name1}, {name2}, ..."</c>).
 /// </param>
 /// <param name="arguments">
 /// The optional list of arguments to be used.
 /// </param>
 /// <returns>
 /// A copy of <paramref name="format"/> with the format elements replaced by the string representation
 /// of the corresponding objects in <paramref name="arguments"/>.
 /// </returns>
 public static String Format(Options options, out IArgumentRelations relations, String format, params Object[] arguments)
 {
     return(Template.Format(false, options, out relations, format, arguments));
 }
 /// <summary>
 /// Formats the list of <paramref name="arguments"/> into the <paramref name="format"/> string using
 /// given format <paramref name="provider"/> as well as given argument <paramref name="serializer"/>.
 /// </summary>
 /// <remarks>
 /// This method formats the list of <paramref name="arguments"/> into the <paramref name="format"/> string
 /// using given format <paramref name="provider"/> as well as given argument <paramref name="serializer"/>.
 /// </remarks>
 /// <param name="provider">
 /// An instance of a <see cref="IFormatProvider"/> derived class used the to perform culture-specific
 /// formatting.
 /// </param>
 /// <param name="serializer">
 /// An instance of a <see cref="IArgumentSerializer"/> derived class used the to perform any kind
 /// of serialization for custom types.
 /// </param>
 /// <param name="relations">
 /// When this method returns, this parameter contains a list of Label-Value relations consisting
 /// of the labels taken from <paramref name="format"/> and the <paramref name="arguments"/> as
 /// their values.
 /// </param>
 /// <param name="format">
 /// A string containing formatting instructions, either for index-based formatting, like
 /// <c>"{0}, {1}, ..."</c>, or for template-based formatting, like <c>"{name1}, {name2}, ..."</c>).
 /// </param>
 /// <param name="arguments">
 /// The optional list of arguments to be used.
 /// </param>
 /// <returns>
 /// A copy of <paramref name="format"/> with the format elements replaced by the string representation
 /// of the corresponding objects in <paramref name="arguments"/>.
 /// </returns>
 /// <seealso cref="Template.Format(String, Object[])"/>
 /// <seealso cref="Template.Format(IFormatProvider, String, Object[])"/>
 /// <seealso cref="Template.Format(IArgumentSerializer, String, Object[])"/>
 /// <seealso cref="Template.Format(Options, String, Object[])"/>
 public static String Format(IFormatProvider provider, IArgumentSerializer serializer, out IArgumentRelations relations, String format, params Object[] arguments)
 {
     return(Template.Format(false, Options.Create(provider, serializer), out relations, format, arguments));
 }
 /// <summary>
 /// Formats the list of <paramref name="arguments"/> into the <paramref name="format"/> string.
 /// </summary>
 /// <remarks>
 /// This method formats the list of <paramref name="arguments"/> into the <paramref name="format"/>
 /// string. This is for sure the simplest way of template formatting.
 /// </remarks>
 /// <param name="relations">
 /// When this method returns, this parameter contains a list of Label-Value relations consisting
 /// of the labels taken from <paramref name="format"/> and the <paramref name="arguments"/> as
 /// their values.
 /// </param>
 /// <param name="format">
 /// A string containing formatting instructions, either for index-based formatting, like
 /// <c>"{0}, {1}, ..."</c>, or for template-based formatting, like <c>"{name1}, {name2}, ..."</c>).
 /// </param>
 /// <param name="arguments">
 /// The optional list of arguments to be used.
 /// </param>
 /// <returns>
 /// A copy of <paramref name="format"/> with the format elements replaced by the string representation
 /// of the corresponding objects in <paramref name="arguments"/>.
 /// </returns>
 /// <seealso cref="Template.Format(IFormatProvider, String, Object[])"/>
 /// <seealso cref="Template.Format(IArgumentSerializer, String, Object[])"/>
 /// <seealso cref="Template.Format(IFormatProvider, IArgumentSerializer, String, Object[])"/>
 /// <seealso cref="Template.Format(Options, String, Object[])"/>
 public static String Format(out IArgumentRelations relations, String format, params Object[] arguments)
 {
     return(Template.Format(false, Options.Create(null, null), out relations, format, arguments));
 }