示例#1
0
        public void StringTemplateValueConverter_Works_With_Alignment_In_PlaceHolder()
        {
            var values = new ValuesForFormatProvider
            {
                DateTimeConvertedToTicks   = new DateTime(42),
                DateTimeConvertedToDayName = DateTime.Today
            };

            string expected = $"{values.DateTimeConvertedToDayName.DayOfWeek,-30}: {values.DateTimeConvertedToTicks.Ticks,30}";
            string actual   = StringTemplate.Format("{DateTimeConvertedToDayName,-30}: {DateTimeConvertedToTicks,30}", values);

            Assert.Equal(expected, actual);
        }
示例#2
0
        public void StringTemplateValueConverter_Works_With_FormatProvider_And_Return_Type_Change()
        {
            var ticks  = 1337;
            var values = new ValuesForFormatProvider {
                DateTimeConvertedToTicks = new DateTime(ticks)
            };
            var formatProvider = new NumberFormatInfo {
                CurrencySymbol = "piasses", CurrencyPositivePattern = 3                                         /* symbol at the end, with a space */
            };
            var expectedFormattedTicks = string.Format(formatProvider, "{0:C0}", ticks);

            var actual = StringTemplate.Format("{DateTimeConvertedToTicks:C0}", values, true, formatProvider);

            Assert.Equal(expectedFormattedTicks, actual);
        }
示例#3
0
        public void StringTemplateValueConverter_Works_With_FormatProvider()
        {
            var values = new ValuesForFormatProvider {
                DateTimeConvertedWithFortyTwoDaysAdded = DateTime.Today
            };
            var expectedConvertedDate = values.DateTimeConvertedWithFortyTwoDaysAdded + TimeSpan.FromDays(42);

            var cultures = new[] { CultureInfo.InvariantCulture, null, new CultureInfo("fr-FR") };

            foreach (var culture in cultures)
            {
                string expected = expectedConvertedDate.ToString("D", culture);
                string actual   = StringTemplate.Format("{DateTimeConvertedWithFortyTwoDaysAdded:D}", values, true, culture);
                Assert.Equal(expected, actual);
            }
        }