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); }
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())); }
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()); }
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); }