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 ClickingTheControlExecutesTheCommand() { // Arrange var executedCount = 0; _command.ExecuteAction = vm => executedCount++; _binder.Control(_control).OnClick(_command); // Act _control.PerformClick(); _control.PerformClick(); // Assert Assert.That(executedCount, Is.EqualTo(2)); }
public void SimpleEvent(bool commandEnabled, bool binderActiveDuringEvent, bool expectUpdated) { // Arrange var executedCount = 0; _command.ExecuteAction = vm => executedCount++; _command.CanExecuteCondition = vm => commandEnabled; _binder.Control(_button).OnEvent("Click").Execute(_command); // Act if (!binderActiveDuringEvent) { _binder.Dispose(); } _button.PerformClick(); // Assert var expected = expectUpdated ? 1 : 0; Assert.That(executedCount, Is.EqualTo(expected)); }