Ejemplo n.º 1
0
        private BindingFlags GetPropertyBindings(PropertyComparison propertyComparison)
        {
            var flags = BindingFlags.Instance | BindingFlags.Public;

            if (propertyComparison.HasFlag(PropertyComparison.IncludeStatic))
            {
                flags |= BindingFlags.Static;
            }
            if (propertyComparison.HasFlag(PropertyComparison.IncludeNonPublic))
            {
                flags |= BindingFlags.NonPublic;
            }

            return(flags);
        }
Ejemplo n.º 2
0
        public IEnumerable <PropertyInfo> GetPropertyInfos(Type type, PropertyComparison propertyComparison)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (_propertyCache.TryGetValue(type, out var propertyInfos))
            {
                return(propertyInfos);
            }

            var bindingFlags = GetPropertyBindings(propertyComparison);

            propertyInfos = type.GetProperties(bindingFlags);

            _propertyCache[type] = propertyInfos;

            return(propertyInfos);
        }
Ejemplo n.º 3
0
        private static IEnumerable <TypePromotionTestCase> ComputeRelationalTestCases()
        {
            var cases = new PropertyComparison[]
            {
                new PropertyComparison {
                    First = stringPropertyDescriptor, Second = stringPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetString(true)
                },
                new PropertyComparison {
                    First = binaryPropertyDescriptor, Second = binaryPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetBinary(true)
                },
                new PropertyComparison {
                    First = boolPropertyDescriptor, Second = boolPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetBoolean(false)
                },
                new PropertyComparison {
                    First = guidPropertyDescriptor, Second = guidPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetGuid(false)
                },
            };

            // same primitive type for both operands
            return(ComputeArithmeticTestCases()
                   .Concat(cases.SelectMany(c => ComputeBinaryTestCases(c.First, c.Second, c.PromotedType))));
        }
Ejemplo n.º 4
0
        private static IEnumerable<TypePromotionTestCase> ComputeRelationalTestCases()
        {
            var cases = new PropertyComparison[]
                {
                    new PropertyComparison { First = stringPropertyDescriptor, Second = stringPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetString(true) },
                    new PropertyComparison { First = binaryPropertyDescriptor, Second = binaryPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetBinary(true) },
                    new PropertyComparison { First = boolPropertyDescriptor, Second = boolPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetBoolean(false) },
                    new PropertyComparison { First = guidPropertyDescriptor, Second = guidPropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetGuid(false) },
                };

            // same primitive type for both operands
            return ComputeArithmeticTestCases()
                .Concat(cases.SelectMany(c => ComputeBinaryTestCases(c.First, c.Second, c.PromotedType)));
        }
