public void When_invoked_then_method_is_called()
 {
     var vm = new MockViewModelWithAction();
     var invoker = new ExpressionInvoker<string>(p => vm.Action(p));
     invoker.Invoke("Foo");
     Assert.IsTrue(vm.ActionCalled);
 }
Ejemplo n.º 2
0
 public void Source_Is_Disabled_When_Target_Command_Gets_Disabled_After_Initialization_With_Expression()
 {
     var source = new MockEventSource();
     var target = new MockViewModelWithAction() { IsActionEnabled = true };
     var binder = new MethodBinder<MockEventArgs>(source, "MockEvent", e => target.Action(), p => target.IsActionEnabled,target);
     binder.Bind();
     target.IsActionEnabled = false;
     Assert.IsFalse(source.IsEnabled);
 }
Ejemplo n.º 3
0
        public void MethodBinder_Doesnt_Support_Parameters_On_Actions()
        {
            var target = new MockViewModelWithAction();

            AssertExt.ExpectException<NotSupportedException>(() =>
            {
                var binder = new MethodBinder<MockEventArgs>(new UserControl(), "MockEvent", e => target.Action("will fail"));
            });
        }
Ejemplo n.º 4
0
        public void When_method_binder_is_added_then_it_can_be_retrieved_by_its_event()
        {
            var button = new Button();
            var view = new UserControl();
            var vm = new MockViewModelWithAction();
            var buttonBinder = new MethodBinder<RoutedEventArgs>(button, "Click", p => vm.Action());
            var viewModelBinder = new ViewBinder<object>(view, vm);
            viewModelBinder.Add(buttonBinder);

            var binder = viewModelBinder.GetMethodBinder(button, "Click");
            Assert.AreEqual(buttonBinder, binder);
        }
 public void When_two_identical_method_actions_are_compared_then_they_match()
 {
     var vm = new MockViewModelWithAction();
     Expression<Action<RoutedEventArgs>> action1 = p => vm.Action();
     Expression<Action<RoutedEventArgs>> action2 = p => vm.Action();
     Assert.IsTrue(action1.ExpressionEquals(action2));
 }
 public void When_two_different_method_actions_are_compared_then_they_do_not_match()
 {
     var vm = new MockViewModelWithAction();
     Expression<Action<RoutedEventArgs>> action1 = p => vm.Action();
     Expression<Action<RoutedEventArgs>> action2 = p => DummyAction();
     Assert.IsFalse(action1.ExpressionEquals(action2));
 }