Skip to content

Commit 65e9e55

Browse files
authored
Merge pull request #63 from jkone27/add-patch-method
Add patch method
2 parents 6417bfb + 8e02415 commit 65e9e55

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

ApiStub.FSharp.Stubbery/ApiStub.FSharp.Stubbery.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<PackageId>ApiStub.FSharp.Stubbery</PackageId>
7-
<Version>1.0.2</Version>
7+
<Version>1.0.3</Version>
88
<Authors>jkone27</Authors>
99
<RequireLicenseAcceptance>false</RequireLicenseAcceptance>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>

ApiStub.FSharp.Stubbery/Library.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ module StubberyCE =
6565
member this.Put(x, route, stub) =
6666
this.Stub(x, [| HttpMethod.Put |], route, stub)
6767

68+
[<CustomOperation("PUT_OBJ")>]
69+
member this.PutObj(x, route, stub) =
70+
this.StubObj(x, [| HttpMethod.Put |], route, (fun _ -> stub))
71+
72+
[<CustomOperation("PATCH")>]
73+
member this.Patch(x, route, stub) =
74+
this.Stub(x, [| HttpMethod.Patch |], route, stub)
75+
76+
[<CustomOperation("PATCH_OBJ")>]
77+
member this.PatchObj(x, route, stub) =
78+
this.StubObj(x, [| HttpMethod.Patch |], route, (fun _ -> stub))
79+
80+
6881
[<CustomOperation("DELETE")>]
6982
member this.Delete(x, route, stub) =
7083
this.Stub(x, [| HttpMethod.Delete |], route, stub)

ApiStub.FSharp/ApiStub.FSharp.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>net6.0</TargetFramework>
44
<GenerateDocumentationFile>true</GenerateDocumentationFile>
55
<PackageId>ApiStub.FSharp</PackageId>
6-
<Version>1.2.0</Version>
6+
<Version>1.2.1</Version>
77
<Authors>jkone27</Authors>
88
<RequireLicenseAcceptance>false</RequireLicenseAcceptance>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>

ApiStub.FSharp/CE.fs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ module CE =
2525
let mutable httpMessageHandler: DelegatingHandler = null
2626

2727
let customConfigureServices =
28-
new ResizeArray<IServiceCollection -> IServiceCollection>()
28+
ResizeArray<IServiceCollection -> IServiceCollection>()
2929

3030
let customConfigureTestServices =
31-
new ResizeArray<IServiceCollection -> IServiceCollection>()
32-
31+
ResizeArray<IServiceCollection -> IServiceCollection>()
3332

3433
interface IDisposable with
3534
member this.Dispose() = factory.Dispose()
@@ -52,13 +51,12 @@ module CE =
5251
useRealHttpClient
5352
) =
5453

55-
let routeValueDict = new RouteValueDictionary()
54+
let routeValueDict = RouteValueDictionary()
5655

5756
let templateMatcher =
5857
try
59-
6058
let rt = TemplateParser.Parse(routeTemplate.TrimStart('/'))
61-
let tm = new TemplateMatcher(rt, routeValueDict)
59+
let tm = TemplateMatcher(rt, routeValueDict)
6260
Some(tm)
6361
with _ ->
6462
None
@@ -167,6 +165,21 @@ module CE =
167165
member this.PutJson(x, route, stub: obj) =
168166
this.StubJson(x, [| HttpMethod.Put |], route, stub)
169167

168+
/// stub PATCH json
169+
[<CustomOperation("PATCH_ASYNC")>]
170+
member this.PatchAsync(x, route, stub) =
171+
this.StubAsync(x, [| HttpMethod.Patch |], route, stub)
172+
173+
/// stub PATCH
174+
[<CustomOperation("PATCH")>]
175+
member this.Patch(x, route, stub) =
176+
this.Stub(x, [| HttpMethod.Patch |], route, stub)
177+
178+
/// stub PATCH json
179+
[<CustomOperation("PATCHJ")>]
180+
member this.PatchJson(x, route, stub: obj) =
181+
this.StubJson(x, [| HttpMethod.Patch |], route, stub)
182+
170183
/// stub DELETE
171184
[<CustomOperation("DELETE")>]
172185
member this.Delete(x, route, stub) =
@@ -207,7 +220,7 @@ module CE =
207220
else
208221
String.Empty
209222

210-
let newBase = new Uri(new Uri("http://127.0.0.1/"), path)
223+
let newBase = Uri(Uri("http://127.0.0.1/"), path)
211224
c.BaseAddress <- newBase)
212225
|> ignore)
213226
|> ignore

ApiStub.FSharp/Csharp.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ type CsharpExtensions =
1919
[<Extension>]
2020
static member DELETEJ<'a when 'a: not struct>(x: TestClient<'a>, route: string, stub: obj) =
2121
x.DeleteJson(x, route, stub)
22+
23+
[<Extension>]
24+
static member PATCHJ<'a when 'a: not struct>(x: TestClient<'a>, route: string, stub: obj) =
25+
x.PatchJson(x, route, stub)

docs/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module Tests =
7676

7777
if you prefer to use C# for testing, some extension methods are provided to use with C# as well:
7878

79-
`GETJ, PUTJ, POSTJ, DELETEJ`
79+
`GETJ, PUTJ, POSTJ, DELETEJ, PATCHJ`
8080

8181
Remember to add this snippet at the end of your `Program.cs` file for the `TestClient` to be able to pick up your configuration:
8282

@@ -130,7 +130,7 @@ Available HTTP methods in the test dsl to "mock" HTTP client responses are the f
130130

131131
### Basic
132132

133-
* `GET`, `PUT`, `POST`, `DELETE` - for accessing request, route parameters and sending back HttpResponseMessage (e.g. using R_JSON or other constructors)
133+
* `GET`, `PUT`, `POST`, `DELETE`, `PATCH` - for accessing request, route parameters and sending back HttpResponseMessage (e.g. using R_JSON or other constructors)
134134

135135
```fsharp
136136
// example of control on request and route value dictionary
@@ -143,15 +143,15 @@ Available HTTP methods in the test dsl to "mock" HTTP client responses are the f
143143

144144
### JSON 📒
145145

146-
* `GETJ`, `PUTJ`, `POSTJ`, `DELETEJ` - for objects converted to JSON content
146+
* `GETJ`, `PUTJ`, `POSTJ`, `DELETEJ`, `PATCHJ` - for objects converted to JSON content
147147

148148
```fsharp
149149
GETJ "/yetAnotherOne" {| Success = true |}
150150
```
151151

152152
### ASYNC Overloads (task) ⚡️
153153

154-
* `GET_ASYNC`, `PUT_ASYNC`, `POST_ASYNC`, `DELETE_ASYNC` - for handling asynchronous requests inside a task computation expression (async/await) and mock dynamically
154+
* `GET_ASYNC`, `PUT_ASYNC`, `POST_ASYNC`, `DELETE_ASYNC`, `PATCH_ASYNC` - for handling asynchronous requests inside a task computation expression (async/await) and mock dynamically
155155

156156
```fsharp
157157
// example of control on request and route value dictionary

0 commit comments

Comments
 (0)