Ejemplo n.º 5
0
        private static IEnumerable<TypePromotionTestCase> ComputeArithmeticTestCases()
        {
            var cases = new PropertyComparison[]
                {
                    // same primitive type for both operands
                    new PropertyComparison { First = bytePropertyDescriptor, Second = bytePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = decimalPropertyDescriptor, Second = decimalPropertyDescriptor,  PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false) },
                    new PropertyComparison { First = doublePropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                    new PropertyComparison { First = int16PropertyDescriptor, Second = int16PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = int32PropertyDescriptor, Second = int32PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = int64PropertyDescriptor, Second = int64PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt64(false) },
                    new PropertyComparison { First = sbytePropertyDescriptor, Second = sbytePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = singlePropertyDescriptor, Second = singlePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetSingle(false) },

                    // different primitive types for the two operands
                    new PropertyComparison { First = decimalPropertyDescriptor, Second = bytePropertyDescriptor,  PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false) },
                    new PropertyComparison { First = decimalPropertyDescriptor, Second = int16PropertyDescriptor,  PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false) },
                    new PropertyComparison { First = decimalPropertyDescriptor, Second = int32PropertyDescriptor,  PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false) },
                    new PropertyComparison { First = decimalPropertyDescriptor, Second = int64PropertyDescriptor,  PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false) },
                    new PropertyComparison { First = bytePropertyDescriptor, Second = int16PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = sbytePropertyDescriptor, Second = int16PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = bytePropertyDescriptor, Second = int32PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = sbytePropertyDescriptor, Second = int32PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = int16PropertyDescriptor, Second = int32PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt32(false) },
                    new PropertyComparison { First = bytePropertyDescriptor, Second = int64PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt64(false) },
                    new PropertyComparison { First = sbytePropertyDescriptor, Second = int64PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt64(false) },
                    new PropertyComparison { First = int16PropertyDescriptor, Second = int64PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt64(false) },
                    new PropertyComparison { First = int32PropertyDescriptor, Second = int64PropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetInt64(false) },
                    new PropertyComparison { First = bytePropertyDescriptor, Second = singlePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetSingle(false) },
                    new PropertyComparison { First = sbytePropertyDescriptor, Second = singlePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetSingle(false) },
                    new PropertyComparison { First = int16PropertyDescriptor, Second = singlePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetSingle(false) },
                    new PropertyComparison { First = int32PropertyDescriptor, Second = singlePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetSingle(false) },
                    new PropertyComparison { First = int64PropertyDescriptor, Second = singlePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetSingle(false) },
                    new PropertyComparison { First = bytePropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                    new PropertyComparison { First = sbytePropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                    new PropertyComparison { First = int16PropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                    new PropertyComparison { First = int32PropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                    new PropertyComparison { First = int64PropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                    new PropertyComparison { First = singlePropertyDescriptor, Second = doublePropertyDescriptor,  PromotedType = EdmCoreModel.Instance.GetDouble(false) },
                };

            return cases.SelectMany(c => ComputeBinaryTestCases(c.First, c.Second, c.PromotedType));
        }
Ejemplo n.º 6
0
        public void GetPropertyInfos_PropertyComparisons_ReturnsSpecifiedPropertyInfos(PropertyComparison rule, int expectedPropertyCount)
        {
            // Arrange
            var cache = CreateCache();

            // Act
            var propertyInfos = cache.GetPropertyInfos(typeof(PropertyCacheTestClass), rule);

            // Assert
            Assert.Equal(expectedPropertyCount, propertyInfos.Count());
        }
Ejemplo n.º 7
0
        private static IEnumerable <TypePromotionTestCase> ComputeArithmeticTestCases()
        {
            var cases = new PropertyComparison[]
            {
                // same primitive type for both operands
                new PropertyComparison {
                    First = bytePropertyDescriptor, Second = bytePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = decimalPropertyDescriptor, Second = decimalPropertyDescriptor, PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false)
                },
                new PropertyComparison {
                    First = doublePropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
                new PropertyComparison {
                    First = int16PropertyDescriptor, Second = int16PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = int32PropertyDescriptor, Second = int32PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = int64PropertyDescriptor, Second = int64PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt64(false)
                },
                new PropertyComparison {
                    First = sbytePropertyDescriptor, Second = sbytePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = singlePropertyDescriptor, Second = singlePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetSingle(false)
                },

                // different primitive types for the two operands
                new PropertyComparison {
                    First = decimalPropertyDescriptor, Second = bytePropertyDescriptor, PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false)
                },
                new PropertyComparison {
                    First = decimalPropertyDescriptor, Second = int16PropertyDescriptor, PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false)
                },
                new PropertyComparison {
                    First = decimalPropertyDescriptor, Second = int32PropertyDescriptor, PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false)
                },
                new PropertyComparison {
                    First = decimalPropertyDescriptor, Second = int64PropertyDescriptor, PromotedType = (IEdmPrimitiveTypeReference)EdmCoreModel.Instance.GetDecimal(false)
                },
                new PropertyComparison {
                    First = bytePropertyDescriptor, Second = int16PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = sbytePropertyDescriptor, Second = int16PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = bytePropertyDescriptor, Second = int32PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = sbytePropertyDescriptor, Second = int32PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = int16PropertyDescriptor, Second = int32PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt32(false)
                },
                new PropertyComparison {
                    First = bytePropertyDescriptor, Second = int64PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt64(false)
                },
                new PropertyComparison {
                    First = sbytePropertyDescriptor, Second = int64PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt64(false)
                },
                new PropertyComparison {
                    First = int16PropertyDescriptor, Second = int64PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt64(false)
                },
                new PropertyComparison {
                    First = int32PropertyDescriptor, Second = int64PropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetInt64(false)
                },
                new PropertyComparison {
                    First = bytePropertyDescriptor, Second = singlePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetSingle(false)
                },
                new PropertyComparison {
                    First = sbytePropertyDescriptor, Second = singlePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetSingle(false)
                },
                new PropertyComparison {
                    First = int16PropertyDescriptor, Second = singlePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetSingle(false)
                },
                new PropertyComparison {
                    First = int32PropertyDescriptor, Second = singlePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetSingle(false)
                },
                new PropertyComparison {
                    First = int64PropertyDescriptor, Second = singlePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetSingle(false)
                },
                new PropertyComparison {
                    First = bytePropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
                new PropertyComparison {
                    First = sbytePropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
                new PropertyComparison {
                    First = int16PropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
                new PropertyComparison {
                    First = int32PropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
                new PropertyComparison {
                    First = int64PropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
                new PropertyComparison {
                    First = singlePropertyDescriptor, Second = doublePropertyDescriptor, PromotedType = EdmCoreModel.Instance.GetDouble(false)
                },
            };

            return(cases.SelectMany(c => ComputeBinaryTestCases(c.First, c.Second, c.PromotedType)));
        }