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 @@ -30,16 +30,15 @@ public class CommandBindingImplementationTests
[Fact]
public void CommandBindByNameWireup()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

Assert.Null(view.Command1.Command);

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);
Assert.Equal(vm.Command1, view.Command1.Command);
var disp = view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1);
Assert.Equal(view.ViewModel.Command1, view.Command1.Command);

var newCmd = ReactiveCommand.Create<int>(_ => { });
vm.Command1 = newCmd;
view.ViewModel.Command1 = newCmd;
Assert.Equal(newCmd, view.Command1.Command);

disp.Dispose();
Expand All @@ -54,14 +53,14 @@ public void CommandBindNestedCommandWireup()
{
var vm = new CommandBindViewModel
{
NestedViewModel = new FakeNestedViewModel()
NestedViewModel = new()
};

var view = new CommandBindView { ViewModel = vm };

view.BindCommand(vm, m => m.NestedViewModel.NestedCommand, x => x.Command1);
view.BindCommand(view.ViewModel, m => m.NestedViewModel.NestedCommand, x => x.Command1);

Assert.Equal(vm.NestedViewModel.NestedCommand, view.Command1.Command);
Assert.Equal(view.ViewModel.NestedViewModel.NestedCommand, view.Command1.Command);
}

/// <summary>
Expand All @@ -70,13 +69,12 @@ public void CommandBindNestedCommandWireup()
[Fact]
public void CommandBindSetsInitialEnabledState_True()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

var canExecute1 = new BehaviorSubject<bool>(true);
vm.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
view.ViewModel.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);

view.BindCommand(vm, x => x.Command1, x => x.Command1);
view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1);

Assert.True(view.Command1.IsEnabled);
}
Expand All @@ -87,13 +85,12 @@ public void CommandBindSetsInitialEnabledState_True()
[Fact]
public void CommandBindSetsDisablesCommandWhenCanExecuteChanged()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

var canExecute1 = new BehaviorSubject<bool>(true);
vm.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
view.ViewModel.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);

view.BindCommand(vm, x => x.Command1, x => x.Command1);
view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1);

Assert.True(view.Command1.IsEnabled);

Expand All @@ -108,13 +105,12 @@ public void CommandBindSetsDisablesCommandWhenCanExecuteChanged()
[Fact]
public void CommandBindSetsInitialEnabledState_False()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

var canExecute1 = new BehaviorSubject<bool>(false);
vm.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
view.ViewModel.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);

view.BindCommand(vm, x => x.Command1, x => x.Command1);
view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1);

Assert.False(view.Command1.IsEnabled);
}
Expand All @@ -125,19 +121,18 @@ public void CommandBindSetsInitialEnabledState_False()
[Fact]
public void CommandBindRaisesCanExecuteChangedOnBind()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

var canExecute1 = new BehaviorSubject<bool>(true);
vm.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
view.ViewModel.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);

view.BindCommand(vm, x => x.Command1, x => x.Command1);
view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1);

Assert.True(view.Command1.IsEnabled);

// Now change to a disabled cmd
var canExecute2 = new BehaviorSubject<bool>(false);
vm.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute2);
view.ViewModel.Command1 = ReactiveCommand.Create<int>(_ => { }, canExecute2);

Assert.False(view.Command1.IsEnabled);
}
Expand All @@ -148,20 +143,18 @@ public void CommandBindRaisesCanExecuteChangedOnBind()
[Fact]
public void CommandBindWithParameterExpression()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

var received = 0;
var cmd = ReactiveCommand.Create<int>(i => { received = i; });
vm.Command1 = cmd;
view.ViewModel.Command1 = ReactiveCommand.Create<int>(i => received = i);

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick));
var disp = view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick));

vm.Value = 42;
view.ViewModel.Value = 42;
view.Command1.RaiseCustomClick();
Assert.Equal(42, received);

