Skip to content

Commit 3de29a4

Browse files
committed
Updated README.md for version 0.1
1 parent 1758490 commit 3de29a4

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MyWebApi - ASP.NET Web API Fluent Testing Framework
2-
====================================
2+
------------------------------------
33

44
MyWebApi is unit testing framework providing easy fluent interface to test the ASP.NET Web API framework. Inspired by [TestStack.FluentMVCTesting](https://github.com/TestStack/TestStack.FluentMVCTesting) and [ChaiJS](https://github.com/chaijs/chai)
55

@@ -91,6 +91,83 @@ MyWebApi
9191
.ContainingModelStateErrorFor(m => m.SecondProperty).Containing("ror mes"); // error message must contain the provided string
9292
```
9393

94+
### Action results
95+
96+
You can test for specific return values or the default IHttpActionResult types:
97+
98+
#### Generic result
99+
100+
Useful where the action does not return IHttpActionResult
101+
102+
```c#
103+
// tests whether the action returns certain type by providing generic parameter
104+
MyWebApi
105+
.Controller<WebApiController>()
106+
.Calling(c => c.SomeAction())
107+
.ShouldReturn<ResponseModel>();
108+
109+
// tests whether the action returns certain type by using typeof
110+
MyWebApi
111+
.Controller<WebApiController>()
112+
.Calling(c => c.SomeAction())
113+
.ShouldReturn(typeof(ResponseModel));
114+
115+
// tests whether the action returns generic model
116+
MyWebApi
117+
.Controller<WebApiController>()
118+
.Calling(c => c.SomeAction())
119+
.ShouldReturn(typeof(IList<>)); // works with IEnumerable<> (or IList<ResponseModel>) too by using polymorphism
120+
```
121+
122+
#### OkResult
123+
124+
```c#
125+
// tests whether the action returns OkResult
126+
MyWebApi
127+
.Controller<WebApiController>()
128+
.Calling(c => c.SomeAction())
129+
.ShouldReturnOk();
130+
131+
// tests whether the action returns OkResult with no response model
132+
MyWebApi
133+
.Controller<WebApiController>()
134+
.Calling(c => c.SomeAction())
135+
.ShouldReturnOk()
136+
.WithNoResponseModel();
137+
138+
// tests whether the action returns OkResult with specific response model type
139+
MyWebApi
140+
.Controller<WebApiController>()
141+
.Calling(c => c.SomeAction())
142+
.ShouldReturnOk()
143+
.WithResponseModel<ResponseModel>();
144+
145+
// tests whether the action returns OkResult with specific object
146+
MyWebApi
147+
.Controller<WebApiController>()
148+
.Calling(c => c.SomeAction())
149+
.ShouldReturnOk()
150+
.WithResponseModel(someResponseModelObject);
151+
152+
// tests whether the action returns OkResult with specific response model passing certain assertions
153+
MyWebApi
154+
.Controller<WebApiController>()
155+
.Calling(c => c.SomeAction())
156+
.ShouldReturnOk()
157+
.WithResponseModel<ResponseModel>(m =>
158+
{
159+
Assert.AreEqual(1, m.Id);
160+
Assert.AreEqual("Some property value", m.SomeProperty);
161+
});
162+
163+
// tests whether the action returns OkResult with specific response model passing a predicate
164+
MyWebApi
165+
.Controller<WebApiController>()
166+
.Calling(c => c.SomeAction())
167+
.ShouldReturnOk()
168+
.WithResponseModel<ResponseModel>(m => m.Id == 1);
169+
```
170+
94171
## Any questions, comments or additions?
95172

96173
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)