예제 #1
0
        public void AddDependency_DependentPropertyOrField_Chains_NotSupported(
            Expression <Func <PathBuildingTestClass, int> > dependentPropertyExpression)
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            Assert.Throws <NotSupportedException>(() => map.AddDependency(dependentPropertyExpression, o => - 1, o => o.IntProperty));
        }
예제 #2
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);
        }
예제 #3
0
        public void AddDependency_NotSupportedPaths(Expression <Func <PathBuildingTestClass, object> > path)
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            Assert.Throws <NotSupportedException>(() =>
                                                  map.AddDependency(o => o.DependentProperty, o => - 1, path));
        }
예제 #4
0
        private static void SupportedPathsTestImpl(Expression <Func <PathBuildingTestClass, object> > path, string[] expectedParseResult)
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

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

            Assert.Equal(expectedParseResult, map.MapItems.Single().PathStrings);
        }
예제 #5
0
        public void AddDependency_PropertyChainWithCollectionItemOfCollectionItemAtTheBegginningAndPropertyInTheEnd_Supported()
        {
            var map = new DependenciesMap <PathBuildingCollectionTestClass <List <string> > >();

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

            Assert.Equal(new[] { "root", "CollectionItem", "CollectionItem", "Length" }, map.MapItems.Single().PathStrings);
        }
예제 #6
0
        public void AddDependency_ReadOnlyDependentPropertyOrField_NotSupported(
            Expression <Func <PathBuildingTestClass, int> > dependentPropertyExpression)
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            //Alexander Demchenko: Actually ArgumentException is raised by an internal method
            //of Expression.Assign implementation, so not by argument checks of AddDependency, but it's enough for now
            Assert.Throws <ArgumentException>(() => map.AddDependency(dependentPropertyExpression, o => - 1, o => o.IntProperty));
        }
예제 #7
0
        public void AddDependency_MoreThanOneDependencyOnAProperty_NotSupported()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            Assert.Throws <InvalidOperationException>(() =>
                                                      map.AddDependency(o => o.DependentProperty, o => - 1, o => o.IntProperty)
                                                      .AddDependency(o => o.DependentProperty, o => - 2, o => o.StringProperty)
                                                      );
        }
        public void NotifyPropertyCollectionTest()
        {
            var map = new DependenciesMap<Invoice>();
            map.AddDependency(i => i.TotalCost, i => 0, i => DependenciesTracking.CollectionExtensions.EachElement(i.Orders).Price,
                                                        i => DependenciesTracking.CollectionExtensions.EachElement(i.Orders).Quantity);

            foreach (var mapItem in map.MapItems)
                Debug.WriteLine(mapItem.ToString());
        }
예제 #9
0
        static PathBuildingTestClassWithPrivatePropertiesAndFields()
        {
            PropertiesDependenciesMap = new DependenciesMap <PathBuildingTestClassWithPrivatePropertiesAndFields>();
            PropertiesDependenciesMap.AddDependency(o => o._costProperty, o => o._priceProperty * o._quantityProperty, o => o._priceProperty,
                                                    o => o._quantityProperty);

            FieldsDependenciesMap = new DependenciesMap <PathBuildingTestClassWithPrivatePropertiesAndFields>();
            FieldsDependenciesMap.AddDependency(o => o._costField, o => o._priceField * o._quantityField, o => o._priceField,
                                                o => o._quantityField);
        }
예제 #10
0
        public void NotifyPropertyCollectionTest()
        {
            var map = new DependenciesMap <Invoice>();

            map.AddDependency(i => i.TotalCost, i => 0, i => DependenciesTracking.CollectionExtensions.EachElement(i.Orders).Price,
                              i => DependenciesTracking.CollectionExtensions.EachElement(i.Orders).Quantity);

            foreach (var mapItem in map.MapItems)
            {
                Debug.WriteLine(mapItem.ToString());
            }
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
        public void AddDependency_CollectionElementAtTheBeginningOfThePathPropertyGetter_Success()
        {
            var map = new DependenciesMap <PathBuildingCollectionTestClass <string> >();

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

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

            var collectionItemPathItem = map.MapItems.Single().Ancestor;

            Assert.IsType <CollectionPathItem <PathBuildingCollectionTestClass <string> > >(collectionItemPathItem);
            var lengthPathItem = (PropertyPathItem <PathBuildingCollectionTestClass <string> >)collectionItemPathItem.Ancestor;

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

            var actualStringLength = lengthPathItem.PropertyOrFieldGetter(obj);

            Assert.Equal(expectedStringLength, actualStringLength);
        }
예제 #14
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));
        }
예제 #15
0
        public void AddDependency_DependentPropertyOrField_ExtensionMethodCalls_NotSupported()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            Assert.Throws <NotSupportedException>(() => map.AddDependency(o => o.DependentProperty.ExtensionCall(), o => "-1", o => o.IntProperty));
        }
예제 #16
0
        public void AddDependency_DependentPropertyOrField_Conversions_NotSupported_2()
        {
            var map = new DependenciesMap <PathBuildingTestClass>();

            Assert.Throws <NotSupportedException>(() => map.AddDependency(o => (int)o.ObjectDependentProperty, o => - 1, o => o.IntProperty));
        }