Skip to content

Commit b0387e7

Browse files
Add missing toQueryParams test cases: float32/double/byte arrays and Option array types (#304)
* Initial plan * Add missing toQueryParams test cases: float32/double/byte arrays and Option array types Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
1 parent 55da396 commit b0387e7

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,42 @@ module ToQueryParamsTests =
170170
let result = toQueryParams "id" (box [| g1; g2 |]) stubClient
171171
result |> shouldEqual [ ("id", g1.ToString()); ("id", g2.ToString()) ]
172172

173+
[<Fact>]
174+
let ``toQueryParams handles float32 array``() =
175+
let result = toQueryParams "v" (box [| 1.5f; 2.5f |]) stubClient
176+
result |> shouldEqual [ ("v", "1.5"); ("v", "2.5") ]
177+
178+
[<Fact>]
179+
let ``toQueryParams handles double array``() =
180+
let result = toQueryParams "v" (box [| 1.5; 2.5 |]) stubClient
181+
result |> shouldEqual [ ("v", "1.5"); ("v", "2.5") ]
182+
183+
[<Fact>]
184+
let ``toQueryParams handles byte array as base64``() =
185+
// byte[] is serialized via client.Serialize (JSON base64) with surrounding quotes trimmed
186+
let bytes = [| 72uy; 101uy; 108uy; 108uy; 111uy |] // "Hello" in ASCII
187+
let expected = (JsonSerializer.Serialize bytes).Trim('"')
188+
let result = toQueryParams "data" (box bytes) stubClient
189+
result |> shouldEqual [ ("data", expected) ]
190+
191+
[<Fact>]
192+
let ``toQueryParams skips None items in Option<string> array``() =
193+
let values: Option<string>[] = [| Some "a"; None; Some "c" |]
194+
let result = toQueryParams "q" (box values) stubClient
195+
result |> shouldEqual [ ("q", "a"); ("q", "c") ]
196+
197+
[<Fact>]
198+
let ``toQueryParams skips None items in Option<float32> array``() =
199+
let values: Option<float32>[] = [| Some 1.5f; None; Some 3.5f |]
200+
let result = toQueryParams "v" (box values) stubClient
201+
result |> shouldEqual [ ("v", "1.5"); ("v", "3.5") ]
202+
203+
[<Fact>]
204+
let ``toQueryParams skips None items in Option<double> array``() =
205+
let values: Option<double>[] = [| Some 1.5; None; Some 3.5 |]
206+
let result = toQueryParams "v" (box values) stubClient
207+
result |> shouldEqual [ ("v", "1.5"); ("v", "3.5") ]
208+
173209

174210
module CombineUrlTests =
175211

0 commit comments

Comments
 (0)