From f64969ba404bf4985598c7d59d39f119c72156f6 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Tue, 24 Aug 2021 23:14:00 +0100 Subject: [PATCH 1/2] fix BindCommand Tests BindCommand with parameter incorrectly coded OLD Assert.Equal(0, received); NEW Assert.Equal(13, received); --- .../CommandBindingImplementationTests.cs | 109 +++++++++--------- src/global.json | 5 + 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/ReactiveUI.Tests/Platforms/windows-xaml/CommandBindingImplementationTests.cs b/src/ReactiveUI.Tests/Platforms/windows-xaml/CommandBindingImplementationTests.cs index 8795b98513..ffbc8552ea 100644 --- a/src/ReactiveUI.Tests/Platforms/windows-xaml/CommandBindingImplementationTests.cs +++ b/src/ReactiveUI.Tests/Platforms/windows-xaml/CommandBindingImplementationTests.cs @@ -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(_ => { }); - vm.Command1 = newCmd; + view.ViewModel.Command1 = newCmd; Assert.Equal(newCmd, view.Command1.Command); disp.Dispose(); @@ -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); } /// @@ -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(true); - vm.Command1 = ReactiveCommand.Create(_ => { }, canExecute1); + view.ViewModel.Command1 = ReactiveCommand.Create(_ => { }, 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); } @@ -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(true); - vm.Command1 = ReactiveCommand.Create(_ => { }, canExecute1); + view.ViewModel.Command1 = ReactiveCommand.Create(_ => { }, 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); @@ -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(false); - vm.Command1 = ReactiveCommand.Create(_ => { }, canExecute1); + view.ViewModel.Command1 = ReactiveCommand.Create(_ => { }, 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); } @@ -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(true); - vm.Command1 = ReactiveCommand.Create(_ => { }, canExecute1); + view.ViewModel.Command1 = ReactiveCommand.Create(_ => { }, 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(false); - vm.Command1 = ReactiveCommand.Create(_ => { }, canExecute2); + view.ViewModel.Command1 = ReactiveCommand.Create(_ => { }, canExecute2); Assert.False(view.Command1.IsEnabled); } @@ -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(i => { received = i; }); - vm.Command1 = cmd; + view.ViewModel.Command1 = ReactiveCommand.Create(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); } @@ -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(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(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); } @@ -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(i => { received = i; }); - vm.Command1 = cmd; + var cmd = ReactiveCommand.Create(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); } /// @@ -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(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); diff --git a/src/global.json b/src/global.json index 400471d455..c690ed8efb 100644 --- a/src/global.json +++ b/src/global.json @@ -1,4 +1,9 @@ { + "sdk": { + "version": "6.0", + "rollForward": "latestMinor", + "allowPrerelease": true + }, "msbuild-sdks": { "MSBuild.Sdk.Extras": "3.0.23" } From 056e9122b49c4fe1e2a06f484fce0535a12086cb Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Wed, 25 Aug 2021 01:08:29 +0100 Subject: [PATCH 2/2] Update PocoObservableForPropertyTests.cs --- .../Resolvers/PocoObservableForPropertyTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ReactiveUI.Tests/Resolvers/PocoObservableForPropertyTests.cs b/src/ReactiveUI.Tests/Resolvers/PocoObservableForPropertyTests.cs index 44e0b2487e..35fa9bed75 100644 --- a/src/ReactiveUI.Tests/Resolvers/PocoObservableForPropertyTests.cs +++ b/src/ReactiveUI.Tests/Resolvers/PocoObservableForPropertyTests.cs @@ -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)); @@ -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) { @@ -76,6 +79,7 @@ public void NotificationPocoErrorOnBind() [Fact] public void NotificationPocoSuppressErrorOnBind() { + RxApp.EnsureInitialized(); using (var testLoggerRegistration = new TestLoggerRegistration()) { var instance = new POCOObservableForProperty();