Allow string return type, and URL-encode param (#38)

This commit is contained in:
Patrick Stevens
2023-12-29 18:13:39 +00:00
committed by GitHub
parent 548d863baf
commit dc0f0803b3
11 changed files with 282 additions and 121 deletions

View File

@@ -0,0 +1,36 @@
namespace MyriadPlugin.Test
open System
open System.Net
open System.Net.Http
open NUnit.Framework
open FsUnitTyped
open PureGym
[<TestFixture>]
module TestPathParam =
[<Test>]
let ``Path params are escaped`` () =
let proc (message : HttpRequestMessage) : HttpResponseMessage Async =
async {
message.Method |> shouldEqual HttpMethod.Get
let expectedUriPrefix = "https://example.com/endpoint/"
let actualUri = message.RequestUri.ToString ()
if not (actualUri.StartsWith (expectedUriPrefix, StringComparison.Ordinal)) then
failwith $"wrong prefix on %s{actualUri}"
let content = new StringContent (actualUri.Substring expectedUriPrefix.Length)
let resp = new HttpResponseMessage (HttpStatusCode.OK)
resp.Content <- content
return resp
}
use client = HttpClientMock.make (Uri "https://example.com") proc
let api = PureGymApi.make client
api.GetPathParam("hello/world?(hi)").Result
|> shouldEqual "hello%2fworld%3f(hi)"