示例#1
0
        public void AddDependency_CollectionElementOfPropertyPropertyGetter_Success()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            map.AddDependency(o => o.DependentProperty, o => - 1, o => DependenciesTracking.CollectionExtensions.EachElement(o.Strings).Length);

            var rootPathItem = map.MapItems.Single();

            Assert.Equal("root", rootPathItem.PathStrings.First());

            var stringsPathItem = (PropertyPathItem <PathBuildingTestClass>)rootPathItem.Ancestor;

            Assert.Equal("Strings", stringsPathItem.PropertyOrFieldName);

            var stringsCollectionItem = (CollectionPathItem <PathBuildingTestClass>)stringsPathItem.Ancestor;

            var lengthPathItem = (PropertyPathItem <PathBuildingTestClass>)stringsCollectionItem.Ancestor;

            Assert.Equal("Length", lengthPathItem.PathStrings.Single());

            var rootObject           = new PathBuildingTestClass();
            var expectedStringsValue = new List <string>();

            rootObject.Strings = expectedStringsValue;

            Assert.Equal(expectedStringsValue, stringsPathItem.PropertyOrFieldGetter(rootObject));

            var expectedStringLength = new Random().Next(1, 10);
            var obj = new string('a', expectedStringLength);

            var actualStringLength = lengthPathItem.PropertyOrFieldGetter(obj);

            Assert.Equal(expectedStringLength, actualStringLength);
        }
示例#2
0
        public void AddDependency_OneLevelValTypeFieldGetter_Success()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            map.AddDependency(o => o.DependentProperty, o => - 1, o => o.StringField);

            var obj = new PathBuildingTestClass();
            var stringFieldExpectedValue = Guid.NewGuid().ToString();

            obj.StringField = stringFieldExpectedValue;
            var stringFieldPathItem = (PropertyPathItem <PathBuildingTestClass>)map.MapItems.Single().Ancestor;

            Assert.Equal("StringField", stringFieldPathItem.PathStrings.Single());

            var getResult = stringFieldPathItem.PropertyOrFieldGetter(obj);

            Assert.Equal(stringFieldExpectedValue, getResult);
        }
示例#3
0
        public void AddDependency_OneLevelRefTypeFieldGetter_Success()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            map.AddDependency(o => o.DependentProperty, o => - 1, o => o.IntField);

            var obj = new PathBuildingTestClass();
            var intFieldExpectedValue = new Random().Next(100, 200);

            obj.IntField = intFieldExpectedValue;
            var intFieldMapItem = (PropertyPathItem <PathBuildingTestClass>)map.MapItems.Single().Ancestor;

            Assert.Equal("IntField", intFieldMapItem.PathStrings.Single());

            var getResult = intFieldMapItem.PropertyOrFieldGetter(obj);

            Assert.Equal(intFieldExpectedValue, getResult);
        }
示例#4
0
        public void AddDependency_SecondLevelPropertyGetter_Success()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            map.AddDependency(o => o.DependentProperty, o => - 1, o => o.InnerProperty.IntProperty);

            var obj = new PathBuildingTestClass();

            var expectedInnerPropertyValue = new PathBuildingInnerTestClass();
            var expectedIntPropertyValue   = new Random().Next(100, 200);

            obj.InnerProperty = expectedInnerPropertyValue;
            expectedInnerPropertyValue.IntProperty = expectedIntPropertyValue;

            var innerPropertyMapItem = (PropertyPathItem <PathBuildingTestClass>)map.MapItems.Single().Ancestor;
            var intPropertyMapItem   = (PropertyPathItem <PathBuildingTestClass>)innerPropertyMapItem.Ancestor;

            Assert.Equal(expectedInnerPropertyValue, innerPropertyMapItem.PropertyOrFieldGetter(obj));
            Assert.Equal(expectedIntPropertyValue, intPropertyMapItem.PropertyOrFieldGetter(expectedInnerPropertyValue));
        }