Ejemplo n.º 1
0
 public virtual void BindingShouldBeRegisteredInBindingManager()
 {
     var target = new object();
     IBindingPath path = new BindingPath("test");
     var bindingManager = new BindingManager();
     DataBinding binding = CreateDataBinding(
         new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => target, Path = path } },
         new BindingSourceAccessorMock(), bindingManager);
     bindingManager.Register(target, path.Path, binding);
     bindingManager.GetBindings(target).Single().ShouldEqual(binding);
     bindingManager.GetBindings(target, path.Path).Single().ShouldEqual(binding);
 }
Ejemplo n.º 2
0
 public static IBindingPath Create([NotNull] string path)
 {
     lock (Cache)
     {
         IBindingPath value;
         if (!Cache.TryGetValue(path, out value))
         {
             value       = new BindingPath(path);
             Cache[path] = value;
         }
         return(value);
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
 public static IBindingPath Create([NotNull] string path, bool useCache = true)
 {
     if (!useCache)
     {
         return(new BindingPath(path));
     }
     lock (Cache)
     {
         IBindingPath value;
         if (!Cache.TryGetValue(path, out value))
         {
             value = new BindingPath(path);
             if (Cache.Count > 300)
             {
                 while (Cache.Count != 250)
                 {
                     Cache.Remove(Cache.FirstOrDefault().Key);
                 }
             }
             Cache[path] = value;
         }
         return(value);
     }
 }
 private static IBindingPath BindingPathFactoryImpl(string path)
 {
     lock (BindingPathCache)
     {
         IBindingPath value;
         if (!BindingPathCache.TryGetValue(path, out value))
         {
             value = new BindingPath(path);
             BindingPathCache[path] = value;
         }
         return value;
     }
 }
Ejemplo n.º 7
0
 public static IBindingPath Create([NotNull]string path, bool useCache = true)
 {
     if (!useCache)
         return new BindingPath(path);
     lock (Cache)
     {
         IBindingPath value;
         if (!Cache.TryGetValue(path, out value))
         {
             value = new BindingPath(path);
             if (Cache.Count > 300)
             {
                 while (Cache.Count != 250)
                     Cache.Remove(Cache.FirstOrDefault().Key);
             }
             Cache[path] = value;
         }
         return value;
     }
 }
Ejemplo n.º 8
0
 public virtual void BindingShouldRaiseExceptionEventWhenUpdateTargetThrowException()
 {
     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
     {
         Source = new ObserverMock
         {
             GetActualSource = b => new object(),
             Path = path,
             IsValid = b => true
         }
     };
     DataBinding binding = CreateDataBinding(target, source, bindingManager);
     target.SetValue = (func, context, arg3) => { throw new TestException(); };
     binding.BindingUpdated += (sender, args) =>
     {
         args.Action.ShouldEqual(BindingAction.UpdateTarget);
         args.Exception.InnerException.ShouldBeType<TestException>();
         isInvoked = true;
     };
     binding.UpdateTarget();
     isInvoked.ShouldBeTrue();
 }
Ejemplo n.º 9
0
 public virtual void BindingShouldUpdateTargetWithBindingContext()
 {
     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
     {
         Source = new ObserverMock
         {
             IsValid = b => true
         }
     };
     DataBinding binding = CreateDataBinding(target, source, bindingManager);
     target.SetValue = (func, context, arg3) =>
     {
         context.ShouldEqual(binding.Context);
         arg3.ShouldBeTrue();
         isInvoked = true;
         return true;
     };
     binding.UpdateTarget();
     isInvoked.ShouldBeTrue();
 }
Ejemplo n.º 10
0
        public virtual void BindingShouldCallAttachDetachMethodInBehavior()
        {
            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);

            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);
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        public virtual void BindingShouldRaiseEventWhenUpdateSourceFalse()
        {
            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);
            source.SetValue = (func, context, arg3) => false;
            binding.BindingUpdated += (sender, args) =>
            {
                args.Action.ShouldEqual(BindingAction.UpdateSource);
                args.Result.ShouldBeFalse();
                isInvoked = true;
            };
            binding.UpdateSource();
            isInvoked.ShouldBeTrue();
        }
Ejemplo n.º 14
0
 protected virtual IObserver CreateObserver(object source, string path, bool ignoreContext,
     IBindingMemberProvider memberProvider = null, IBindingContextManager contextManager = null, bool hasStablePath = false, bool observable = true, bool optional = false)
 {
     if (memberProvider != null)
         BindingServiceProvider.MemberProvider = memberProvider;
     if (contextManager != null)
         BindingServiceProvider.ContextManager = contextManager;
     var bindingPath = new BindingPath(path);
     if (bindingPath.IsEmpty)
         return new EmptyPathObserver(source, bindingPath);
     if (bindingPath.IsSingle)
         return new SinglePathObserver(source, bindingPath, ignoreContext, hasStablePath, observable, optional);
     return new MultiPathObserver(source, bindingPath, ignoreContext, hasStablePath, observable, optional);
 }