Skip to content

Commit 76769fe

Browse files
committed
Updated README.md for model state number of errors testing (closes #33)
1 parent 4e6e95d commit 76769fe

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

documentation/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ MyWebApi
136136
.ShouldHave()
137137
.InvalidModelState();
138138

139+
// tests whether model state is not valid
140+
// with specific number of errors
141+
MyWebApi
142+
.Controller<WebApiController>()
143+
.Calling(c => c.SomeAction(requestModel))
144+
.ShouldHave()
145+
.InvalidModelState(withNumberOfErrors: 5);
146+
139147
// tests whether model state is valid and returns some action result
140148
MyWebApi
141149
.Controller<WebApiController>()

src/MyWebApi.Tests/BuildersTests/ActionsTests/ShouldHaveModelStateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void ShouldHaveInvalidModelStateShouldThrowExceptionWithValidRequestModel
134134
.Controller<WebApiController>()
135135
.Calling(c => c.ModelStateCheck(requestModel))
136136
.ShouldHave()
137-
.InvalidModelState(5);
137+
.InvalidModelState(withNumberOfErrors: 5);
138138
}
139139

140140
[Test]

src/MyWebApi/Builders/Actions/ShouldHave/ShouldHaveModelState.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ public IAndTestBuilder<TActionResult> ValidModelState()
5151
/// <summary>
5252
/// Checks whether the tested action's provided model state is not valid.
5353
/// </summary>
54-
/// <param name="numberOfErrors">Expected number of errors. If default null is provided, the test builder checks only if any errors are found.</param>
54+
/// <param name="withNumberOfErrors">Expected number of errors. If default null is provided, the test builder checks only if any errors are found.</param>
5555
/// <returns>Test builder with AndAlso method.</returns>
56-
public IAndTestBuilder<TActionResult> InvalidModelState(int? numberOfErrors = null)
56+
public IAndTestBuilder<TActionResult> InvalidModelState(int? withNumberOfErrors = null)
5757
{
5858
var actualModelStateErrors = this.Controller.ModelState.Count;
5959
if (actualModelStateErrors == 0
60-
|| (numberOfErrors != null && actualModelStateErrors != numberOfErrors))
60+
|| (withNumberOfErrors != null && actualModelStateErrors != withNumberOfErrors))
6161
{
6262
throw new ModelErrorAssertionException(string.Format(
6363
"When calling {0} action in {1} expected to have invalid model state{2}, {3}.",
6464
this.ActionName,
6565
this.Controller.GetName(),
66-
numberOfErrors == null ? string.Empty : string.Format(" with {0} errors", numberOfErrors),
67-
numberOfErrors == null ? "but was in fact valid" : string.Format("but contained {0}", actualModelStateErrors)));
66+
withNumberOfErrors == null ? string.Empty : string.Format(" with {0} errors", withNumberOfErrors),
67+
withNumberOfErrors == null ? "but was in fact valid" : string.Format("but contained {0}", actualModelStateErrors)));
6868
}
6969

7070
return this.NewAndTestBuilder();

src/MyWebApi/Builders/Contracts/Actions/IShouldHaveTestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public interface IShouldHaveTestBuilder<TActionResult> : IBaseTestBuilderWithAct
4242
/// <summary>
4343
/// Checks whether the tested action's provided model state is not valid.
4444
/// </summary>
45-
/// <param name="numberOfErrors">Expected number of errors. If default null is provided, the test builder checks only if any errors are found.</param>
45+
/// <param name="withNumberOfErrors">Expected number of errors. If default null is provided, the test builder checks only if any errors are found.</param>
4646
/// <returns>Test builder with AndAlso method.</returns>
47-
IAndTestBuilder<TActionResult> InvalidModelState(int? numberOfErrors = null);
47+
IAndTestBuilder<TActionResult> InvalidModelState(int? withNumberOfErrors = null);
4848
}
4949
}

0 commit comments

Comments
 (0)