-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jeromelaban/dev/converter-unsetvalue-fix
test: Add unit tests for UnsetValue returning converter
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Dynamic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Data; | ||
|
||
namespace Uno.UI.Tests.BinderTests | ||
{ | ||
[TestClass] | ||
public partial class Given_Binder_Converter | ||
{ | ||
[TestMethod] | ||
public void When_Converter_Returns_UnsetValue() | ||
{ | ||
var SUT = new MyControl(); | ||
|
||
var myTestConverter = new MyTestConverter(); | ||
|
||
SUT.SetBinding( | ||
MyControl.MyPropertyProperty, | ||
new Windows.UI.Xaml.Data.Binding() | ||
{ | ||
Path = new PropertyPath("."), | ||
Converter = myTestConverter, | ||
FallbackValue = "fallback value", | ||
TargetNullValue = "null value" | ||
} | ||
); | ||
|
||
myTestConverter.OutputValue = v => v; | ||
SUT.DataContext = "hello"; | ||
Assert.AreEqual("hello", SUT.MyProperty); | ||
|
||
myTestConverter.OutputValue = v => DependencyProperty.UnsetValue; | ||
SUT.DataContext = "hello 3"; | ||
Assert.AreEqual("fallback value", SUT.MyProperty); | ||
} | ||
|
||
internal class MyTestConverter : IValueConverter | ||
{ | ||
public Func<object, object?> OutputValue { get; set; } = o => null; | ||
|
||
public object? Convert(object value, Type targetType, object parameter, string language) => OutputValue(value); | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); | ||
} | ||
|
||
public partial class MyControl : DependencyObject | ||
{ | ||
public string MyProperty | ||
{ | ||
get { return (string)GetValue(MyPropertyProperty); } | ||
set { SetValue(MyPropertyProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty MyPropertyProperty = | ||
DependencyProperty.Register("MyProperty", typeof(string), typeof(MyControl), new FrameworkPropertyMetadata(null)); | ||
} | ||
} | ||
|
||
} |