File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
tests/DynamicObject.Tests Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ let hashDateTime (dt : System.DateTime) : int =
15
15
16
16
17
17
let hash obj =
18
- obj.GetHashCode()
18
+ if obj = null then
19
+ 0
20
+ else
21
+ obj.GetHashCode()
19
22
20
23
let boxHashOption ( a : 'a option ) : obj =
21
24
if a.IsSome then a.Value.GetHashCode() else ( 0 ) .GetHashCode()
Original file line number Diff line number Diff line change @@ -535,6 +535,21 @@ let tests_GetHashCode = testList "GetHashCode" [
535
535
b2.SetProperty( " c" , 2 )
536
536
a2.SetProperty( " b" , b2)
537
537
Expect.equal ( a.GetHashCode()) ( a2.GetHashCode()) " Values should be equal"
538
+
539
+ testCase " null Value same key" <| fun _ ->
540
+ let a = DynamicObj()
541
+ a.SetProperty( " b" , null )
542
+ let b = DynamicObj()
543
+ b.SetProperty( " b" , null )
544
+ Expect.equal ( a.GetHashCode()) ( b.GetHashCode()) " Values should be equal"
545
+
546
+ testCase " null Value different key" <| fun _ ->
547
+ let a = DynamicObj()
548
+ a.SetProperty( " b" , null )
549
+ let b = DynamicObj()
550
+ a.SetProperty( " c" , null )
551
+ Expect.notEqual ( a.GetHashCode()) ( b.GetHashCode()) " Values should not be equal"
552
+
538
553
]
539
554
540
555
let main = testList " DynamicObj (Class)" [
Original file line number Diff line number Diff line change @@ -68,6 +68,13 @@ let tests_remove = testList "Remove" [
68
68
69
69
Expect.equal p.FirstName null " Static property should "
70
70
71
+ testCase " Remove Static HashCodeDoesNotFail" <| fun _ ->
72
+ let p = Person( " 123" , " John" )
73
+
74
+ p.RemoveProperty( " FirstName" ) |> ignore
75
+
76
+ p.GetHashCode() |> ignore
77
+
71
78
testCase " Remove Static Immutable" <| fun _ ->
72
79
let p = Person( " 123" , " John" )
73
80
let f = fun () -> p.RemoveProperty( " Id" ) |> ignore
You can’t perform that action at this time.
0 commit comments