public void convert_return_unset_value_if_value_is_not_a_string() { var converter = new CaseConverter(); Assert.Same(DependencyProperty.UnsetValue, converter.Convert(123, null, null, null)); Assert.Same(DependencyProperty.UnsetValue, converter.Convert(123d, null, null, null)); Assert.Same(DependencyProperty.UnsetValue, converter.Convert(DateTime.Now, null, null, null)); }
public void convert_returns_upper_cased_value_if_target_casing_is_upper() { var converter = new CaseConverter { TargetCasing = CharacterCasing.Upper }; Assert.Equal("ABCD", converter.Convert("abcd", null, null, null)); Assert.Equal("ABCD", converter.Convert("ABCD", null, null, null)); Assert.Equal("ABCD", converter.Convert("AbCd", null, null, null)); }
public void convert_returns_same_value_if_target_casing_is_normal() { var converter = new CaseConverter { TargetCasing = CharacterCasing.Normal }; Assert.Equal("abcd", converter.Convert("abcd", null, null, null)); Assert.Equal("ABCD", converter.Convert("ABCD", null, null, null)); Assert.Equal("AbCd", converter.Convert("AbCd", null, null, null)); }
public void convert_uses_specified_culture_when_converting_to_lower_case() { var converter = new CaseConverter { TargetCasing = CharacterCasing.Lower }; var cultureInfo = new CultureInfo("tr"); Assert.Equal("ijk", converter.Convert("ijk", null, null, cultureInfo)); Assert.Equal("ıjk", converter.Convert("IJK", null, null, cultureInfo)); Assert.Equal("ijk", converter.Convert("iJk", null, null, cultureInfo)); }
private static void OnCharacterCasingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var val = (CharacterCasing)e.NewValue; DependencyProperty prop = d switch { TextBlock txt => TextBlock.TextProperty, TextBox tbox => TextBox.PlaceholderTextProperty, ButtonBase hBtn => ButtonBase.ContentProperty, PivotItem pvi => PivotItem.HeaderProperty, _ => throw new ArgumentException(), }; d.RegisterPropertyChangedCallback(prop, (s, e) => { if (_mutex) { return; } _mutex = true; d.SetValue(prop, CaseConverter.Convert((string)d.GetValue(prop), val)); _mutex = false; }); }
public void CaseConverter_Test_Equals() { string arg = "fOObaR"; Assert.Equal("Foobar", CaseConverter.Convert(arg)); }
public void convert_uses_specified_culture_when_converting_to_upper_case() { var converter = new CaseConverter { TargetCasing = CharacterCasing.Upper }; var cultureInfo = new CultureInfo("tr"); converter.TargetCasing = CharacterCasing.Upper; Assert.Equal("İJK", converter.Convert("ijk", null, null, cultureInfo)); Assert.Equal("IJK", converter.Convert("IJK", null, null, cultureInfo)); Assert.Equal("İJK", converter.Convert("iJk", null, null, cultureInfo)); }