Пример #1
0
        public void LambdaExpressionAccessesNotProperty_ThrowException()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr = (d, p) => d.ForeignKey1 == p.Field;

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => PropertyPairSelectorVisitor.GetSelectedProperty(expr),
                                                               string.Format("Member '{0}.Field' is not a property.", typeof(Principal).FullName));
        }
Пример #2
0
        public void UnsupportedExpressionNodeType_ThrowException()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr = (d, p) => d.ForeignKey1 > p.PrincipalKey1;

            // Act & Assert
            ExceptionAssert.Throws <NotSupportedException>(() => PropertyPairSelectorVisitor.GetSelectedProperty(expr),
                                                           "Unsupported Expression NodeType 'GreaterThan'.");
        }
Пример #3
0
        public void LambdaExpressionHasNotTwoParameters_ThrowException()
        {
            // Arrange
            Expression <Func <Dependent, int> > expr = d => d.ForeignKey1;

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => PropertyPairSelectorVisitor.GetSelectedProperty(expr),
                                                               SRResources.LambdaExpressionMustHaveExactlyTwoParameters);
        }
Пример #4
0
        public void MemberExpressionNotBoundToParameter_ThrowException()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr =
                (d, p) => new Dependent().ForeignKey1 == new Principal().PrincipalKey1;

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => PropertyPairSelectorVisitor.GetSelectedProperty(expr),
                                                               "MemberExpressions must be bound to the LambdaExpression parameter.");
        }
Пример #5
0
        public void CanWork_WithNullValue()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr = null;

            // Act
            IDictionary <PropertyInfo, PropertyInfo> properties =
                PropertyPairSelectorVisitor.GetSelectedProperty(expr);

            // Assert
            Assert.Equal(0, properties.Count);
        }
Пример #6
0
        public void MemberExpressionTypeNotMatch_ThrowException()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr =
                (d, p) => d.ForeignKey4 == p.PrincipalKey1;

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => PropertyPairSelectorVisitor.GetSelectedProperty(expr),
                                                               String.Format(SRResources.EqualExpressionsMustHaveSameTypes,
                                                                             typeof(Dependent).FullName, "ForeignKey4", "System.Int16",
                                                                             typeof(Principal).FullName, "PrincipalKey1", "System.Int32"));
        }
Пример #7
0
        public void CanGetSingleSelectedPropertyPair()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr = (d, p) => d.ForeignKey1 == p.PrincipalKey1;

            // Act
            IDictionary <PropertyInfo, PropertyInfo> properties =
                PropertyPairSelectorVisitor.GetSelectedProperty(expr);

            // Assert
            Assert.Single(properties);
            Assert.Equal("ForeignKey1", properties.Keys.First().Name);
            Assert.Equal("PrincipalKey1", properties.Values.First().Name);
        }
Пример #8
0
        public void CanGetMultiSelectedPropertyPairs()
        {
            // Arrange
            Expression <Func <Dependent, Principal, bool> > expr =
                (d, p) => d.ForeignKey1 == p.PrincipalKey1 && d.ForeignKey2 == p.PrincipalKey2;

            // Act
            IDictionary <PropertyInfo, PropertyInfo> properties =
                PropertyPairSelectorVisitor.GetSelectedProperty(expr);

            // Assert
            Assert.Equal(2, properties.Count);

            Assert.Equal("PrincipalKey1", properties[typeof(Dependent).GetProperty("ForeignKey1")].Name);
            Assert.Equal("PrincipalKey2", properties[typeof(Dependent).GetProperty("ForeignKey2")].Name);
        }