Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void ViewModelIndexerPropertyToView()
}

[Fact]
public void BindToShouldntInitiallySetToNull()
public void OneWayBindShouldntInitiallySetToNull()
{
var vm = new PropertyBindViewModel();
var view = new PropertyBindView { ViewModel = null };
Expand Down Expand Up @@ -354,6 +354,77 @@ public void OneWayBindConverter()
Assert.False(view.SomeTextBox.IsEnabled);
}

[Fact]
public void OneWayBindWithNullStartingValueToNonNullValue()
{
var vm = new PropertyBindViewModel();
var view = new PropertyBindView { ViewModel = vm };

view.OneWayBind(vm, x => x.Property1, x => x.SomeTextBox.Text);

vm.Property1 = "Baz";

Assert.Equal("Baz", view.SomeTextBox.Text);
}

[Fact]
public void OneWayBindWithNonNullStartingValueToNullValue()
{
var vm = new PropertyBindViewModel();
var view = new PropertyBindView { ViewModel = vm };

vm.Property1 = "Baz";

view.OneWayBind(vm, x => x.Property1, x => x.SomeTextBox.Text);

vm.Property1 = null;

Assert.True(string.IsNullOrEmpty(view.SomeTextBox.Text));
}

[Fact]
public void OneWayBindWithSelectorAndNonNullStartingValueToNullValue()
{
var vm = new PropertyBindViewModel();
var view = new PropertyBindView { ViewModel = vm };

view.OneWayBind(vm, x => x.Model, x => x.SomeTextBox.Text, x => x?.AnotherThing);

vm.Model = null;

Assert.True(string.IsNullOrEmpty(view.SomeTextBox.Text));
}

[Fact]
public void BindToWithNullStartingValueToNonNullValue()
{
var vm = new PropertyBindViewModel();
var view = new PropertyBindView { ViewModel = vm };

view.WhenAnyValue(x => x.ViewModel!.Property1)
.BindTo(view, x => x.SomeTextBox.Text);

vm.Property1 = "Baz";

Assert.Equal("Baz", view.SomeTextBox.Text);
}

[Fact]
public void BindToWithNonNullStartingValueToNullValue()
{
var vm = new PropertyBindViewModel();
var view = new PropertyBindView { ViewModel = vm };

vm.Property1 = "Baz";

view.WhenAnyValue(x => x.ViewModel!.Property1)
.BindTo(view, x => x.SomeTextBox.Text);

vm.Property1 = null;

Assert.True(string.IsNullOrEmpty(view.SomeTextBox.Text));
}

[Fact]
public void BindExpectsConverterFuncsToNotBeNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public IDisposable BindTo<TValue, TTarget, TTValue>(

if (converter == null)
{
defaultSetter?.Invoke(paramTarget, paramValue ?? throw new ArgumentNullException(nameof(paramValue)), paramParams);
defaultSetter?.Invoke(paramTarget, paramValue, paramParams);
return defaultGetter(paramTarget, paramParams);
}

Expand Down