Skip to content

Commit df92383

Browse files
github-actions[bot]CopilotCopilotsergey-tihondsyme
authored
[Repo Assist] Add unit tests for RuntimeHelpers module (#295)
* Add unit tests for RuntimeHelpers module RuntimeHelpers.fs handles all parameter serialization and HTTP request building for generated API clients, but previously had zero dedicated unit tests. This PR adds 44 focused tests covering: - toParam: DateTime/DateTimeOffset ISO 8601 formatting, null handling - toQueryParams: all supported array/option/scalar types, DateTime ISO 8601 serialization, None filtering in optional arrays - combineUrl: trailing/leading slash normalisation - createHttpRequest: HTTP method, path, query params, null filtering - fillHeaders: header addition, null-value skip, Content-Type silence - toStringContent/toTextContent/toStreamContent: content-type headers, error on non-stream input Closes no specific issue; improves baseline test coverage for the runtime serialization layer (Task 9 - Testing Improvements). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks * 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> * Merge master and fix CI: add RuntimeHelpers unit tests (#305) * Fix Option types in form data not being unwrapped (issue #214) (#298) RuntimeHelpers.getPropertyValues now strips the FSharpOption<T> wrapper before returning property values. Previously, a property set to Some(true) was serialised as the string "Some(true)" in multipart/form-data and application/x-www-form-urlencoded bodies instead of the bare "True". None values were already handled (null). Also relax global.json SDK version constraint from 10.0.103 to 10.0.100 with rollForward:latestPatch so the project builds with any 10.0.1xx SDK available locally or in CI. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Initial plan * Fix Build and Test workflow to run on all pull requests, not just PRs targeting master Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: Don Syme <dsyme@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@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> * Remove unreachable null check from `toQueryParams` fallthrough case (#306) * Initial plan * Fix toQueryParams: remove unreachable null check from _ case 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> * Make null handling explicit in `toQueryParams` and fix misleading test comment (#307) * Initial plan * Add explicit null guard in toQueryParams and fix test comment Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> * Apply Fantomas formatting to RuntimeHelpers.fs 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> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
1 parent 12033b6 commit df92383

4 files changed

Lines changed: 375 additions & 34 deletions

File tree

.github/workflows/dotnetcore.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches:
66
- master
77
pull_request:
8-
branches:
9-
- master
108

119
concurrency:
1210
group: ${{ github.workflow }}-${{ github.ref }}

src/SwaggerProvider.Runtime/RuntimeHelpers.fs

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,42 @@ module RuntimeHelpers =
8585
| _ -> obj.ToString()
8686

8787
let toQueryParams (name: string) (obj: obj) (client: Swagger.ProvidedApiClientBase) =
88-
match obj with
89-
| :? array<byte> as xs -> [ name, (client.Serialize xs).Trim('\"') ] // TODO: Need to verify how servers parse byte[] from query string
90-
| :? array<bool> as xs -> xs |> toStrArray name
91-
| :? array<int32> as xs -> xs |> toStrArray name
92-
| :? array<int64> as xs -> xs |> toStrArray name
93-
| :? array<float32> as xs -> xs |> toStrArray name
94-
| :? array<double> as xs -> xs |> toStrArray name
95-
| :? array<string> as xs -> xs |> toStrArray name
96-
| :? array<DateTime> as xs -> xs |> toStrArrayDateTime name
97-
| :? array<DateTimeOffset> as xs -> xs |> toStrArrayDateTimeOffset name
98-
| :? array<Guid> as xs -> xs |> toStrArray name
99-
| :? array<Option<bool>> as xs -> xs |> toStrArrayOpt name
100-
| :? array<Option<int32>> as xs -> xs |> toStrArrayOpt name
101-
| :? array<Option<int64>> as xs -> xs |> toStrArrayOpt name
102-
| :? array<Option<float32>> as xs -> xs |> toStrArrayOpt name
103-
| :? array<Option<double>> as xs -> xs |> toStrArrayOpt name
104-
| :? array<Option<string>> as xs -> xs |> toStrArrayOpt name
105-
| :? array<Option<DateTime>> as xs -> xs |> toStrArrayDateTimeOpt name
106-
| :? array<Option<DateTimeOffset>> as xs -> xs |> toStrArrayDateTimeOffsetOpt name
107-
| :? array<Option<Guid>> as xs -> xs |> toStrArray name
108-
| :? Option<bool> as x -> x |> toStrOpt name
109-
| :? Option<int32> as x -> x |> toStrOpt name
110-
| :? Option<int64> as x -> x |> toStrOpt name
111-
| :? Option<float32> as x -> x |> toStrOpt name
112-
| :? Option<double> as x -> x |> toStrOpt name
113-
| :? Option<string> as x -> x |> toStrOpt name
114-
| :? Option<DateTime> as x -> x |> toStrDateTimeOpt name
115-
| :? Option<DateTimeOffset> as x -> x |> toStrDateTimeOffsetOpt name
116-
| :? DateTime as x -> [ name, x.ToString("O") ]
117-
| :? DateTimeOffset as x -> [ name, x.ToString("O") ]
118-
| :? Option<Guid> as x -> x |> toStrOpt name
119-
| _ -> [ name, (if isNull obj then null else obj.ToString()) ]
88+
if isNull obj then
89+
[]
90+
else
91+
92+
match obj with
93+
| :? array<byte> as xs -> [ name, (client.Serialize xs).Trim('\"') ] // TODO: Need to verify how servers parse byte[] from query string
94+
| :? array<bool> as xs -> xs |> toStrArray name
95+
| :? array<int32> as xs -> xs |> toStrArray name
96+
| :? array<int64> as xs -> xs |> toStrArray name
97+
| :? array<float32> as xs -> xs |> toStrArray name
98+
| :? array<double> as xs -> xs |> toStrArray name
99+
| :? array<string> as xs -> xs |> toStrArray name
100+
| :? array<DateTime> as xs -> xs |> toStrArrayDateTime name
101+
| :? array<DateTimeOffset> as xs -> xs |> toStrArrayDateTimeOffset name
102+
| :? array<Guid> as xs -> xs |> toStrArray name
103+
| :? array<Option<bool>> as xs -> xs |> toStrArrayOpt name
104+
| :? array<Option<int32>> as xs -> xs |> toStrArrayOpt name
105+
| :? array<Option<int64>> as xs -> xs |> toStrArrayOpt name
106+
| :? array<Option<float32>> as xs -> xs |> toStrArrayOpt name
107+
| :? array<Option<double>> as xs -> xs |> toStrArrayOpt name
108+
| :? array<Option<string>> as xs -> xs |> toStrArrayOpt name
109+
| :? array<Option<DateTime>> as xs -> xs |> toStrArrayDateTimeOpt name
110+
| :? array<Option<DateTimeOffset>> as xs -> xs |> toStrArrayDateTimeOffsetOpt name
111+
| :? array<Option<Guid>> as xs -> xs |> toStrArray name
112+
| :? Option<bool> as x -> x |> toStrOpt name
113+
| :? Option<int32> as x -> x |> toStrOpt name
114+
| :? Option<int64> as x -> x |> toStrOpt name
115+
| :? Option<float32> as x -> x |> toStrOpt name
116+
| :? Option<double> as x -> x |> toStrOpt name
117+
| :? Option<string> as x -> x |> toStrOpt name
118+
| :? Option<DateTime> as x -> x |> toStrDateTimeOpt name
119+
| :? Option<DateTimeOffset> as x -> x |> toStrDateTimeOffsetOpt name
120+
| :? DateTime as x -> [ name, x.ToString("O") ]
121+
| :? DateTimeOffset as x -> [ name, x.ToString("O") ]
122+
| :? Option<Guid> as x -> x |> toStrOpt name
123+
| _ -> [ name, obj.ToString() ]
120124

121125
let getPropertyNameAttribute name =
122126
{ new Reflection.CustomAttributeData() with

0 commit comments

Comments
 (0)