vm.Value = 13;
view.ViewModel.Value = 13;
view.Command1.RaiseCustomClick();
Assert.Equal(13, received);
}
Expand All @@ -172,22 +165,21 @@ public void CommandBindWithParameterExpression()
[Fact]
public void CommandBindWithDelaySetVMParameterExpression()
{
var vm = new CommandBindViewModel();
var view = new ReactiveObjectCommandBindView();
var view = new ReactiveObjectCommandBindView
{
ViewModel = new()
};

var received = 0;
var cmd = ReactiveCommand.Create<int>(i => { received = i; });
vm.Command1 = cmd;

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick));
view.ViewModel.Command1 = ReactiveCommand.Create<int>(i => received = i);

view.ViewModel = vm;
var disp = view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick));

vm.Value = 42;
view.ViewModel.Value = 42;
view.Command1.RaiseCustomClick();
Assert.Equal(42, received);

vm.Value = 13;
view.ViewModel.Value = 13;
view.Command1.RaiseCustomClick();
Assert.Equal(13, received);
}
Expand All @@ -198,24 +190,25 @@ public void CommandBindWithDelaySetVMParameterExpression()
[Fact]
public void CommandBindWithDelaySetVMParameterNoINPCExpression()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView();
var view = new CommandBindView { ViewModel = new() };

var received = 0;
var cmd = ReactiveCommand.Create<int>(i => { received = i; });
vm.Command1 = cmd;
var cmd = ReactiveCommand.Create<int>(i => received = i);
view.ViewModel.Command1 = cmd;
view.ViewModel.Value = 10;

view.BindCommand(vm, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick));
view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick));

view.ViewModel = vm;
view.Command1.RaiseCustomClick();
Assert.Equal(10, received);

vm.Value = 42;
view.ViewModel.Value = 42;
view.Command1.RaiseCustomClick();
Assert.Equal(0, received);
Assert.Equal(42, received);

vm.Value = 13;
view.ViewModel.Value = 13;
view.Command1.RaiseCustomClick();
Assert.Equal(0, received);
Assert.Equal(13, received);
}

/// <summary>
Expand All @@ -224,17 +217,19 @@ public void CommandBindWithDelaySetVMParameterNoINPCExpression()
[Fact]
public void CommandBindWithParameterObservable()
{
var vm = new CommandBindViewModel();
var view = new CommandBindView { ViewModel = vm };
var view = new CommandBindView { ViewModel = new() };

var received = 0;
var cmd = ReactiveCommand.Create<int>(i => { received = i; });
vm.Command1 = cmd;
view.ViewModel.Command1 = cmd;
view.ViewModel.Value = 10;
var value = view.ViewModel.WhenAnyValue(v => v.Value);
var disp = view.BindCommand(view.ViewModel, x => x.Command1, x => x.Command1, value, nameof(CustomClickButton.CustomClick));

var value = Observable.Return(42);
var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1, value, nameof(CustomClickButton.CustomClick));
view.Command1.RaiseCustomClick();
Assert.Equal(10, received);

vm.Value = 42;
view.ViewModel.Value = 42;
view.Command1.RaiseCustomClick();

Assert.Equal(42, received);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PocoObservableForPropertyTests
[Fact]
public void CheckGetAffinityForObjectValues()
{
RxApp.EnsureInitialized();
var instance = new POCOObservableForProperty();

Assert.Equal(1, instance.GetAffinityForObject(typeof(PocoType), null!, false));
Expand All @@ -30,6 +31,8 @@ public void CheckGetAffinityForObjectValues()
[Fact]
public void NotificationPocoErrorOnBind()
{
RxApp.EnsureInitialized();

// Use same logger, when the test is executed multiple times in the same AndroidRunner/AppDomain/AssemblyLoadContext
if (_testLoggerForNotificationPocoErrorOnBind is null)
{
Expand Down Expand Up @@ -76,6 +79,7 @@ public void NotificationPocoErrorOnBind()
[Fact]
public void NotificationPocoSuppressErrorOnBind()
{
RxApp.EnsureInitialized();
using (var testLoggerRegistration = new TestLoggerRegistration())
{
var instance = new POCOObservableForProperty();
Expand Down
5 changes: 5 additions & 0 deletions src/global.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"sdk": {
"version": "6.0",
"rollForward": "latestMinor",
"allowPrerelease": true
},
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "3.0.23"
}
Expand Down