Skip to content

Commit f49642d

Browse files
committed
Support for parsing conditional or operator.
1 parent 47566fa commit f49642d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

TestStack.FluentMVCTesting.Tests/Internal/ExpressionInspectorTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,42 @@ public void Correctly_parse_relational_comparison()
7171
var actual = sut.Inspect(func);
7272
Assert.AreEqual("number => number < 5", actual);
7373
}
74+
75+
[Test]
76+
public void Correctly_parse_conditional_or_operator()
77+
{
78+
Expression<Func<string, bool>> func =
79+
text => text == "any" || text.Length == 3;
80+
ExpressionInspector sut = new ExpressionInspector();
81+
var actual = sut.Inspect(func);
82+
Assert.AreEqual("text => text == \"any\" || text.Length == 3", actual);
83+
}
84+
85+
public void Correctly_parse_two_conditional_or_operators()
86+
{
87+
Expression<Func<string, bool>> func =
88+
text => text == "any" || text.Length == 3 || text.Length == 9;
89+
ExpressionInspector sut = new ExpressionInspector();
90+
var actual = sut.Inspect(func);
91+
Assert.AreEqual("text => text == \"any\" || text.Length == 3 || text.Length == 9", actual);
92+
}
93+
94+
[Test]
95+
public void Not_mistake_property_called_OrElse_for_conditional_or_operator()
96+
{
97+
Expression<Func<PostViewModel, bool>> func =
98+
post => post.Title == "" || post.OrElse == "";
99+
ExpressionInspector sut = new ExpressionInspector();
100+
var actual = sut.Inspect(func);
101+
Assert.AreEqual("post => post.Title == \"\" || post.OrElse == \"\"", actual);
102+
}
74103
}
75104

76105
public class PostViewModel
77106
{
78107
public string Title { get; set; }
79108
public string Slug { get; set; }
109+
110+
public string OrElse { get; set; }
80111
}
81112
}

TestStack.FluentMvcTesting/Internal/ExpressionInspector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ internal class ExpressionInspector
77
{
88
internal string Inspect(LambdaExpression expression)
99
{
10-
return Regex.Replace(expression.ToString(), "[()]", "");
10+
return Regex.Replace(expression.ToString(), "[()]", "")
11+
.Replace(" OrElse ", " || ");
1112
}
1213
}
1314
}

0 commit comments

Comments
 (0)