Exemplo n.º 1
0
        public void ObservesAdoptedObject()
        {
            var obj = new Body {
                LeftArm = new Arm {
                    Thumb = new Digit {
                        LengthMM = 50
                    }
                }
            };

            var path = PropertyPaths <Body> .Get <int>(t => t.LeftArm.Thumb.LengthMM).Single();

            var observer = new PropertyPathObserver <Body>(path, obj);

            obj.LeftArm.Thumb = new Digit();

            int changesObserved = 0;

            observer.Changed += (sender, e) =>
            {
                changesObserved++;
            };

            obj.LeftArm.Thumb.LengthMM = 51;

            Assert.Equal(1, changesObserved);
        }
Exemplo n.º 2
0
        public void InterpretsPropertyPathsCorrectly()
        {
            var paths = PropertyPaths <Outer> .Get <int>(o => o.Inner != null?o.Inner.Qty : 0);

            Assert.Equal(2, paths.Count);
            Assert.Contains("Inner", paths.Select(p => p.ToString()));
            Assert.Contains("Inner.Qty", paths.Select(p => p.ToString()));
        }
Exemplo n.º 3
0
        public void ReducesLikePaths()
        {
            var paths = PropertyPaths <Outer> .Get(o => o.Inner.Qty > 6 && o.Inner.Qty < 10);

            var reduced = PropertyPath.Reduce(paths);

            Assert.Equal(1, reduced.Count);
            Assert.Equal("Inner.Qty", reduced.Single().ToString());
        }
Exemplo n.º 4
0
        public void ObservesIntermediatePath()
        {
            var obj  = new Body();
            var path = PropertyPaths <Body> .Get <int>(t => t.LeftArm.Thumb.LengthMM).Single();

            var observer = new PropertyPathObserver <Body>(path, obj);

            int changesObserved = 0;

            observer.Changed += (sender, e) =>
            {
                changesObserved++;
            };

            obj.LeftArm = new Arm();

            Assert.Equal(1, changesObserved);
        }