Skip to content

Commit

Permalink
Reuse GetIEdmProperty() and GetIEdmType() methods in the other existi…
Browse files Browse the repository at this point in the history
…ng tests
  • Loading branch information
WanjohiSammy committed Aug 14, 2024
1 parent f0fbbde commit 8f0698b
Showing 1 changed file with 27 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public void ParseFilterWithEnum()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(GetColorProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("Color"));

binaryNode
.Right
.ShouldBeEnumNode(this.GetColorType(this.userModel), (int)Color.Green);
.ShouldBeEnumNode(this.GetIEdmType<IEdmEnumType>("NS.Color"), (int)Color.Green);
}

[Fact]
Expand All @@ -121,11 +121,11 @@ public void ParseFilterWithEnumInt()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(GetColorProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("Color"));

binaryNode
.Right
.ShouldBeEnumNode(this.GetColorType(this.userModel), (int)Color.Green);
.ShouldBeEnumNode(this.GetIEdmType<IEdmEnumType>("NS.Color"), (int)Color.Green);
}

[Fact]
Expand All @@ -143,11 +143,11 @@ public void ParseFilterWithHasOperatorEnumMemberName()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(this.GetColorFlagsType(this.userModel), (int)ColorFlags.Green);
.ShouldBeEnumNode(this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"), (int)ColorFlags.Green);
}

[Fact]
Expand All @@ -165,11 +165,11 @@ public void ParseFilterWithHasOperatorEnumUnderlyingValue()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(this.GetColorFlagsType(this.userModel), (int)ColorFlags.Green);
.ShouldBeEnumNode(this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"), (int)ColorFlags.Green);
}

[Fact]
Expand All @@ -187,11 +187,11 @@ public void ParseFilterWithHasOperatorEnumLiteralValueAsLeftOperand()

binaryNode
.Left
.ShouldBeEnumNode(this.GetColorFlagsType(this.userModel), (int)(ColorFlags.Green | ColorFlags.Red));
.ShouldBeEnumNode(this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"), (int)(ColorFlags.Green | ColorFlags.Red));

binaryNode
.Right
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));
}

[Fact]
Expand All @@ -209,11 +209,11 @@ public void ParseFilterWithHasOperatorNonFlagsEnum()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("Color"));

binaryNode
.Right
.ShouldBeEnumNode(this.GetColorType(this.userModel), (int)Color.Green);
.ShouldBeEnumNode(this.GetIEdmType<IEdmEnumType>("NS.Color"), (int)Color.Green);
}

[Fact]
Expand All @@ -231,12 +231,12 @@ public void ParseFilterWithEnumNormalConbinedValues()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorFlagsType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"),
(int)(ColorFlags.Green | ColorFlags.Red));
}

Expand All @@ -255,12 +255,12 @@ public void ParseFilterWithEnumCombinedValuesOrderReversed()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorFlagsType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"),
(int)(ColorFlags.Green | ColorFlags.Red));
}

Expand All @@ -279,12 +279,12 @@ public void ParseFilterWithEnumValuesCompatibleWithString()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorFlagsType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"),
"Red");
}

Expand All @@ -303,12 +303,12 @@ public void ParseFilterWithEnumDefinedConbinedValues()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorFlagsType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"),
(int)(ColorFlags.Green | ColorFlags.Red));
}

Expand All @@ -327,12 +327,12 @@ public void ParseFilterWithEnumCombinedUnderlyingValues()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorFlagsProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("ColorFlags"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorFlagsType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.ColorFlags"),
(int)(ColorFlags.Green | ColorFlags.Red));
}

Expand All @@ -351,12 +351,12 @@ public void ParseFilterWithEnumNegativeMember()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("Color"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.Color"),
(int)(Color.White));

var constantNode = Assert.IsType<ConstantNode>(binaryNode.Right);
Expand All @@ -379,12 +379,12 @@ public void ParseFilterWithEnumUndefinedMember()

binaryNode
.Left
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorProp(this.userModel));
.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("Color"));

binaryNode
.Right
.ShouldBeEnumNode(
this.GetColorType(this.userModel),
this.GetIEdmType<IEdmEnumType>("NS.Color"),
-132534290);

var constantNode = Assert.IsType<ConstantNode>(binaryNode.Right);
Expand All @@ -403,7 +403,7 @@ public void ParseFilterWithNullEnumValue()
{
var filterQueryNode = ParseFilter("Color eq null", this.userModel, this.entityType, this.entitySet);
var binaryNode = filterQueryNode.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal);
binaryNode.Left.ShouldBeSingleValuePropertyAccessQueryNode(this.GetColorProp(this.userModel));
binaryNode.Left.ShouldBeSingleValuePropertyAccessQueryNode(this.GetIEdmProperty("Color"));

var convertNode = Assert.IsType<ConvertNode>(binaryNode.Right);
convertNode.Source.ShouldBeConstantQueryNode((object)null);
Expand Down Expand Up @@ -701,30 +701,6 @@ public void ParseFilterWithInOperatorWithEnumsInvalidMemberNames_ThrowsIsNotVali
action.Throws<ODataException>(Strings.Binder_IsNotValidEnumConstant(expectedExceptionParameter));
}

private IEdmStructuralProperty GetColorProp(IEdmModel model)
{
return (IEdmStructuralProperty)((IEdmStructuredType)model
.FindType("NS.MyEntityType"))
.FindProperty("Color");
}

private IEdmEnumType GetColorType(IEdmModel model)
{
return (IEdmEnumType)model.FindType("NS.Color");
}

private IEdmStructuralProperty GetColorFlagsProp(IEdmModel model)
{
return (IEdmStructuralProperty)((IEdmStructuredType)model
.FindType("NS.MyEntityType"))
.FindProperty("ColorFlags");
}

private IEdmEnumType GetColorFlagsType(IEdmModel model)
{
return (IEdmEnumType)model.FindType("NS.ColorFlags");
}

private T GetIEdmType<T>(string typeName) where T : IEdmType
{
return (T)this.userModel.FindType(typeName);
Expand Down

0 comments on commit 8f0698b

Please sign in to comment.