public void SetValueShouldAutoConvertValueTypeConverterOnProperty() { var srcAccessor = new BindingSourceAccessorMock(); var sourceModel = new ConverterTestClass(); string propertyName = GetMemberPath <ConverterTestClass>(model => model.DoubleProperty); var valueAccessor = GetAccessor(sourceModel, propertyName, EmptyContext, true); srcAccessor.GetValue = (info, context, arg3) => { context.ShouldEqual(EmptyContext); return(double.MaxValue); }; valueAccessor.SetValue(srcAccessor, EmptyContext, true); sourceModel.DoubleProperty.ShouldNotBeNull(); sourceModel.DoubleProperty.Double.ShouldEqual(double.MaxValue); }
public void SetValueShouldAutoConvertValueFalse() { var srcAccessor = new BindingSourceAccessorMock(); var sourceModel = new BindingSourceModel(); string propertyName = GetMemberPath <BindingSourceModel>(model => model.IntProperty); var valueAccessor = GetAccessor(sourceModel, propertyName, EmptyContext, true); BindingServiceProvider.ValueConverter = null; srcAccessor.GetValue = (info, context, arg3) => { context.ShouldEqual(EmptyContext); return(int.MaxValue.ToString()); }; ShouldThrow <InvalidCastException>(() => valueAccessor.SetValue(srcAccessor, EmptyContext, true)); }
public virtual void BindingShouldCorrectInitializeProperties() { IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); binding.TargetAccessor.ShouldEqual(target); binding.SourceAccessor.ShouldEqual(source); binding.Behaviors.ShouldBeEmpty(); }
public void SetValueShouldUpdateIsEnabledProperty() { bool canExecute = false; var command = new RelayCommand(o => { }, o => canExecute, this); var srcAccessor = new BindingSourceAccessorMock(); var source = new BindingSourceModel(); var accessor = GetAccessor(source, BindingSourceModel.EventName, EmptyContext, false); srcAccessor.GetValue = (info, context, arg3) => command; accessor.SetValue(srcAccessor, EmptyContext, true); source.IsEnabled.ShouldBeFalse(); canExecute = true; command.RaiseCanExecuteChanged(); source.IsEnabled.ShouldBeTrue(); }
public void SetValueShouldUpdateValueInSourceNestedPropertyDoubleIndexer() { var srcAccessor = new BindingSourceAccessorMock(); var propertyName = GetMemberPath <BindingSourceModel>(model => model.NestedModel["test", 0]); var sourceModel = new BindingSourceModel { NestedModel = new BindingSourceNestedModel() }; var valueAccessor = GetAccessor(sourceModel, propertyName, EmptyContext, true); srcAccessor.GetValue = (info, context, arg3) => { context.ShouldEqual(EmptyContext); return(propertyName); }; valueAccessor.SetValue(srcAccessor, EmptyContext, true); sourceModel.NestedModel["test", 0].ShouldEqual(propertyName); }
public void SetValueShouldAutoConvertValueTrue() { var srcAccessor = new BindingSourceAccessorMock(); var sourceModel = new BindingSourceModel(); string propertyName = GetMemberPath <BindingSourceModel>(model => model.IntProperty); var valueAccessor = GetAccessor(sourceModel, propertyName, EmptyContext, true); valueAccessor.AutoConvertValue = true; srcAccessor.GetValue = (info, context, arg3) => { context.ShouldEqual(EmptyContext); return(int.MaxValue.ToString()); }; valueAccessor.SetValue(srcAccessor, EmptyContext, true); sourceModel.IntProperty.ShouldEqual(int.MaxValue); }
public virtual void BindingShouldAddSelfToDataContext() { IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var dataContext = binding.Context; dataContext.Count.ShouldEqual(1); dataContext.GetData(BindingConstants.Binding).ShouldEqual(binding); }
public void SetValueShouldUpdateIsEnabledPropertyOneTimeModeAfterDispose() { bool canExecute = false; var command = new RelayCommand(o => { }, o => canExecute, this); var srcAccessor = new BindingSourceAccessorMock(); var source = new BindingSourceModel(); var ctx = new DataContext(BindingBuilderConstants.Behaviors.ToValue(new List<IBindingBehavior> { new OneTimeBindingMode() })); var accessor = GetAccessor(source, BindingSourceModel.EventName, ctx, false); srcAccessor.GetValue = (info, context, arg3) => command; accessor.SetValue(srcAccessor, EmptyContext, true); accessor.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); source.IsEnabled.ShouldBeFalse(); canExecute = true; command.RaiseCanExecuteChanged(); source.IsEnabled.ShouldBeTrue(); }
public void ExecuteShouldCallCmdExecuteMethod() { var parameter = new object(); bool isInvoked = false; var command = new RelayCommand(o => { o.ShouldEqual(parameter); isInvoked = true; }); var srcAccessor = new BindingSourceAccessorMock(); var source = new BindingSourceModel(); var accessor = GetAccessor(source, BindingSourceModel.EventName, EmptyContext, false, d => parameter); srcAccessor.GetValue = (info, context, arg3) => command; accessor.SetValue(srcAccessor, EmptyContext, true); source.RaiseEvent(); isInvoked.ShouldBeTrue(); isInvoked = false; source.RaiseEvent(); isInvoked.ShouldBeTrue(); }
public virtual void BindingShouldNotAddSameBehavior() { IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; binding.Behaviors.Add(first); ShouldThrow(() => binding.Behaviors.Add(first)); }
public void AccessorShouldUseCommandParameterCanExecute() { bool isInvoked = false; var parameter = new object(); var command = new RelayCommand(o => { }, o => { o.ShouldEqual(parameter); isInvoked = true; return false; }, this); var srcAccessor = new BindingSourceAccessorMock(); var source = new BindingSourceModel(); var accessor = GetAccessor(source, BindingSourceModel.EventName, EmptyContext, false, d => parameter); srcAccessor.GetValue = (info, context, arg3) => command; accessor.SetValue(srcAccessor, EmptyContext, true); isInvoked.ShouldBeTrue(); isInvoked = false; command.RaiseCanExecuteChanged(); isInvoked.ShouldBeTrue(); }
public void AccessorShouldToggleEnabledFalse() { bool canExecute = false; bool isInvoked = false; var parameter = new object(); var command = new RelayCommand(o => { }, o => { o.ShouldEqual(parameter); isInvoked = true; return(canExecute); }, this); bool isEnabled = true; IAttachedBindingMemberInfo <object, bool> member = AttachedBindingMember.CreateMember <object, bool>(AttachedMemberConstants.Enabled, (info, o) => isEnabled, (info, o, v) => isEnabled = v); var memberProvider = new BindingMemberProvider(); memberProvider.Register(typeof(object), member, false); BindingServiceProvider.MemberProvider = memberProvider; var srcAccessor = new BindingSourceAccessorMock(); var source = new BindingSourceModel(); var accessor = GetAccessor(source, BindingSourceModel.EventName, new DataContext(BindingBuilderConstants.ToggleEnabledState.ToValue(false)), false, d => parameter); srcAccessor.GetValue = (info, context, arg3) => command; isEnabled.ShouldBeTrue(); accessor.SetValue(srcAccessor, EmptyContext, true); isInvoked.ShouldBeFalse(); isEnabled.ShouldBeTrue(); isInvoked = false; canExecute = true; command.RaiseCanExecuteChanged(); isInvoked.ShouldBeFalse(); isEnabled.ShouldBeTrue(); }
public virtual void BindingShouldNotAddBehaviorIfAttachReturnsFalse() { IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => false }; binding.Behaviors.Add(first); binding.Behaviors.Count.ShouldEqual(0); binding.Behaviors.Contains(first).ShouldBeFalse(); }
public virtual void BindingShouldThrowExceptionDuplicateIdBehavior() { IBindingPath path = BindingPath.Create("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new BindingSourceMock { GetSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; var second = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; binding.Behaviors.Add(first); ShouldThrow(() => binding.Behaviors.Add(second)); }
public virtual void BindingShouldRaiseExceptionEventWhenUpdateSourceThrowException() { bool isInvoked = false; IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path, IsValid = b => true } }; var source = new BindingSourceAccessorMock { Source = new ObserverMock { IsValid = b => true, GetActualSource = b => new object(), Path = path, } }; DataBinding binding = CreateDataBinding(target, source, bindingManager); source.SetValue = (func, context, arg3) => { throw new TestException(); }; binding.BindingUpdated += (sender, args) => { args.Action.ShouldEqual(BindingAction.UpdateSource); args.Exception.InnerException.ShouldBeType <TestException>(); isInvoked = true; }; binding.UpdateSource(); isInvoked.ShouldBeTrue(); }
public virtual void BindingShouldRaiseEventWhenUpdateTargetFalse() { bool isInvoked = false; IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); target.SetValue = (func, context, arg3) => false; binding.BindingUpdated += (sender, args) => { args.Action.ShouldEqual(BindingAction.UpdateTarget); args.Result.ShouldBeFalse(); isInvoked = true; }; binding.UpdateTarget(); isInvoked.ShouldBeTrue(); }