Skip to content

Commit 1b1bb0d

Browse files
authored
Merge branch 'main' into fix-list-query-stringification
2 parents 354de2d + 07e3390 commit 1b1bb0d

12 files changed

Lines changed: 484 additions & 34 deletions

File tree

ConsumePlugin/GeneratedCapturingMock.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,13 @@ type internal TypeWithPropertiesMock =
555555
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0))
556556
this.Mem1 (arg_0_0)
557557

558-
member this.Prop1 = this.Prop1 ()
559-
member this.Prop2 = this.Prop2 ()
558+
member this.Prop1 =
559+
lock this.Calls.Prop1 (fun _ -> this.Calls.Prop1.Add ())
560+
this.Prop1 ()
561+
562+
member this.Prop2 =
563+
lock this.Calls.Prop2 (fun _ -> this.Calls.Prop2.Add ())
564+
this.Prop2 ()
560565

561566
interface System.IDisposable with
562567
member this.Dispose () : unit = this.Dispose ()

ConsumePlugin/GeneratedJson.fs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace ConsumePlugin
99

10+
open System.Collections.Generic
1011
open System.Text.Json.Serialization
1112

1213
/// Module containing JSON serializing methods for the InternalTypeNotExtensionSerial type
@@ -36,6 +37,7 @@ module internal InternalTypeNotExtensionSerial =
3637
node :> _
3738
namespace ConsumePlugin
3839

40+
open System.Collections.Generic
3941
open System.Text.Json.Serialization
4042

4143
/// Module containing JSON serializing extension members for the InternalTypeExtension type
@@ -94,6 +96,27 @@ namespace ConsumePlugin
9496
module JsonRecordType =
9597
/// Parse from a JSON node.
9698
let jsonParse (node : System.Text.Json.Nodes.JsonNode) : JsonRecordType =
99+
let arg_6 =
100+
match node.["g"] |> Option.ofObj with
101+
| None ->
102+
raise (
103+
System.Collections.Generic.KeyNotFoundException (
104+
sprintf "Required key '%s' not found on JSON object" ("g")
105+
)
106+
)
107+
| Some node ->
108+
node.AsObject ()
109+
|> Seq.map (fun kvp ->
110+
let key = (kvp.Key)
111+
let value = kvp.Value |> Option.ofObj
112+
113+
key,
114+
match value with
115+
| None -> System.Nullable ()
116+
| Some v -> v.AsValue().GetValue<System.Int32> () |> System.Nullable
117+
)
118+
|> dict
119+
97120
let arg_5 =
98121
match node.["f"] |> Option.ofObj with
99122
| None ->
@@ -194,6 +217,7 @@ module JsonRecordType =
194217
D = arg_3
195218
E = arg_4
196219
F = arg_5
220+
G = arg_6
197221
}
198222
namespace ConsumePlugin
199223

@@ -256,7 +280,12 @@ module ToGetExtensionMethodJsonParseExtension =
256280
sprintf "Required key '%s' not found on JSON object" ("whiskey")
257281
)
258282
)
259-
| Some node -> System.Numerics.BigInteger.Parse (node.ToJsonString ())
283+
| Some node ->
284+
System.Numerics.BigInteger.Parse (
285+
node.ToJsonString (),
286+
System.Globalization.NumberStyles.Float,
287+
System.Globalization.CultureInfo.InvariantCulture
288+
)
260289

261290
let arg_19 =
262291
match node.["victor"] |> Option.ofObj with
@@ -481,3 +510,28 @@ module ToGetExtensionMethodJsonParseExtension =
481510
Victor = arg_19
482511
Whiskey = arg_20
483512
}
513+
namespace ConsumePlugin
514+
515+
/// Module containing JSON parsing methods for the ContainsABigInt type
516+
[<RequireQualifiedAccess ; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
517+
module ContainsABigInt =
518+
/// Parse from a JSON node.
519+
let jsonParse (node : System.Text.Json.Nodes.JsonNode) : ContainsABigInt =
520+
let arg_0 =
521+
match node.["bigNum"] |> Option.ofObj with
522+
| None ->
523+
raise (
524+
System.Collections.Generic.KeyNotFoundException (
525+
sprintf "Required key '%s' not found on JSON object" ("bigNum")
526+
)
527+
)
528+
| Some node ->
529+
System.Numerics.BigInteger.Parse (
530+
node.ToJsonString (),
531+
System.Globalization.NumberStyles.Float,
532+
System.Globalization.CultureInfo.InvariantCulture
533+
)
534+
535+
{
536+
BigNum = arg_0
537+
}

ConsumePlugin/JsonRecord.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace ConsumePlugin
22

3+
open System.Collections.Generic
34
open System.Text.Json.Serialization
45

56
module Literals =
@@ -27,6 +28,7 @@ type JsonRecordType =
2728
D : InnerType
2829
E : string array
2930
F : int[]
31+
G : IDictionary<string, System.Nullable<int>>
3032
}
3133

