public void format_should_return_formatted_status_string(ApiVersionFormatProvider provider)
        {
            // arrange
            var apiVersion = new ApiVersion(2, 5, "Beta");

            // act
            var status = provider.Format("S", apiVersion, CurrentCulture);

            // assert
            status.Should().Be("Beta");
        }
        public void format_should_return_formatted_long_version_string(ApiVersionFormatProvider provider)
        {
            // arrange
            var apiVersion = ApiVersion.Parse("1-RC");

            // act
            var minorVersion = provider.Format("VVVV", apiVersion, CurrentCulture);

            // assert
            minorVersion.Should().Be("1.0-RC");
        }
        public void format_should_return_formatted_short_version_string(ApiVersionFormatProvider provider)
        {
            // arrange
            var apiVersion = new ApiVersion(2, 0);

            // act
            var minorVersion = provider.Format("VVV", apiVersion, CurrentCulture);

            // assert
            minorVersion.Should().Be("2");
        }
        public void format_should_not_allow_malformed_literal_string(ApiVersionFormatProvider provider, string malformedFormat)
        {
            // arrange
            var apiVersion = new ApiVersion(new DateTime(2017, 5, 1));

            // act
            Action format = () => provider.Format(malformedFormat, apiVersion, null);

            // assert
            format.Should().Throw <FormatException>();
        }
        public void format_should_allow_null_or_empty_format_string(ApiVersionFormatProvider provider)
        {
            // arrange
            var apiVersion = new ApiVersion(1, 0);
            var expected   = new[] { apiVersion.ToString(), apiVersion.ToString() };

            // act
            var actual = new[] { provider.Format(null, apiVersion, CurrentCulture), provider.Format(Empty, apiVersion, CurrentCulture) };

            // assert
            actual.Should().Equal(expected);
        }
        public void get_format_should_return_expected_format_provider()
        {
            // arrange
            var formatType = typeof(ICustomFormatter);
            var provider   = new ApiVersionFormatProvider();

            // act
            var format = provider.GetFormat(formatType);

            // assert
            format.Should().BeSameAs(provider);
        }
        public void get_format_should_return_null_for_unsupported_format_type()
        {
            // arrange
            var formatType = typeof(object);
            var provider   = new ApiVersionFormatProvider();

            // act
            var format = provider.GetFormat(formatType);

            // assert
            format.Should().BeNull();
        }
        public void format_should_return_formatted_string_with_escape_sequence()
        {
            // arrange
            var groupVersion = new DateTime(2017, 5, 1);
            var apiVersion   = new ApiVersion(groupVersion, 1, 0, "Beta");
            var provider     = new ApiVersionFormatProvider();

            // act
            var result = provider.Format("VV '('\\'yy')'", apiVersion, CurrentCulture);

            // assert
            result.Should().Be("1.0 ('17)");
        }
        public void format_should_return_formatted_string_with_multiple_parameters(ApiVersionFormatProvider provider, string format, object secondArgument, string expected)
        {
            // arrange
            var groupVersion = new DateTime(2017, 5, 1);
            var apiVersion   = new ApiVersion(groupVersion, 1, 0, "Beta");
            var args         = new object[] { apiVersion, secondArgument };

            // act
            var status = Format(provider, format, args);

            // assert
            status.Should().Be(expected);
        }
        public void format_should_return_formatted_group_version_string(ApiVersionFormatProvider provider, string format)
        {
            // arrange
            var groupVersion = new DateTime(2017, 5, 1);
            var apiVersion   = new ApiVersion(groupVersion);
            var expected     = groupVersion.ToString(format, CurrentCulture);

            // act
            var actual = provider.Format(format, apiVersion, CurrentCulture);

            // assert
            actual.Should().Be(expected);
        }
        public void format_should_return_formatted_major_version_with_padding_string(ApiVersionFormatProvider provider, string format)
        {
            // arrange
            var numberFormat = format.Replace("P", "D");
            var apiVersion   = new ApiVersion(2, 5);

            if (numberFormat == "D")
            {
                numberFormat += "2";
            }

            // act
            var majorVersion = provider.Format(format, apiVersion, CurrentCulture);

            // assert
            majorVersion.Should().Be(apiVersion.MajorVersion.Value.ToString(numberFormat, CurrentCulture));
        }
Пример #12
0
        /// <summary>
        /// Returns the text representation of the version using the specified format and format provider.
        /// <seealso cref="ApiVersionFormatProvider"/></summary>
        /// <param name="format">The format to return the text representation in. The value can be <c>null</c> or empty.</param>
        /// <param name="formatProvider">The <see cref="IFormatProvider">format provider</see> used to generate text.
        /// This implementation should typically use an <see cref="InvariantCulture">invariant culture</see>.</param>
        /// <returns>The <see cref="string">string</see> representation of the version.</returns>
        /// <exception cref="FormatException">The specified <paramref name="format"/> is not one of the supported format values.</exception>
        public virtual string ToString(string format, IFormatProvider formatProvider)
        {
            var provider = ApiVersionFormatProvider.GetInstance(formatProvider);

            return(provider.Format(format, this, formatProvider));
        }
        public void format_should_return_original_string_format_when_argument_cannot_be_formatted(ApiVersionFormatProvider provider)
        {
            // arrange
            var value    = new object();
            var expected = new string[] { "d", value.ToString() };

            // act
            var actual = new[] { provider.Format("d", null, CurrentCulture), provider.Format("d", value, CurrentCulture) };

            // assert
            actual.Should().Equal(expected);
        }
        public void format_should_return_full_formatted_string_with_optional_components(ApiVersionFormatProvider provider)
        {
            // arrange
            var apiVersion = ApiVersion.Parse("2017-05-01.1-Beta");

            // act
            var format = provider.Format("FF", apiVersion, CurrentCulture);

            // assert
            format.Should().Be("2017-05-01.1.0-Beta");
        }