public virtual void BindingShouldNotAddBehaviorIfAttachReturnsFalse() { 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 => false }; binding.Behaviors.Add(first); binding.Behaviors.Count.ShouldEqual(0); binding.Behaviors.Contains(first).ShouldBeFalse(); }
public virtual void BindingShouldCallAttachDetachMethodInBehavior() { 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); int countAttach = 0; int countDetach = 0; var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => { countAttach++; return true; }, Detach = binding1 => countDetach++ }; binding.Behaviors.Add(first); countAttach.ShouldEqual(1); countDetach.ShouldEqual(0); binding.Behaviors.Remove(first); countAttach.ShouldEqual(1); countDetach.ShouldEqual(1); }
public virtual void BindingShouldNotAddSameBehavior() { 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 }; binding.Behaviors.Add(first); ShouldThrow(() => binding.Behaviors.Add(first)); }
public void BuilderShouldUseCustomBehavior() { var mock = new BindingBehaviorMock(); var builder = new BindingBuilder(); builder.Bind(new object(), "test").To("test").WithBehavior(mock); builder.GetData(BindingBuilderConstants.Behaviors).Single().ShouldEqual(mock); }
public void ResolverShouldUnregisterBehavior() { const string name = "name"; var source = new BindingBehaviorMock(); var resolver = CreateBindingResourceResolver(); resolver.AddBehavior(name, (context, list) => source, true); resolver.ResolveBehavior(name, EmptyContext, Empty.Array<string>(), true).ShouldEqual(source); resolver.RemoveBehavior(name).ShouldBeTrue(); resolver.ResolveBehavior(name, EmptyContext, Empty.Array<string>(), false).ShouldBeNull(); }
public void ResolverShouldRegisterAndResolveBehavior() { const string name = "name"; var source = new BindingBehaviorMock(); var resolver = CreateBindingResourceResolver(); resolver.ResolveBehavior(name, EmptyContext, Empty.Array<string>(), false).ShouldBeNull(); resolver.AddBehavior(name, (context, list) => { context.ShouldEqual(EmptyContext); list.ShouldEqual(Empty.Array<string>()); return source; }, true); resolver.ResolveBehavior(name, EmptyContext, Empty.Array<string>(), true).ShouldEqual(source); }
public virtual void BindingShouldThrowExceptionDuplicateIdBehavior() { 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 }; var second = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; binding.Behaviors.Add(first); ShouldThrow(() => binding.Behaviors.Add(second)); }