3234
[<WoofWare.Myriad.Plugins.JsonParse>]
@@ -80,3 +82,9 @@ type ToGetExtensionMethod =
8082
[<RequireQualifiedAccess>]
8183
module ToGetExtensionMethod =
8284
let thisModuleWouldClash = 3
85+
86+
[<WoofWare.Myriad.Plugins.JsonParse>]
87+
type ContainsABigInt =
88+
{
89+
BigNum : bigint
90+
}

WoofWare.Myriad.Plugins.Test/TestCapturingMockGenerator/TestCapturingMockGenerator.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@ module TestCapturingMockGenerator =
3535
mock.Mem2 (3, "hi") 'a' |> shouldEqual "hiahiahi"
3636
mock.Mem3 (3, "hi") 'a' |> shouldEqual "hiahiahi"
3737

38+
[<Test>]
39+
let ``Property accesses are recorded in Calls`` () =
40+
let mock =
41+
{ TypeWithPropertiesMock.Empty () with
42+
Prop1 = fun () -> 44
43+
Prop2 = fun () -> async { return () }
44+
}
45+
46+
let itf = mock :> TypeWithProperties
47+
48+
mock.Calls.Prop1.Count |> shouldEqual 0
49+
mock.Calls.Prop2.Count |> shouldEqual 0
50+
51+
itf.Prop1 |> shouldEqual 44
52+
mock.Calls.Prop1.Count |> shouldEqual 1
53+
mock.Calls.Prop2.Count |> shouldEqual 0
54+
55+
itf.Prop1 |> shouldEqual 44
56+
mock.Calls.Prop1.Count |> shouldEqual 2
57+
58+
// note: we don't attempt to track async scheduling or anything
59+
itf.Prop2 |> ignore<_ Async>
60+
mock.Calls.Prop2.Count |> shouldEqual 1
61+
3862
[<Test>]
3963
let ``Example of use: properties`` () =
4064
let mock : TypeWithProperties =

WoofWare.Myriad.Plugins.Test/TestJsonParse/TestJsonParse.fs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace WoofWare.Myriad.Plugins.Test
22

3+
open System
4+
open System.Collections.Generic
5+
open System.Globalization
36
open System.Text.Json.Nodes
47
open ConsumePlugin
58
open NUnit.Framework
@@ -14,7 +17,7 @@ module TestJsonParse =
1417
let s =
1518
"""
1619
{
17-
"a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"},
20+
"a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}, "g": {},
1821
"e": ["something", "else"], "f": []
1922
}
2023
"""
@@ -30,6 +33,61 @@ module TestJsonParse =
3033
}
3134
E = [| "something" ; "else" |]
3235
F = [||]
36+
G = dict []
37+
}
38+
39+
let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
40+
actual |> shouldEqual expected
41+
42+
[<Test>]
43+
let ``Single example with explicit null`` () =
44+
let s =
45+
"""
46+
{
47+
"a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}, "g": {"hi": null},
48+
"e": ["something", "else"], "f": []
49+
}
50+
"""
51+
52+
let expected =
53+
{
54+
A = 3
55+
B = "hello"
56+
C = [ 6 ; 1 ]
57+
D =
58+
{
59+
Thing = "oh hi"
60+
}
61+
E = [| "something" ; "else" |]
62+
F = [||]
63+
G = dict [ "hi", Nullable () ]
64+
}
65+
66+
let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
67+
actual |> shouldEqual expected
68+
69+
[<Test>]
70+
let ``Single example, nullable provided`` () =
71+
let s =
72+
"""
73+
{
74+
"a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}, "g": {"hi": 3},
75+
"e": ["something", "else"], "f": []
76+
}
77+
"""
78+
79+
let expected =
80+
{
81+
A = 3
82+
B = "hello"
83+
C = [ 6 ; 1 ]
84+
D =
85+
{
86+
Thing = "oh hi"
87+
}
88+
E = [| "something" ; "else" |]
89+
F = [||]
90+
G = dict [ "hi", Nullable 3 ]
3391
}
3492

3593
let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
@@ -61,3 +119,21 @@ module TestJsonParse =
61119
|> JsonNode.Parse
62120
|> SomeEnum.jsonParse
63121
|> shouldEqual expected
122+
123+
[<Test>]
124+
[<NonParallelizable>]
125+
let ``Bigints are parsed in the invariant culture`` () =
126+
let currentCulture = CultureInfo.CurrentCulture
127+
let desiredCulture = CultureInfo.CreateSpecificCulture "for-test"
128+
desiredCulture.NumberFormat.NegativeSign <- "!"
129+
130+
CultureInfo.CurrentCulture <- desiredCulture
131+
132+
try
133+
"""{"bigNum": -3}"""
134+
|> JsonNode.Parse
135+
|> ContainsABigInt.jsonParse
136+
|> _.BigNum
137+
|> shouldEqual (bigint -3)
138+
finally
139+
CultureInfo.CurrentCulture <- currentCulture

0 commit comments

Comments
 (0)