Skip to content

Commit 00ce004

Browse files
NullNull
Null
authored and
Null
committed
Merge pull request #57 from ByteBlast/master
Brought in ExpressionToString
2 parents fde71ce + a13eadd commit 00ce004

File tree

10 files changed

+323
-203
lines changed

10 files changed

+323
-203
lines changed

BREAKING_CHANGES.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can read the original problem specification and discussion [here](https://g
2323

2424
If your project has been impacted by this particular breaking change, you might consider reevaluate the correctness of the affected tests.
2525

26-
## Error Messages
26+
## Error Message Quotes
2727

2828
Some error messages surrounded actual values in double quotes. Others surrounded the values in single quotes. In version 3.0.0 *all* values are surrounded in single quotes.
2929

@@ -33,7 +33,27 @@ Consistency.
3333

3434
### Fix
3535

36-
Amend all effected tests to expect single quotes instead of double quotes.
36+
Amend any affected tests to expect single quotes instead of double quotes.
37+
38+
## Error Message Lambda Expression
39+
40+
In error messages, lambda expressions arguments are now surrounded in a pair of parentheses. For example:
41+
42+
... to pass the given condition (model => (model.Property1 != null))
43+
44+
will now look like this:
45+
46+
... to pass the given condition ((model) => (model.Property1 != null))
47+
48+
As you can see, the argument called `model` is now surrounded in parentheses.
49+
50+
###Reason
51+
52+
FluentMVCTesting now uses [ExpressionToString](https://github.com/JakeGinnivan/ExpressionToString) to humanize expression trees. ExpressionToString surrounds arguments in parentheses.
53+
54+
###Fix
55+
56+
Amend any affected tests to expect lambda expression arguments to be surrounded in parentheses.
3757

3858
# Version 2.0.0
3959

TestStack.FluentMVCTesting.Tests/Internal/ExpressionInspectorTests.cs

Lines changed: 0 additions & 174 deletions
This file was deleted.

TestStack.FluentMVCTesting.Tests/TestStack.FluentMVCTesting.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
<Compile Include="ControllerResultTestTests\ShouldReturnEmptyResultTests.cs" />
9090
<Compile Include="ControllerResultTestTests\ShouldReturnJsonTests.cs" />
9191
<Compile Include="ControllerResultTestTests\ShouldReturnContentTests.cs" />
92-
<Compile Include="Internal\ExpressionInspectorTests.cs" />
9392
<Compile Include="RouteValueDictionaryExtensionsTests.cs" />
9493
<Compile Include="TempDataResultTest.cs" />
9594
<Compile Include="TestControllers\AsyncController.cs" />

TestStack.FluentMVCTesting.Tests/ViewResultTestTests.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void Check_for_invalid_model_using_predicate()
7272
var exception = Assert.Throws<ViewResultModelAssertionException>(() =>
7373
_viewResultTest.WithModel<TestViewModel>(m => m.Property1 == null)
7474
);
75-
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model {{\"Property1\":\"{0}\",\"Property2\":{1}}} to pass the given condition (m => (m.Property1 == null)), but it failed.", _model.Property1, _model.Property2)));
75+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model {{\"Property1\":\"{0}\",\"Property2\":{1}}} to pass the given condition ((m) => (m.Property1 == null)), but it failed.", _model.Property1, _model.Property2)));
7676
}
7777

7878
[Test]
@@ -81,7 +81,7 @@ public void Check_for_invalid_model_using_predicate_with_conditional_or()
8181
var exception = Assert.Throws<ViewResultModelAssertionException>(() =>
8282
_viewResultTest.WithModel<TestViewModel>(m => m.Property1 == null || m.Property2 == 1)
8383
);
84-
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model {{\"Property1\":\"{0}\",\"Property2\":{1}}} to pass the given condition (m => ((m.Property1 == null) || (m.Property2 == 1))), but it failed.", _model.Property1, _model.Property2)));
84+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model {{\"Property1\":\"{0}\",\"Property2\":{1}}} to pass the given condition ((m) => ((m.Property1 == null) || (m.Property2 == 1))), but it failed.", _model.Property1, _model.Property2)));
8585
}
8686

8787
[Test]
@@ -91,7 +91,18 @@ public void Check_for_invalid_model_using_predicate_with_primitive_operand()
9191
var exception = Assert.Throws<ViewResultModelAssertionException>(() =>
9292
_viewResultTest.WithModel<string>(m => m == "ab")
9393
);
94-
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model \"{0}\" to pass the given condition (m => (m == \"ab\")), but it failed.", _viewResult.ViewData.Model)));
94+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model \"{0}\" to pass the given condition ((m) => (m == \"ab\")), but it failed.", _viewResult.ViewData.Model)));
95+
}
96+
97+
[Test]
98+
public void Check_for_invalid_model_using_predicate_with_captured_var_operand()
99+
{
100+
var capturedOuterVar = "ab";
101+
_viewResult.ViewData.Model = "abc";
102+
var exception = Assert.Throws<ViewResultModelAssertionException>(() =>
103+
_viewResultTest.WithModel<string>(m => m == capturedOuterVar)
104+
);
105+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected view model \"{0}\" to pass the given condition ((m) => (m == capturedOuterVar)), but it failed.", _viewResult.ViewData.Model)));
95106
}
96107

97108
[Test]

0 commit comments

Comments
 (0)