Skip to content

Commit 587c6f7

Browse files
committed
Readability tweaks.
1 parent 71e6564 commit 587c6f7

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

TestStack.FluentMVCTesting.Tests/Internal/ExpressionInspectorTests.cs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,32 @@ public void Correctly_parse_equality_comparison_with_property_operand()
3636
}
3737

3838
[Test]
39-
public void Correctly_parse_equality_comparison_with_property_operands()
39+
public void Correctly_parse_equality_comparison_with_two_property_operands()
4040
{
41-
Expression<Func<PostViewModel, bool>> func = post => post.Title == post.Slug;
41+
Expression<Func<PostViewModel, bool>> func = post =>
42+
post.Title == post.Slug;
4243
ExpressionInspector sut = new ExpressionInspector();
4344
var actual = sut.Inspect(func);
4445
Assert.AreEqual("post => (post.Title == post.Slug)", actual);
4546
}
4647

4748
[Test]
48-
public void Correctly_parse_inequality_comparison()
49+
public void Correctly_parse_equality_comparison_with_captured_constant_operand()
4950
{
50-
Expression<Func<int, bool>> func = number => number != 5;
51+
const int Number = 5;
52+
Expression<Func<int, bool>> func = number => number == Number;
5153
ExpressionInspector sut = new ExpressionInspector();
5254
var actual = sut.Inspect(func);
53-
Assert.AreEqual("number => (number != 5)", actual);
55+
Assert.AreEqual(string.Concat("number => (number == ", Number, ")"), actual);
5456
}
5557

5658
[Test]
57-
public void Correctly_parse_equality_comparison_with_captured_constant_operand()
59+
public void Correctly_parse_inequality_comparison()
5860
{
59-
const int Number = 5;
60-
Expression<Func<int, bool>> func = number => number == Number;
61+
Expression<Func<int, bool>> func = number => number != 5;
6162
ExpressionInspector sut = new ExpressionInspector();
6263
var actual = sut.Inspect(func);
63-
Assert.AreEqual(
64-
string.Concat("number => (number == ", Number, ")"), actual);
64+
Assert.AreEqual("number => (number != 5)", actual);
6565
}
6666

6767
[Test]
@@ -73,6 +73,25 @@ public void Correctly_parse_relational_comparison()
7373
Assert.AreEqual("number => (number < 5)", actual);
7474
}
7575

76+
[Test]
77+
public void Correctly_parse_expression_whose_source_text_contains_parentheses()
78+
{
79+
Expression<Func<PostViewModel, bool>> func = post => post.Title.Contains("");
80+
ExpressionInspector sut = new ExpressionInspector();
81+
var actual = sut.Inspect(func);
82+
Assert.AreEqual("post => post.Title.Contains(\"\")", actual);
83+
}
84+
85+
[Test]
86+
public void Correctly_parse_null_coalescing_operator()
87+
{
88+
Expression<Func<string, bool>> func =
89+
text => text == ("" ?? "a");
90+
ExpressionInspector sut = new ExpressionInspector();
91+
var actual = sut.Inspect(func);
92+
Assert.AreEqual("text => (text == (\"\" ?? \"a\"))", actual);
93+
}
94+
7695
[Test]
7796
public void Correctly_parse_conditional_or_operator()
7897
{
@@ -90,10 +109,10 @@ public void Correctly_parse_two_conditional_or_operators()
90109
text => text == "any" || text.Length == 3 || text.Length == 9;
91110
ExpressionInspector sut = new ExpressionInspector();
92111
var actual = sut.Inspect(func);
93-
Assert.AreEqual("text => (((text == \"any\") || (text.Length == 3)) || (text.Length == 9))", actual);
112+
Assert.AreEqual(
113+
"text => (((text == \"any\") || (text.Length == 3)) || (text.Length == 9))", actual);
94114
}
95115

96-
97116
[Test]
98117
public void Correctly_parse_conditional_and_operator()
99118
{
@@ -114,7 +133,6 @@ public void Correctly_parse_logical_and_operator()
114133
Assert.AreEqual("text => ((text == \"any\") & (text.Length == 3))", actual);
115134
}
116135

117-
118136
[Test]
119137
public void Correctly_parse_logical_or_operator()
120138
{
@@ -125,16 +143,6 @@ public void Correctly_parse_logical_or_operator()
125143
Assert.AreEqual("text => ((text == \"any\") | (text.Length == 3))", actual);
126144
}
127145

128-
[Test]
129-
public void Correctly_parse_null_coalescing_operator()
130-
{
131-
Expression<Func<string, bool>> func =
132-
text => text == ("" ?? "a");
133-
ExpressionInspector sut = new ExpressionInspector();
134-
var actual = sut.Inspect(func);
135-
Assert.AreEqual("text => (text == (\"\" ?? \"a\"))", actual);
136-
}
137-
138146
[Test]
139147
public void Not_mistake_property_called_OrElse_for_conditional_or_operator()
140148
{
@@ -145,15 +153,6 @@ public void Not_mistake_property_called_OrElse_for_conditional_or_operator()
145153
Assert.AreEqual("post => ((post.Title == \"\") || (post.OrElse == \"\"))", actual);
146154
}
147155

148-
[Test]
149-
public void Correctly_parse_expression_whose_source_text_contains_parentheses()
150-
{
151-
Expression<Func<PostViewModel, bool>> func = post => post.Title.Contains("");
152-
ExpressionInspector sut = new ExpressionInspector();
153-
var actual = sut.Inspect(func);
154-
Assert.AreEqual("post => post.Title.Contains(\"\")", actual);
155-
}
156-
157156
[Test]
158157
public void Correctly_parse_logical_xor_operator()
159158
{

TestStack.FluentMvcTesting/Internal/ExpressionInspector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Linq.Expressions;
2-
using System.Text.RegularExpressions;
32

43
namespace TestStack.FluentMVCTesting.Internal
54
{
@@ -12,7 +11,6 @@ internal string Inspect(LambdaExpression expression)
1211
.Replace(" AndAlso ", " && ")
1312
.Replace(" Or ", " | ")
1413
.Replace(" And ", " & ");
15-
1614
}
1715
}
1816
}

0 commit comments

Comments
 (0)