public void TwoWayBinding(bool binderActiveDuringEvent, bool expectUpdated) { // Arrange _binder.Control(_userControl).Property(c => c.Text).Bind(vm => vm.StringValue); if (!binderActiveDuringEvent) { _binder.Dispose(); } // Act & Assert _userControl.Text = "value #1"; var expected = expectUpdated ? _userControl.Text : null; Assert.That(_viewModel.StringValue, Is.EqualTo(expected)); _viewModel.StringValue = "value #2"; expected = expectUpdated ? _viewModel.StringValue : "value #1"; Assert.That(_userControl.Text, Is.EqualTo(expected)); }
public void ObserveControlAndSendToCommand(bool commandEnabled, bool binderActiveDuringEvent, bool expectUpdated) { // Arrange string mouseMoveButton = null; _command.ExecuteAction = parm => { mouseMoveButton = parm; }; _command.CanExecuteCondition = vm => commandEnabled; _binder.Observe(_button.MouseMoveButton).Execute(_command); // Act if (!binderActiveDuringEvent) { _binder.Dispose(); } _button.PerformMouseMove(new MouseEventArgs(MouseButtons.Right, 0, 0, 0, 0)); var expected = expectUpdated ? "Right" : null; // Assert Assert.That(mouseMoveButton, Is.EqualTo(expected)); }
public void ActionIsNotCalledAfterSourceIsDisposed() { // Arrange var callCount = 0; _binder.OnPropertyChanged(vm => vm.IntValue).Subscribe(x => callCount++); _binder.Dispose(); // Act _viewModel.IntValue = 3; // Assert Assert.That(callCount, Is.EqualTo(0)); }
public void TargetUpdatedWhenSourceChanges(bool binderActiveDuringEvent, bool expectUpdated) { // Arrange const string originalValue = "value #1"; const string updatedValue = "value #2"; _viewModel.StringValue = originalValue; _binder.Target(_textBox).Property(c => c.Text).Get(vm => vm.StringValue); var expected = originalValue; Assert.That(_textBox.Text, Is.EqualTo(expected), "Should immediately update target property to source value"); if (!binderActiveDuringEvent) { _binder.Dispose(); } // Act _viewModel.StringValue = updatedValue; // Assert expected = expectUpdated ? updatedValue : originalValue; Assert.That(_textBox.Text, Is.EqualTo(expected)); }
public void AfterEach() { _binder.Dispose(); _button.Dispose(); }