public void WhenParameterIsInvalidFormat_ThenReturnValue() { var converter = new StringFormatConverter(); var result = converter.Convert(Date, typeof(string), "{1:}", "en-us"); Assert.AreEqual(Date, result); }
internal void UpdateActualLabelContent() { if (this.LabelContent != null) { this.ActualLabelContent = this.LabelContent; } else if (this.ShowValueAsLabel) { StringFormatConverter stringFormatConverter = new StringFormatConverter(); string str = ValueHelper.PrepareFormatString(this.StringFormat); bool flag = false; double doubleValue; if (this.Series != null && this.Series.LabelDisplayUnitSystem != null && ValueHelper.TryConvert(this.PrimaryValue, false, out doubleValue)) { this.Series.LabelDisplayUnitSystem.CalculateActualDisplayUnit(doubleValue, str); if (this.Series.LabelDisplayUnitSystem.ActualDisplayUnit != null) { flag = true; this.ActualLabelContent = this.Series.LabelDisplayUnitSystem.FormatLabel(str, (object)doubleValue, new int?(2)); } } if (flag) { return; } this.ActualLabelContent = stringFormatConverter.Convert(this.PrimaryValue, (Type)null, (object)str, (CultureInfo)null); } else { this.ActualLabelContent = (object)null; } }
public void WhenValueExistsAndParameterIsNull_ThenReturnValue() { var converter = new StringFormatConverter(); var result = converter.Convert(NotEmptyString, typeof(string), NullString, "en-us"); Assert.AreEqual(NotEmptyString, result); }
public void WhenParameterIsTimeFormat_ThenReturnValueOfTimeFormat() { var converter = new StringFormatConverter(); var result = converter.Convert(Date, typeof(string), "{0:HH:mm}", "en-us"); Assert.AreEqual(Date.ToString("HH:mm"), result); }
public void WhenParameterIsNotAString_ThenReturnValue() { var converter = new StringFormatConverter(); var result = converter.Convert(NotEmptyString, typeof(string), 172, "en-us"); Assert.AreEqual(NotEmptyString, result); }
public void WhenValueIsNull_ThenReturnNull() { var converter = new StringFormatConverter(); var result = converter.Convert(NullString, typeof(string), NullString, "en-us"); Assert.IsNull(result); }
public void ConvertWithDoubleReturnsFormattedString() { var converter = new StringFormatConverter(); var expected = "The result: 12,345.68!"; var actual = converter.Convert(12345.6789, typeof(string), "The result: {0:N2}!", CultureInfo.CurrentCulture); Assert.AreEqual(actual, expected); }
public void ConvertWithDateTimeReturnsFormattedString() { var converter = new StringFormatConverter(); var expected = "The result: 1981-08-20T12:20:05.1230000!"; var actual = converter.Convert(new DateTime(1981, 8, 20, 12, 20, 5, 123), typeof(string), "The result: {0:o}!", CultureInfo.CurrentCulture); Assert.AreEqual(actual, expected); }
public void ConvertWithStringReturnsFormattedString() { var converter = new StringFormatConverter(); var expected = "The result: My String!"; var actual = converter.Convert("My String", typeof(string), "The result: {0}!", CultureInfo.CurrentCulture); Assert.AreEqual(actual, expected); }
public void Convert_UnsupportableTargetTypes_ExceptionThrown(Type targetType) { // ARRANGE. var converter = new StringFormatConverter(); // ACT + ASSERT. var exception = Assert.Throws <Exception>(() => converter.Convert(_values, targetType, null, CultureInfo.InvariantCulture)); Assert.Equal("TargetType is not supported strings", exception.Message); }
public void Convert_ValuesIsEmpty_ExceptionThrown() { // ARRANGE. var converter = new StringFormatConverter(); // ACT + ASSERT. var exception = Assert.Throws <Exception>(() => converter.Convert(Array.Empty <object>(), typeof(string), null, CultureInfo.InvariantCulture)); Assert.Equal("Not enough parameters", exception.Message); }
public void From_decimal() { // Arrange var c = new StringFormatConverter(typeof(decimal), "F2"); // Act var result = c.FieldToString(1234.5678m); // Assert Assert.AreEqual("1234.57", result); }
public void Convert_SpecifiedValues_ValueConverted(string expectedConvertedValue, params object[] values) { // ARRANGE. var converter = new StringFormatConverter(); // ACT. var convertedValue = converter.Convert(values, typeof(string), null, CultureInfo.InvariantCulture); // ASSERT. Assert.Equal(expectedConvertedValue, convertedValue); }
public void ConvertBack_AnyValue_ReturnsNull() { // ARRANGE. var converter = new StringFormatConverter(); // ACT. var originalValues = converter.ConvertBack(CONVERTED_VALUE, new [] { typeof(string) }, null, CultureInfo.InvariantCulture); // ASSERT. Assert.Null(originalValues); }
public void Convert_SecondValueIsUnsetValue_ReturnsNull() { // ARRANGE. var converter = new StringFormatConverter(); // ACT. var convertedValue = converter.Convert(new[] { CONVERTED_VALUE, DependencyProperty.UnsetValue }, typeof(string), null, CultureInfo.InvariantCulture); // ASSERT. Assert.Null(convertedValue); }
public void To_integer_from_decimal() { // Arrange var c = new StringFormatConverter(typeof(int), "F0"); // Act var result = c.StringToField("1235"); // Assert Assert.AreEqual(1235.0m, result); }
public void From_decimal_to_integer() { // Arrange var c = new StringFormatConverter(typeof(int), "F0"); // Act var result = c.FieldToString(1234.5678m); // Assert Assert.AreEqual("1235", result); }
public void To_decimal() { // Arrange var c = new StringFormatConverter(typeof(decimal), "F2"); // Act var result = c.StringToField("1234.57"); // Assert Assert.AreEqual(1234.57m, result); }
public void Convert_FormatStringIsNull_ReturnsNull() { // ARRANGE. var converter = new StringFormatConverter(); // ACT. var convertedValue = converter.Convert(new object[] { null, "hello", "world" }, typeof(string), null, CultureInfo.InvariantCulture); // ASSERT. Assert.Null(convertedValue); }
public void Convert_SupportedTargetType_ValueConverted(Type targetType) { // ARRANGE. var converter = new StringFormatConverter(); // ACT. var convertedValue = converter.Convert(_values, targetType, null, CultureInfo.InvariantCulture); // ASSERT. Assert.Equal(CONVERTED_VALUE, convertedValue); }
public void StringFormatConverterBasicTest() { string book = "Star Wars - Heir to the Empire"; string format = "Book: {0}"; StringFormatConverter converter = StringFormatConverter.Default; Assert.AreEqual(string.Format(null, format, book), converter.Convert(book, null, format, null)); Assert.AreEqual(string.Format(null, "{0}", book), converter.Convert(book, null, null, null)); //AssertHelper.ExpectedException<NotSupportedException>(() => converter.ConvertBack(null, null, null, null)); }
public void StringFormatMultiConverterBasicTest() { string book = "Star Wars - Heir to the Empire"; string author = "Timothy Zahn"; string format = "Book: {0} by {1}"; StringFormatConverter converter = StringFormatConverter.Default; Assert.AreEqual(string.Format(null, format, new[] { book, author }), converter.Convert(new[] { book, author }, null, format, null)); Assert.AreEqual(string.Format(null, "{0}", new[] { book, author }), converter.Convert(new[] { book, author }, null, null, null)); AssertHelper.ExpectedException <NotSupportedException>(() => converter.ConvertBack(null, (Type[])null !, null, null)); }
protected override string GetNameCore() { StringBuilder stringBuilder = new StringBuilder(); if (this.DataPoint.IsSelected) { stringBuilder.Append(Resources.DataPointHighlightedScreenReaderContent); } stringBuilder.Append(Resources.DataPointDetailsScreenReaderContent); string str1 = base.GetNameCore(); if (string.IsNullOrEmpty(str1) && this.DataPoint.ToolTipContent != null) { str1 = this.DataPoint.ToolTipContent.AutomationName; } if (string.IsNullOrEmpty(str1)) { str1 = this.DataPoint.ActualLabelContent as string; } if (string.IsNullOrEmpty(str1) && this.DataPoint is XYDataPoint) { XYDataPoint xyDataPoint = (XYDataPoint)this.DataPoint; if (xyDataPoint.XValue != null) { str1 = ((XYDataPoint)this.DataPoint).XValue.ToString(); } if (xyDataPoint.YValue != null) { if (!string.IsNullOrEmpty(str1)) { str1 += "; "; } StringFormatConverter stringFormatConverter = new StringFormatConverter(); string str2 = ValueHelper.PrepareFormatString(xyDataPoint.StringFormat); str1 += (string)stringFormatConverter.Convert(xyDataPoint.YValue, (Type)null, (object)str2, (CultureInfo)null); } } if (string.IsNullOrEmpty(str1)) { str1 = this.DataPoint.Name; } if (string.IsNullOrEmpty(str1)) { str1 = this.DataPoint.GetType().Name; } stringBuilder.Append(str1); return(stringBuilder.ToString()); }
protected override string GetNameCore() { StringBuilder stringBuilder = new StringBuilder(); if (this.DataPoint.IsSelected) stringBuilder.Append(Resources.DataPointHighlightedScreenReaderContent); stringBuilder.Append(Resources.DataPointDetailsScreenReaderContent); string str1 = base.GetNameCore(); if (string.IsNullOrEmpty(str1) && this.DataPoint.ToolTipContent != null) str1 = this.DataPoint.ToolTipContent.AutomationName; if (string.IsNullOrEmpty(str1)) str1 = this.DataPoint.ActualLabelContent as string; if (string.IsNullOrEmpty(str1) && this.DataPoint is XYDataPoint) { XYDataPoint xyDataPoint = (XYDataPoint)this.DataPoint; if (xyDataPoint.XValue != null) str1 = ((XYDataPoint)this.DataPoint).XValue.ToString(); if (xyDataPoint.YValue != null) { if (!string.IsNullOrEmpty(str1)) str1 += "; "; StringFormatConverter stringFormatConverter = new StringFormatConverter(); string str2 = ValueHelper.PrepareFormatString(xyDataPoint.StringFormat); str1 += (string)stringFormatConverter.Convert(xyDataPoint.YValue, (Type)null, (object)str2, (CultureInfo)null); } } if (string.IsNullOrEmpty(str1)) str1 = this.DataPoint.Name; if (string.IsNullOrEmpty(str1)) str1 = this.DataPoint.GetType().Name; stringBuilder.Append(str1); return stringBuilder.ToString(); }
internal void UpdateActualLabelContent() { if (this.LabelContent != null) this.ActualLabelContent = this.LabelContent; else if (this.ShowValueAsLabel) { StringFormatConverter stringFormatConverter = new StringFormatConverter(); string str = ValueHelper.PrepareFormatString(this.StringFormat); bool flag = false; double doubleValue; if (this.Series != null && this.Series.LabelDisplayUnitSystem != null && ValueHelper.TryConvert(this.PrimaryValue, false, out doubleValue)) { this.Series.LabelDisplayUnitSystem.CalculateActualDisplayUnit(doubleValue, str); if (this.Series.LabelDisplayUnitSystem.ActualDisplayUnit != null) { flag = true; this.ActualLabelContent = this.Series.LabelDisplayUnitSystem.FormatLabel(str, (object)doubleValue, new int?(2)); } } if (flag) return; this.ActualLabelContent = stringFormatConverter.Convert(this.PrimaryValue, (Type)null, (object)str, (CultureInfo)null); } else this.ActualLabelContent = (object)null; }
public void ConvertBackIsNotImplemented() { var converter = new StringFormatConverter(); Assert.ThrowsException <NotImplementedException>(() => converter.ConvertBack(null, typeof(string), null, CultureInfo.CurrentCulture)); }
public void Setup() { m_converter = new StringFormatConverter(); }