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)); }
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'."); }
public void LambdaExpressionHasNotTwoParameters_ThrowException() { // Arrange Expression <Func <Dependent, int> > expr = d => d.ForeignKey1; // Act & Assert ExceptionAssert.Throws <InvalidOperationException>(() => PropertyPairSelectorVisitor.GetSelectedProperty(expr), SRResources.LambdaExpressionMustHaveExactlyTwoParameters); }
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."); }
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); }
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")); }
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); }
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); }