public void BindCommandMethodExCanPropertyAction() { var stubServiceProvider = MockServiceProvider.Instance; var bindCommand = new BindCommand(); var viewModel = new _TestBindCommand(); bindCommand.Source = viewModel; bindCommand.ExecuteMethodName = "ExecuteMethod"; bindCommand.CanExecuteMethodName = "CanExecuteMethod"; bindCommand.PropertyActionCanExecuteChanged = "PropertyActionCanExecuteChanged"; var bindResolve = bindCommand.ProvideValue(stubServiceProvider); var fakeTargetICommand = (ICommand)bindResolve; if (fakeTargetICommand != null) { fakeTargetICommand.Execute(null); } Assert.AreEqual(viewModel.ExecuteCalled, true, "Execute - bind was not resolved"); if (fakeTargetICommand != null) { fakeTargetICommand.CanExecute(null); } Assert.AreEqual(viewModel.CanExecuteCalled, true, "CanExecute - bind was not resolved"); if (fakeTargetICommand != null) { fakeTargetICommand.CanExecuteChanged += EventHandlerCanExecuteChanged; } _count = 0; // Execute notification viewModel.PropertyActionCanExecuteChanged(); Assert.AreEqual(_count, 1, "CanExecuteChanged - bind was not resolved"); }
public void BindCommandPropertyExCanEventToInvoke() { var stubServiceProvider = MockServiceProvider.Instance; var bindCommand = new BindCommand(); var viewModel = new _TestBindCommand(); bindCommand.Source = viewModel; bindCommand.ExecutePropertyName = "ExecutePropertyName"; bindCommand.CanExecutePropertyName = "CanExecutePropertyName"; bindCommand.EventToInvokeCanExecuteChanged = "EventToInvokeCanExecuteChanged"; var bindResolve = bindCommand.ProvideValue(stubServiceProvider); var fakeTargetICommand = (ICommand)bindResolve; if (fakeTargetICommand != null) { fakeTargetICommand.Execute(null); } Assert.Equal(viewModel.ExecuteCalled, true); if (fakeTargetICommand != null) { fakeTargetICommand.CanExecute(null); } Assert.Equal(viewModel.CanExecuteCalled, true); if (fakeTargetICommand != null) { fakeTargetICommand.CanExecuteChanged += EventHandlerCanExecuteChanged; } _count = 0; // Execute notification viewModel.ExecuteEventNotifyCanExecuteChanged(); Assert.Equal(_count, 1); }
public void ProvideValueFromSourceExceptions() { var stubServiceProvider = MockServiceProvider.Instance; var bindCommand = new BindCommand(); var viewModel = new _TestBindCommand(); bindCommand.Source = viewModel; bindCommand.ExecuteMethodName = "_ExecuteMethod"; bindCommand.CanExecuteMethodName = "CanExecuteMethod"; bindCommand.EventToInvokeCanExecuteChanged = "EventNotifyCanExecuteChanged"; bindCommand.PropertyActionCanExecuteChanged = "DelegateNotifyCanExecuteChanged"; UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider), "ProvideValueExceptions - expected exception - ArgumentException"); bindCommand.ExecuteMethodName = "ExecuteMethod"; bindCommand.CanExecuteMethodName = "_CanExecuteMethod"; bindCommand.EventToInvokeCanExecuteChanged = "EventNotifyCanExecuteChanged"; bindCommand.PropertyActionCanExecuteChanged = "DelegateNotifyCanExecuteChanged"; UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider), "ProvideValueExceptions - expected exception - ArgumentException"); bindCommand.ExecuteMethodName = "ExecuteMethod"; bindCommand.CanExecuteMethodName = "CanExecuteMethod"; bindCommand.EventToInvokeCanExecuteChanged = "_EventNotifyCanExecuteChanged"; bindCommand.PropertyActionCanExecuteChanged = "DelegateNotifyCanExecuteChanged"; UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider), "ProvideValueExceptions - expected exception - ArgumentException"); bindCommand.ExecuteMethodName = "ExecuteMethod"; bindCommand.CanExecuteMethodName = "CanExecuteMethod"; bindCommand.EventToInvokeCanExecuteChanged = "EventNotifyCanExecuteChanged"; bindCommand.PropertyActionCanExecuteChanged = "_DelegateNotifyCanExecuteChanged"; UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider), "ProvideValueExceptions - expected exception - ArgumentException"); }