Skip to content

Commit a96ea88

Browse files
committed
Added calling actions instructions to README.md
1 parent 177d26f commit a96ea88

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

MyWebApi.Tests/BuildersTests/ControllerBuilderTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void CallingShouldPopulateCorrectActionNameAndActionResultWithAsyncAction
3434
[Test]
3535
public void CallingShouldPopulateModelStateWhenThereAreModelErrors()
3636
{
37-
var requestBody = TestObjectFactory.GetRequestModelWithErrors();
37+
var requestModel = TestObjectFactory.GetRequestModelWithErrors();
3838

3939
var actionResultTestBuilder = MyWebApi
4040
.Controller<WebApiController>()
41-
.Calling(c => c.OkResultActionWithRequestBody(1, requestBody));
41+
.Calling(c => c.OkResultActionWithRequestBody(1, requestModel));
4242

4343
var modelState = actionResultTestBuilder.Controller.ModelState;
4444

@@ -51,11 +51,11 @@ public void CallingShouldPopulateModelStateWhenThereAreModelErrors()
5151
[Test]
5252
public void CallingShouldHaveValidModelStateWhenThereAreNoModelErrors()
5353
{
54-
var requestBody = TestObjectFactory.GetValidRequestModel();
54+
var requestModel = TestObjectFactory.GetValidRequestModel();
5555

5656
var actionResultTestBuilder = MyWebApi
5757
.Controller<WebApiController>()
58-
.Calling(c => c.OkResultActionWithRequestBody(1, requestBody));
58+
.Calling(c => c.OkResultActionWithRequestBody(1, requestModel));
5959

6060
var modelState = actionResultTestBuilder.Controller.ModelState;
6161

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MyWebApi is unit testing framework providing easy fluent interface to test the A
77

88
## How to use
99

10-
### Controllers
10+
### Controller instantiation
1111

1212
You have a couple of options from which you can setup the controller you want to test. The framework gives you static `MyWebApi` class from which the test builder starts.
1313

@@ -21,6 +21,27 @@ MyWebApi
2121
.Controller(() => new WebApiController(mockedInjectedService));
2222
```
2323

24+
### Calling actions
25+
26+
You can call any action using lambda expression. All parameter values will be resolved and model state validation will be performed on them.
27+
28+
```c#
29+
// calls action with no parameters
30+
MyWebApi
31+
.Controller<WebApiController>()
32+
.Calling(c => c.SomeAction());
33+
34+
// calls action with parameters
35+
MyWebApi
36+
.Controller<WebApiController>()
37+
.Calling(c => c.SomeAction(requestModel));
38+
39+
// calls async action
40+
MyWebApi
41+
.Controller<WebApiController>()
42+
.CallingAsync(c => c.SomeActionAsync());
43+
```
44+
2445
## Any questions, comments or additions?
2546

2647
Leave an issue on the [issues page](https://github.com/ivaylokenov/MyWebApi/issues) or send a [pull request](https://github.com/ivaylokenov/MyWebApi/pulls).

0 commit comments

Comments
 (0)