diff --git a/src/DynamicObj/DynObj.fs b/src/DynamicObj/DynObj.fs
index 3b685be..08207d7 100644
--- a/src/DynamicObj/DynObj.fs
+++ b/src/DynamicObj/DynObj.fs
@@ -60,17 +60,17 @@ module DynObj =
match first.TryGetPropertyValue (kv.Key) with
| Some valueF ->
let tmp = combine (unbox valueF) (unbox valueS)
- first.SetValue(kv.Key,tmp)
- | None -> first.SetValue(kv.Key,valueS)
- | _ -> first.SetValue(kv.Key,kv.Value)
+ first.SetProperty(kv.Key,tmp)
+ | None -> first.SetProperty(kv.Key,valueS)
+ | _ -> first.SetProperty(kv.Key,kv.Value)
first
///
- /// Returns Some('TPropertyValue) when a dynamic property with the given name and type exists on the input DynamicObj, otherwise None.
+ /// Returns Some('TPropertyValue) when a dynamic (or static) property with the given name and type exists on the input, otherwise None.
///
- ///
- ///
- let inline tryGetTypedValue<'TPropertyValue> (propertyName:string) (dynObj : DynamicObj) : 'TPropertyValue option =
+ /// the name of the property to get
+ /// the input DynamicObj
+ let inline tryGetTypedPropertyValue<'TPropertyValue> (propertyName:string) (dynObj : DynamicObj) : 'TPropertyValue option =
match (dynObj.TryGetPropertyValue propertyName) with
| None -> None
| Some o ->
@@ -79,105 +79,111 @@ module DynObj =
| _ -> None
///
- /// Sets the given dynamic property name and value on the given DynamicObj.
+ /// Sets the dynamic (or static) property value with the given name on the given DynamicObj, creating a new dynamic property if none exists.
///
/// The name of the dynamic property to set
/// The value of the dynamic property to set
/// The DynamicObj to set the property on
/// This function mutates the input DynamicObj
- let setValue (propertyName:string) (propertyValue:'TPropertyValue) (dynObj : DynamicObj) =
- dynObj.SetValue(propertyName,propertyValue)
+ let setProperty (propertyName:string) (propertyValue:'TPropertyValue) (dynObj : DynamicObj) =
+ dynObj.SetProperty(propertyName,propertyValue)
///
- /// Sets the given dynamic property name and value on the given DynamicObj and returns it.
+ /// Sets the dynamic (or static) property value with the given name, creating a new dynamic property if none exists on the given DynamicObj and returns it.
///
- /// The name of the dynamic property to set
- /// The value of the dynamic property to set
+ /// The name of the property to set
+ /// The value of the property to set
/// The DynamicObj to set the property on
/// This function mutates the input DynamicObj
- let withValue (propertyName:string) (propertyValue:'TPropertyValue) (dynObj: DynamicObj) =
- setValue propertyName propertyValue dynObj
+ let withProperty (propertyName:string) (propertyValue:'TPropertyValue) (dynObj: DynamicObj) =
+ setProperty propertyName propertyValue dynObj
dynObj
///
- /// Sets the given dynamic property name and value on the given DynamicObj if the value is Some('TPropertyValue).
+ /// Sets the dynamic (or static) property value with the given name on the given DynamicObj if the value is Some('TPropertyValue), creating a new dynamic property if none exists.
/// If the given propertyValue is None, does nothing to the input DynamicObj.
///
- /// The name of the dynamic property to set
- /// The value of the dynamic property to set
+ /// The name of the property to set
+ /// The value of the property to set
/// The DynamicObj to set the property on
/// This function mutates the input DynamicObj
- let setValueOpt (propertyName: string) (propertyValue: 'TPropertyValue option) (dynObj: DynamicObj) =
+ let setOptionalProperty (propertyName: string) (propertyValue: 'TPropertyValue option) (dynObj: DynamicObj) =
match propertyValue with
- | Some pv -> dynObj |> setValue propertyName pv
+ | Some pv -> dynObj |> setProperty propertyName pv
| None -> ()
///
- /// Sets the given dynamic property name and value on the given DynamicObj if the value is Some('TPropertyValue) and returns it.
- /// If the given propertyValue is None, returns the unchanged DynamicObj.
+ /// Sets the dynamic (or static) property value with the given name on the given DynamicObj if the value is Some('TPropertyValue), creating a new dynamic property if none exists, and returns it.
+ /// If the given propertyValue is None, does nothing to the input DynamicObj.
///
- /// The name of the dynamic property to set
- /// The value of the dynamic property to set
+ /// The name of the property to set
+ /// The value of the property to set
/// The DynamicObj to set the property on
/// This function mutates the input DynamicObj
- let withValueOpt (propertyName: string) (propertyValue: 'TPropertyValue option) (dynObj: DynamicObj) =
+ let withOptionalProperty (propertyName: string) (propertyValue: 'TPropertyValue option) (dynObj: DynamicObj) =
match propertyValue with
- | Some pv -> dynObj |> withValue propertyName pv
+ | Some pv -> dynObj |> withProperty propertyName pv
| None -> dynObj
///
- /// Sets the given dynamic property name with the result of a mapping function applied to the given property value on the given DynamicObj if the value is Some('TPropertyValue).
+ /// Sets the given dynamic (or static) property with the result of a mapping function applied to the given property value on the given DynamicObj if the value is Some('TPropertyValue).
/// If the given propertyValue is None, does nothing to the input DynamicObj.
///
- /// The name of the dynamic property to set
- /// The value of the dynamic property to set
+ /// The name of the property to set
+ /// The value of the property to set
/// A function to apply to the property value before setting it on the DynamicObj
/// The DynamicObj to set the property on
/// This function mutates the input DynamicObj
- let setValueOptBy (propertyName: string) (propertyValue: 'TPropertyValue option) (mapping: 'TPropertyValue -> 'UPropertyValue) (dynObj: DynamicObj) =
+ let setOptionalPropertyBy (propertyName: string) (propertyValue: 'TPropertyValue option) (mapping: 'TPropertyValue -> 'UPropertyValue) (dynObj: DynamicObj) =
match propertyValue with
- | Some pv -> dynObj |> setValue propertyName (mapping pv)
+ | Some pv -> dynObj |> setProperty propertyName (mapping pv)
| None -> ()
///
- /// Sets the given dynamic property name with the result of a mapping function applied to the given property value on the given DynamicObj if the value is Some('TPropertyValue) and returns it.
+ /// Sets the given dynamic (or static) property with the result of a mapping function applied to the given property value on the given DynamicObj if the value is Some('TPropertyValue) and returns it.
/// If the given propertyValue is None, returns the unchanged DynamicObj.
///
- /// The name of the dynamic property to set
- /// The value of the dynamic property to set
+ /// The name of the property to set
+ /// The value of the property to set
/// A function to apply to the property value before setting it on the DynamicObj
/// The DynamicObj to set the property on
/// This function mutates the input DynamicObj
- let withValueOptBy (propertyName: string) (propertyValue: 'TPropertyValue option) (mapping: 'TPropertyValue -> 'UPropertyValue) (dynObj: DynamicObj) =
+ let withOptionalPropertyBy (propertyName: string) (propertyValue: 'TPropertyValue option) (mapping: 'TPropertyValue -> 'UPropertyValue) (dynObj: DynamicObj) =
match propertyValue with
- | Some pv -> dynObj |> withValue propertyName (mapping pv)
+ | Some pv -> dynObj |> withProperty propertyName (mapping pv)
| None -> dynObj
///
- /// Returns Some(boxed value) if the DynamicObj contains a dynamic property with the given name, and None otherwise.
+ /// Returns Some(boxed property value) if a dynamic (or static) property with the given name exists on the input, otherwise None.
///
- /// The name of the dynamic property to get
+ /// The name of the property to get
/// The DynamicObj to get the property from
- let tryGetValue (propertyName: string) (dynObj: DynamicObj) =
+ let tryGetPropertyValue (propertyName: string) (dynObj: DynamicObj) =
dynObj.TryGetPropertyValue propertyName
///
/// Removes any dynamic property with the given name from the input DynamicObj.
+ /// If the property is static and mutable, it will be set to null.
+ /// Static immutable properties cannot be removed.
///
- /// The name of the dynamic property to remove
+ /// The name of the property to remove
/// The DynamicObj to remove the property from
/// This function mutates the input DynamicObj
- let remove (propertyName: string) (dynObj: DynamicObj) =
- DynamicObj.remove (dynObj, propertyName) |> ignore
+ /// Thrown if the dynamic property does not exist
+ let removeProperty (propertyName: string) (dynObj: DynamicObj) =
+ dynObj.RemoveProperty(propertyName) |> ignore
///
- /// Returns the input DynamicObj with any dynamic property with the given name removed.
+ /// Removes any dynamic property with the given name from the input DynamicObj and returns it.
+ /// If the property is static and mutable, it will be set to null.
+ /// Static immutable properties cannot be removed.
///
- /// The name of the dynamic property to remove
+ /// The name of the property to remove
/// The DynamicObj to remove the property from
/// This function mutates the input DynamicObj
+ /// Thrown if the dynamic property does not exist
let withoutProperty(propertyName: string) (dynObj: DynamicObj) =
- dynObj |> remove propertyName
+ dynObj |> removeProperty propertyName
dynObj
///
diff --git a/src/DynamicObj/DynamicObj.fs b/src/DynamicObj/DynamicObj.fs
index d1acbbf..991fa18 100644
--- a/src/DynamicObj/DynamicObj.fs
+++ b/src/DynamicObj/DynamicObj.fs
@@ -30,22 +30,22 @@ type DynamicObj() =
obj
///
- ///
+ /// Returns Some(PropertyHelper) if a static property with the given name exists, otherwise None.
///
- ///
+ /// The name of the property to get the PropertyHelper for
member this.TryGetStaticPropertyHelper (propertyName: string) : PropertyHelper option =
ReflectionUtils.tryGetStaticPropertyInfo this propertyName
///
- ///
+ /// Returns Some(PropertyHelper) if a dynamic property with the given name exists, otherwise None.
///
- ///
+ /// The name of the property to get the PropertyHelper for
member this.TryGetDynamicPropertyHelper (propertyName: string) : PropertyHelper option =
#if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT
- FableJS.tryGetDynamicPropertyHelper this name
+ FableJS.tryGetDynamicPropertyHelper this propertyName
#endif
#if FABLE_COMPILER_PYTHON
- FablePy.tryGetDynamicPropertyHelper this name
+ FablePy.tryGetDynamicPropertyHelper this propertyName
#endif
#if !FABLE_COMPILER
match properties.TryGetValue propertyName with
@@ -64,9 +64,9 @@ type DynamicObj() =
#endif
///
- ///
+ /// Returns Some(PropertyHelper) if a property (static or dynamic) with the given name exists, otherwise None.
///
- ///
+ /// The name of the property to get the PropertyHelper for
member this.TryGetPropertyHelper (propertyName: string) : PropertyHelper option =
match this.TryGetStaticPropertyHelper propertyName with
| Some pi -> Some pi
@@ -85,11 +85,11 @@ type DynamicObj() =
/// Returns the boxed property value of the dynamic (or static) property with the given name.
///
/// the name of the property to get
- /// Thrown if the dynamic property does not exist
+ /// Thrown if no dynamic or static property with the given name exists
member this.GetPropertyValue (propertyName: string) =
match this.TryGetPropertyValue(propertyName) with
| Some value -> value
- | None -> raise <| System.MissingMemberException($"Property \"{propertyName}\" does not exist on object.")
+ | None -> raise <| System.MissingMemberException($"No dynamic or static property \"{propertyName}\" does exist on object.")
#if !FABLE_COMPILER
@@ -106,7 +106,7 @@ type DynamicObj() =
| None -> None
| Some o ->
match o with
- | :? 'a as o -> o |> Some
+ | :? 'TPropertyValue as o -> o |> Some
| _ -> None
#endif
@@ -114,9 +114,9 @@ type DynamicObj() =
///
/// Sets the dynamic (or static) property value with the given name, creating a new dynamic property if none exists.
///
- ///
- ///
- member this.SetPropertyValue (
+ /// the name of the property to set
+ /// the value of the property to set
+ member this.SetProperty (
propertyName: string,
propertyValue: obj
) =
@@ -129,10 +129,10 @@ type DynamicObj() =
failwith $"Cannot set value for static, immutable property \"{propertyName}\""
| None ->
#if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT
- FableJS.setPropertyValue this name value
+ FableJS.setPropertyValue this propertyName propertyValue
#endif
#if FABLE_COMPILER_PYTHON
- FablePy.setPropertyValue this name value
+ FablePy.setPropertyValue this propertyName propertyValue
#endif
#if !FABLE_COMPILER
// Next check the Properties collection for member
@@ -146,7 +146,7 @@ type DynamicObj() =
/// If the property is static and mutable, it will be set to null.
/// Static immutable properties cannot be removed.
///
- ///
+ /// the name of the property to remove
/// Thrown if the dynamic property does not exist
member this.RemoveProperty (propertyName: string) =
match this.TryGetPropertyHelper propertyName with
@@ -158,9 +158,11 @@ type DynamicObj() =
| None -> false
///
- ///
+ /// Returns PropertyHelpers for all dynamic properties of the DynamicObj.
+ ///
+ /// When includeInstanceProperties is set to true, instance properties (= 'static' properties on the class) are included in the result.
///
- ///
+ /// whether to include instance properties (= 'static' properties on the class)
member this.GetPropertyHelpers (includeInstanceProperties: bool) =
#if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT
FableJS.getPropertyHelpers this
@@ -193,8 +195,12 @@ type DynamicObj() =
#endif
|> Seq.filter (fun p -> p.Name.ToLower() <> "properties")
- /// Returns both instance and dynamic properties when passed true, only dynamic properties otherwise.
- /// Properties are returned as a key value pair of the member names and the boxed values
+ ///
+ /// Returns a sequence of all dynamic properties as a key value pair of the property names and the boxed property values.
+ ///
+ /// When includeInstanceProperties is set to true, instance properties (= 'static' properties on the class) are included in the result.
+ ///
+ /// whether to include instance properties (= 'static' properties on the class)
member this.GetProperties includeInstanceProperties : seq> =
this.GetPropertyHelpers(includeInstanceProperties)
|> Seq.choose (fun kv ->
@@ -204,43 +210,63 @@ type DynamicObj() =
None
)
+ ///
+ /// Returns a sequence of all dynamic property names.
+ ///
+ /// When includeInstanceProperties is set to true, instance properties (= 'static' properties on the class) are included in the result.
+ ///
+ ///
+ member this.GetPropertyNames(includeInstanceProperties) =
+ this.GetProperties(includeInstanceProperties)
+ |> Seq.map (fun kv -> kv.Key)
+
+ ///
/// Copies all dynamic members of the DynamicObj to the target DynamicObj.
+ ///
+ /// If overWrite is set to true, existing properties on the target object will be overwritten.
+ ///
+ /// Note that this method will not perform nested checks, e.g. if a property is a DynamicObj itself, it will not be copied recursively.
+ ///
+ /// The target object to copy dynamic members to
+ /// Whether existing properties on the target object will be overwritten
member this.CopyDynamicPropertiesTo(target:#DynamicObj, ?overWrite) =
- let overWrite = Option.defaultValue false overWrite
+ let overWrite = defaultArg overWrite false
this.GetProperties(false)
|> Seq.iter (fun kv ->
match target.TryGetPropertyHelper kv.Key with
| Some pi when overWrite -> pi.SetValue target kv.Value
| Some _ -> failwith $"Property \"{kv.Key}\" already exists on target object and overWrite was not set to true."
- | None -> target.SetPropertyValue(kv.Key,kv.Value)
+ | None -> target.SetProperty(kv.Key,kv.Value)
)
+ ///
/// Returns a new DynamicObj with only the dynamic properties of the original DynamicObj (sans instance properties).
+ ///
member this.CopyDynamicProperties() =
let target = DynamicObj()
this.CopyDynamicPropertiesTo(target)
target
- member this.GetPropertyNames(includeInstanceProperties) =
- this.GetProperties(includeInstanceProperties)
- |> Seq.map (fun kv -> kv.Key)
-
///
- /// Operator to access a dynamic member by name
+ /// Operator to access a property by name
+ ///
+ /// This method is not Fable-compatible and can therefore not be used in code that will be transpiled.
///
- /// This operator is not Fable-compatible
+ /// This method is not Fable-compatible and can therefore not be used in code that will be transpiled.
static member (?) (lookup:#DynamicObj,name:string) =
match lookup.TryGetPropertyValue name with
| Some(value) -> value
| None -> raise <| System.MemberAccessException()
///
- /// Operator to set a dynamic member
+ /// Operator to set a property value
+ ///
+ /// This method is not Fable-compatible and can therefore not be used in code that will be transpiled.
///
- /// This operator is not Fable-compatible
+ /// This method is not Fable-compatible and can therefore not be used in code that will be transpiled.
static member (?<-) (lookup:#DynamicObj,name:string,value:'v) =
- lookup.SetPropertyValue (name,value)
+ lookup.SetProperty (name,value)
override this.GetHashCode () =
this.GetProperties(true)
diff --git a/tests/DynamicObject.Tests/DynObj.fs b/tests/DynamicObject.Tests/DynObj.fs
index ed4340d..bcd223c 100644
--- a/tests/DynamicObject.Tests/DynObj.fs
+++ b/tests/DynamicObject.Tests/DynObj.fs
@@ -11,8 +11,8 @@ let tests_ofDict = ptestList "ofDict" [
d.Add("key1", box 1)
d.Add("key2", box 2)
let dyn = DynObj.ofDict d
- Expect.equal (dyn.GetValue("key1")) 1 "Value should be 1"
- Expect.equal (dyn.GetValue("key2")) 2 "Value should be 2"
+ Expect.equal (dyn.GetPropertyValue("key1")) 1 "Value should be 1"
+ Expect.equal (dyn.GetPropertyValue("key2")) 2 "Value should be 2"
]
let tests_ofSeq = ptestList "ofSeq" [
@@ -23,8 +23,8 @@ let tests_ofSeq = ptestList "ofSeq" [
"key2", box 2
}
let dyn = DynObj.ofSeq d
- Expect.equal (dyn.GetValue("key1")) 1 "Value should be 1"
- Expect.equal (dyn.GetValue("key2")) 2 "Value should be 2"
+ Expect.equal (dyn.GetPropertyValue("key1")) 1 "Value should be 1"
+ Expect.equal (dyn.GetPropertyValue("key2")) 2 "Value should be 2"
]
let tests_ofList = ptestList "ofList" [
@@ -34,8 +34,8 @@ let tests_ofList = ptestList "ofList" [
"key2", box 2
]
let dyn = DynObj.ofList d
- Expect.equal (dyn.GetValue("key1")) 1 "Value should be 1"
- Expect.equal (dyn.GetValue("key2")) 2 "Value should be 2"
+ Expect.equal (dyn.GetPropertyValue("key1")) 1 "Value should be 1"
+ Expect.equal (dyn.GetPropertyValue("key2")) 2 "Value should be 2"
]
let tests_ofArray = ptestList "ofArray" [
@@ -45,8 +45,8 @@ let tests_ofArray = ptestList "ofArray" [
"key2", box 2
|]
let dyn = DynObj.ofArray d
- Expect.equal (dyn.GetValue("key1")) 1 "Value should be 1"
- Expect.equal (dyn.GetValue("key2")) 2 "Value should be 2"
+ Expect.equal (dyn.GetPropertyValue("key1")) 1 "Value should be 1"
+ Expect.equal (dyn.GetPropertyValue("key2")) 2 "Value should be 2"
]
let tests_combine = testList "combine" [
@@ -54,64 +54,64 @@ let tests_combine = testList "combine" [
testCase "Combine flat DOs" <| fun _ ->
let target = DynamicObj()
- target.SetValue("target-unique", [42])
- target.SetValue("will-be-overridden", "WAS_NOT_OVERRIDDEN!")
+ target.SetProperty("target-unique", [42])
+ target.SetProperty("will-be-overridden", "WAS_NOT_OVERRIDDEN!")
let source = DynamicObj()
- source.SetValue("source-unique", [42; 32])
- source.SetValue("will-be-overridden", "WAS_OVERRIDDEN =)")
+ source.SetProperty("source-unique", [42; 32])
+ source.SetProperty("will-be-overridden", "WAS_OVERRIDDEN =)")
let combined = DynObj.combine target source
let expected = DynamicObj()
- expected.SetValue("target-unique", [42])
- expected.SetValue("source-unique", [42; 32])
- expected.SetValue("will-be-overridden", "WAS_OVERRIDDEN =)")
+ expected.SetProperty("target-unique", [42])
+ expected.SetProperty("source-unique", [42; 32])
+ expected.SetProperty("will-be-overridden", "WAS_OVERRIDDEN =)")
Expect.equal expected combined "Combine flat DOs failed"
testCase "Combine nested DOs" <| fun _ ->
let target = DynamicObj()
- target.SetValue("target-unique", 1337)
- target.SetValue("will-be-overridden", -42)
+ target.SetProperty("target-unique", 1337)
+ target.SetProperty("will-be-overridden", -42)
let something2BeCombined = DynamicObj()
- something2BeCombined.SetValue("inner","I Am")
+ something2BeCombined.SetProperty("inner","I Am")
let something2BeOverriden = DynamicObj()
- something2BeOverriden.SetValue("inner","NOT_OVERRIDDEN")
- target.SetValue("nested-will-be-combined", something2BeCombined)
- target.SetValue("nested-will-be-overridden", something2BeOverriden)
+ something2BeOverriden.SetProperty("inner","NOT_OVERRIDDEN")
+ target.SetProperty("nested-will-be-combined", something2BeCombined)
+ target.SetProperty("nested-will-be-overridden", something2BeOverriden)
let source = DynamicObj()
- source.SetValue("source-unique", 69)
- source.SetValue("will-be-overridden", "WAS_OVERRIDDEN")
+ source.SetProperty("source-unique", 69)
+ source.SetProperty("will-be-overridden", "WAS_OVERRIDDEN")
let alsoSomething2BeCombined = DynamicObj()
- alsoSomething2BeCombined.SetValue("inner_combined","Complete")
- source.SetValue("nested-will-be-combined", alsoSomething2BeCombined)
- source.SetValue("nested-will-be-overridden", "WAS_OVERRIDDEN")
+ alsoSomething2BeCombined.SetProperty("inner_combined","Complete")
+ source.SetProperty("nested-will-be-combined", alsoSomething2BeCombined)
+ source.SetProperty("nested-will-be-overridden", "WAS_OVERRIDDEN")
let combined = DynObj.combine target source
let expected = DynamicObj()
- expected.SetValue("source-unique", 69)
- expected.SetValue("target-unique", 1337)
- expected.SetValue("will-be-overridden", "WAS_OVERRIDDEN")
- expected.SetValue("nested-will-be-overridden", "WAS_OVERRIDDEN")
- expected.SetValue("nested-will-be-combined",
+ expected.SetProperty("source-unique", 69)
+ expected.SetProperty("target-unique", 1337)
+ expected.SetProperty("will-be-overridden", "WAS_OVERRIDDEN")
+ expected.SetProperty("nested-will-be-overridden", "WAS_OVERRIDDEN")
+ expected.SetProperty("nested-will-be-combined",
let inner = DynamicObj()
- inner.SetValue("inner","I Am")
- inner.SetValue("inner_combined","Complete")
+ inner.SetProperty("inner","I Am")
+ inner.SetProperty("inner_combined","Complete")
inner
)
Expect.equal expected combined "Combine nested DOs failed"
]
-let tests_tryGetTypedValue = testList "tryGetTypedValue" [
+let tests_tryGetTypedPropertyValue = testList "tryGetTypedPropertyValue" [
testCase "typeof" <| fun _ ->
let a = typeof
@@ -119,81 +119,81 @@ let tests_tryGetTypedValue = testList "tryGetTypedValue" [
testCase "NonExisting" <| fun _ ->
let a = DynamicObj()
- let b = DynObj.tryGetTypedValue "a" a
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.isNone b "Value should not exist"
testCase "Correct Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", 1)
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.equal b (Some 1) "Value should be 1"
testCase "Incorrect Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", "1")
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.isNone b "Value should not be an int"
testCase "Correct String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", "1")
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.equal b (Some "1") "Value should be '1'"
testCase "Incorrect String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", 1)
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.isNone b "Value should not be a string"
testCase "Correct List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", [1; 2; 3])
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.equal b (Some [1; 2; 3]) "Value should be [1; 2; 3]"
ptestCase "Incorrect List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", [1; 2; 3])
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.isNone b "Value should not be a string list"
testCase "Correct DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
- let c = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", b)
+ let c = DynObj.tryGetTypedPropertyValue "a" a
Expect.equal c (Some b) "Value should be a DynamicObj"
testCase "Incorrect DynamicObj" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = DynObj.tryGetTypedValue "a" a
+ a.SetProperty("a", 1)
+ let b = DynObj.tryGetTypedPropertyValue "a" a
Expect.isNone b "Value should not be a DynamicObj"
]
-let tests_setValue = testList "setValue" [
+let tests_setProperty = testList "setProperty" [
testCase "Same String" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValue "aaa" 5
+ a |> DynObj.setProperty "aaa" 5
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 5
+ b |> DynObj.setProperty "aaa" 5
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Different Strings" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValue "aaa" 1212
+ a |> DynObj.setProperty "aaa" 1212
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 5
+ b |> DynObj.setProperty "aaa" 5
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should not be equal"
testCase "String only on one" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 5
+ b |> DynObj.setProperty "aaa" 5
Expect.notEqual a b "Values should not be equal"
Expect.notEqual b a "Values should not be equal (Reversed equality)"
@@ -201,8 +201,8 @@ let tests_setValue = testList "setValue" [
testCase "Same lists different keys" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- a |> DynObj.setValue "quack!" [1; 2; 3]
- b |> DynObj.setValue "quack!1" [1; 2; 3]
+ a |> DynObj.setProperty "quack!" [1; 2; 3]
+ b |> DynObj.setProperty "quack!1" [1; 2; 3]
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should not be equal"
@@ -210,8 +210,8 @@ let tests_setValue = testList "setValue" [
testCase "Different lists" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- a |> DynObj.setValue "quack!" [1; 2; 3]
- b |> DynObj.setValue "quack!" [1; 2; 3; 4; 34]
+ a |> DynObj.setProperty "quack!" [1; 2; 3]
+ b |> DynObj.setProperty "quack!" [1; 2; 3; 4; 34]
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should not be equal"
@@ -222,11 +222,11 @@ let tests_setValue = testList "setValue" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a' |> DynObj.setValue "quack!" [1; 2; 3]
- b' |> DynObj.setValue "quack!" [1; 2; 3]
+ a' |> DynObj.setProperty "quack!" [1; 2; 3]
+ b' |> DynObj.setProperty "quack!" [1; 2; 3]
- a |> DynObj.setValue "aaa" a'
- b |> DynObj.setValue "aaa" b'
+ a |> DynObj.setProperty "aaa" a'
+ b |> DynObj.setProperty "aaa" b'
Expect.equal a' b' "New Values should be equal"
Expect.equal a b "Old Values should be equal"
@@ -239,51 +239,51 @@ let tests_setValue = testList "setValue" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a' |> DynObj.setValue "quack!" [1; 2; 3]
- b' |> DynObj.setValue "quack!" [1; 2; 3]
+ a' |> DynObj.setProperty "quack!" [1; 2; 3]
+ b' |> DynObj.setProperty "quack!" [1; 2; 3]
- a |> DynObj.setValue "aaa" a'
- b |> DynObj.setValue "aaa1" b'
+ a |> DynObj.setProperty "aaa" a'
+ b |> DynObj.setProperty "aaa1" b'
Expect.equal a' b' "New Values should be equal"
Expect.notEqual a b "Old Values should not be equal"
Expect.equal (a'.GetHashCode()) (b'.GetHashCode()) "New Hash codes should be equal"
]
-let tests_withValue = testList "withValue" [
+let tests_withProperty = testList "withProperty" [
testCase "Same String" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "aaa" 5
- |> DynObj.withValue "aaaa" 6
+ |> DynObj.withProperty "aaa" 5
+ |> DynObj.withProperty "aaaa" 6
let b =
DynamicObj ()
- |> DynObj.withValue "aaa" 5
- |> DynObj.withValue "aaaa" 6
+ |> DynObj.withProperty "aaa" 5
+ |> DynObj.withProperty "aaaa" 6
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Different Strings" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "111" 5
- |> DynObj.withValue "1111" 6
+ |> DynObj.withProperty "111" 5
+ |> DynObj.withProperty "1111" 6
let b =
DynamicObj ()
- |> DynObj.withValue "aaa" 5
- |> DynObj.withValue "aaaa" 6
+ |> DynObj.withProperty "aaa" 5
+ |> DynObj.withProperty "aaaa" 6
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should not be equal"
testCase "String different amounts" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "aaa" 5
+ |> DynObj.withProperty "aaa" 5
let b =
DynamicObj ()
- |> DynObj.withValue "aaa" 5
- |> DynObj.withValue "aaaa" 6
+ |> DynObj.withProperty "aaa" 5
+ |> DynObj.withProperty "aaaa" 6
Expect.notEqual a b "Values should not be equal"
Expect.notEqual b a "Values should not be equal (Reversed equality)"
@@ -292,12 +292,12 @@ let tests_withValue = testList "withValue" [
testCase "Same lists different keys" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aa" [1; 2; 3]
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aa" [1; 2; 3]
let b =
DynamicObj ()
- |> DynObj.withValue "aa" [1; 2; 3]
- |> DynObj.withValue "bbb" [1; 2; 3]
+ |> DynObj.withProperty "aa" [1; 2; 3]
+ |> DynObj.withProperty "bbb" [1; 2; 3]
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should not be equal"
@@ -305,8 +305,8 @@ let tests_withValue = testList "withValue" [
testCase "Different lists" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- a |> DynObj.setValue "quack!" [1; 2; 3]
- b |> DynObj.setValue "quack!" [1; 2; 3; 4; 34]
+ a |> DynObj.setProperty "quack!" [1; 2; 3]
+ b |> DynObj.setProperty "quack!" [1; 2; 3; 4; 34]
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should not be equal"
@@ -315,8 +315,8 @@ let tests_withValue = testList "withValue" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- let a = DynamicObj () |> DynObj.withValue "aaa" (a' |> DynObj.withValue "quack!" [1; 2; 3])
- let b = DynamicObj () |> DynObj.withValue "aaa" (b' |> DynObj.withValue "quack!" [1; 2; 3])
+ let a = DynamicObj () |> DynObj.withProperty "aaa" (a' |> DynObj.withProperty "quack!" [1; 2; 3])
+ let b = DynamicObj () |> DynObj.withProperty "aaa" (b' |> DynObj.withProperty "quack!" [1; 2; 3])
Expect.equal a' b' "New Values should be equal"
Expect.equal a b "Old Values should be equal"
@@ -327,210 +327,210 @@ let tests_withValue = testList "withValue" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- let a = DynamicObj () |> DynObj.withValue "aaa" (a' |> DynObj.withValue "quack!" [1; 2; 3])
- let b = DynamicObj () |> DynObj.withValue "aaa1" (b' |> DynObj.withValue "quack!" [1; 2; 3])
+ let a = DynamicObj () |> DynObj.withProperty "aaa" (a' |> DynObj.withProperty "quack!" [1; 2; 3])
+ let b = DynamicObj () |> DynObj.withProperty "aaa1" (b' |> DynObj.withProperty "quack!" [1; 2; 3])
Expect.equal a' b' "New Values should be equal"
Expect.notEqual a b "Old Values should not be equal"
Expect.equal (a'.GetHashCode()) (b'.GetHashCode()) "New Hash codes should be equal"
]
-let tests_setValueOpt = testList "setValueOpt" [
+let tests_setOptionalProperty = testList "setOptionalProperty" [
testCase "Some" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValueOpt "aaa" (Some 5)
+ a |> DynObj.setOptionalProperty "aaa" (Some 5)
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 5
+ b |> DynObj.setProperty "aaa" 5
Expect.equal a b "Values should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 5 "Values should be equal"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 5 "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "None" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValueOpt "aaa" None
+ a |> DynObj.setOptionalProperty "aaa" None
let b = DynamicObj ()
Expect.equal a b "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaa" |> Option.get |> ignore) "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get |> ignore) "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Some and None" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValueOpt "aaa" (Some 5)
- a |> DynObj.setValueOpt "aaaa" None
+ a |> DynObj.setOptionalProperty "aaa" (Some 5)
+ a |> DynObj.setOptionalProperty "aaaa" None
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 5
- b |> DynObj.setValue "aaaa" 5
+ b |> DynObj.setProperty "aaa" 5
+ b |> DynObj.setProperty "aaaa" 5
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 5 "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaaa" |> Option.get |> ignore) "Values should not exist"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 5 "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaaa" |> Option.get |> ignore) "Values should not exist"
]
-let tests_withValueOpt = testList "withValueOpt" [
+let tests_withOptionalProperty = testList "withOptionalProperty" [
testCase "Some" <| fun _ ->
- let a = DynamicObj () |> DynObj.withValueOpt "aaa" (Some 5)
- let b = DynamicObj () |> DynObj.withValue "aaa" 5
+ let a = DynamicObj () |> DynObj.withOptionalProperty "aaa" (Some 5)
+ let b = DynamicObj () |> DynObj.withProperty "aaa" 5
Expect.equal a b "Values should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 5 "Values should be equal"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 5 "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "None" <| fun _ ->
- let a = DynamicObj () |> DynObj.withValueOpt "aaa" None
+ let a = DynamicObj () |> DynObj.withOptionalProperty "aaa" None
let b = DynamicObj ()
Expect.equal a b "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaa" |> Option.get |> ignore) "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get |> ignore) "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Some and None" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValueOpt "aaa" (Some 5)
- |> DynObj.withValueOpt "aaaa" None
+ |> DynObj.withOptionalProperty "aaa" (Some 5)
+ |> DynObj.withOptionalProperty "aaaa" None
let b =
DynamicObj ()
- |> DynObj.withValue "aaa" 5
- |> DynObj.withValue "aaaa" 5
+ |> DynObj.withProperty "aaa" 5
+ |> DynObj.withProperty "aaaa" 5
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 5 "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaaa" |> Option.get |> ignore) "Values should not exist"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 5 "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaaa" |> Option.get |> ignore) "Values should not exist"
]
-let tests_setValueOptBy = testList "setValueOptBy" [
+let tests_setOptionalPropertyBy = testList "setOptionalPropertyBy" [
testCase "Some" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValueOptBy "aaa" (Some 5) (fun x -> x + 1)
+ a |> DynObj.setOptionalPropertyBy "aaa" (Some 5) (fun x -> x + 1)
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 6
+ b |> DynObj.setProperty "aaa" 6
Expect.equal a b "Values should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 6 "Values should be equal"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 6 "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "None" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValueOptBy "aaa" None id
+ a |> DynObj.setOptionalPropertyBy "aaa" None id
let b = DynamicObj ()
Expect.equal a b "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaa" |> Option.get |> ignore) "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get |> ignore) "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Some and None" <| fun _ ->
let a = DynamicObj ()
- a |> DynObj.setValueOptBy "aaa" (Some 5) (fun x -> x + 1)
- a |> DynObj.setValueOptBy "aaaa" None id
+ a |> DynObj.setOptionalPropertyBy "aaa" (Some 5) (fun x -> x + 1)
+ a |> DynObj.setOptionalPropertyBy "aaaa" None id
let b = DynamicObj ()
- b |> DynObj.setValue "aaa" 6
- b |> DynObj.setValue "aaaa" 6
+ b |> DynObj.setProperty "aaa" 6
+ b |> DynObj.setProperty "aaaa" 6
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 6 "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaaa" |> Option.get |> ignore) "Values should not exist"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 6 "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaaa" |> Option.get |> ignore) "Values should not exist"
]
-let tests_withValueOptBy = testList "withValueOptBy" [
+let tests_withOptionalPropertyBy = testList "withOptionalPropertyBy" [
testCase "Some" <| fun _ ->
- let a = DynamicObj () |> DynObj.withValueOptBy "aaa" (Some 5) (fun x -> x+1)
- let b = DynamicObj () |> DynObj.withValue "aaa" 6
+ let a = DynamicObj () |> DynObj.withOptionalPropertyBy "aaa" (Some 5) (fun x -> x+1)
+ let b = DynamicObj () |> DynObj.withProperty "aaa" 6
Expect.equal a b "Values should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 6 "Values should be equal"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 6 "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "None" <| fun _ ->
- let a = DynamicObj () |> DynObj.withValueOptBy "aaa" None id
+ let a = DynamicObj () |> DynObj.withOptionalPropertyBy "aaa" None id
let b = DynamicObj ()
Expect.equal a b "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaa" |> Option.get |> ignore) "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get |> ignore) "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Some and None" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValueOptBy "aaa" (Some 5) (fun x -> x+1)
- |> DynObj.withValueOptBy "aaaa" None id
+ |> DynObj.withOptionalPropertyBy "aaa" (Some 5) (fun x -> x+1)
+ |> DynObj.withOptionalPropertyBy "aaaa" None id
let b =
DynamicObj ()
- |> DynObj.withValue "aaa" 6
- |> DynObj.withValue "aaaa" 6
+ |> DynObj.withProperty "aaa" 6
+ |> DynObj.withProperty "aaaa" 6
Expect.notEqual a b "Values should not be equal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
- Expect.equal (a |> DynObj.tryGetTypedValue "aaa" |> Option.get) 6 "Values should be equal"
- Expect.throws (fun _ -> a |> DynObj.tryGetTypedValue "aaaa" |> Option.get |> ignore) "Values should not exist"
+ Expect.equal (a |> DynObj.tryGetTypedPropertyValue "aaa" |> Option.get) 6 "Values should be equal"
+ Expect.throws (fun _ -> a |> DynObj.tryGetTypedPropertyValue "aaaa" |> Option.get |> ignore) "Values should not exist"
]
-let tests_tryGetValue = testList "tryGetValue" [
+let tests_tryGetPropertyValue = testList "tryGetPropertyValue" [
testCase "NonExisting" <| fun _ ->
let a = DynamicObj()
- let b = a |> DynObj.tryGetValue "a"
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.isNone b "Value should not exist"
testCase "Correct boxed Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", 1)
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (b) (Some (box 1)) "Value should be 1"
testCase "Correct unboxed Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", 1)
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (b |> Option.map unbox) (Some 1) "Value should be 1"
testCase "Correct boxed String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", "1")
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (b) (Some (box "1")) "Value should be '1'"
testCase "Correct unboxed String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", "1")
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (b |> Option.map unbox) (Some "1") "Value should be '1'"
testCase "Correct boxed List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", [1; 2; 3])
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (b) (Some (box [1; 2; 3])) "Value should be [1; 2; 3]"
testCase "Correct unboxed List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", [1; 2; 3])
+ let b = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (b |> Option.map unbox) (Some [1; 2; 3]) "Value should be [1; 2; 3]"
testCase "Correct boxed DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
- let c = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", b)
+ let c = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (c) (Some (box b)) "Value should be a DynamicObj"
testCase "Correct unboxed DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
- let c = a |> DynObj.tryGetValue "a"
+ a.SetProperty("a", b)
+ let c = a |> DynObj.tryGetPropertyValue "a"
Expect.equal (c |> Option.map unbox) (Some b) "Value should be a DynamicObj"
]
-let tests_remove = testList "remove" [
+let tests_removeProperty = testList "removeProperty" [
testCase "Remove" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- a.SetValue("quack!", "hello")
+ a.SetProperty("quack!", "hello")
- a |> DynObj.remove "quack!" |> ignore
+ a |> DynObj.removeProperty "quack!" |> ignore
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -539,10 +539,10 @@ let tests_remove = testList "remove" [
let a = DynamicObj ()
let b = DynamicObj ()
- a.SetValue("quack!", "hello")
- b.SetValue("quack!", "hello")
+ a.SetProperty("quack!", "hello")
+ b.SetProperty("quack!", "hello")
- a |> DynObj.remove "quecky!" |> ignore
+ a |> DynObj.removeProperty "quecky!" |> ignore
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -551,10 +551,10 @@ let tests_remove = testList "remove" [
let a = DynamicObj ()
let b = DynamicObj ()
- a.SetValue("quack!", "hello")
- b.SetValue("quack!", "hello")
+ a.SetProperty("quack!", "hello")
+ b.SetProperty("quack!", "hello")
- a |> DynObj.remove "quack!" |> ignore
+ a |> DynObj.removeProperty "quack!" |> ignore
Expect.notEqual a b "Values should be unequal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be unequal"
@@ -565,12 +565,12 @@ let tests_remove = testList "remove" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- a |> DynObj.remove "quack!" |> ignore
- b.SetValue("aaa", b')
+ a.SetProperty("aaa", a')
+ a |> DynObj.removeProperty "quack!" |> ignore
+ b.SetProperty("aaa", b')
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -581,12 +581,12 @@ let tests_remove = testList "remove" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- a' |> DynObj.remove "quack!" |> ignore
- b.SetValue("aaa", b')
+ a.SetProperty("aaa", a')
+ a' |> DynObj.removeProperty "quack!" |> ignore
+ b.SetProperty("aaa", b')
Expect.notEqual a b "Values should be unequal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be unequal"
@@ -597,26 +597,25 @@ let tests_remove = testList "remove" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- a |> DynObj.remove "quack!" |> ignore
- b.SetValue("aaa", b')
- b |> DynObj.remove "quack!" |> ignore
+ a.SetProperty("aaa", a')
+ a |> DynObj.removeProperty "quack!" |> ignore
+ b.SetProperty("aaa", b')
+ b |> DynObj.removeProperty "quack!" |> ignore
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
]
-
let tests_withoutProperty = testList "withoutProperty" [
testCase "Remove" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "quack!" "hello"
+ |> DynObj.withProperty "quack!" "hello"
|> DynObj.withoutProperty "quack!"
let b = DynamicObj ()
@@ -628,10 +627,10 @@ let tests_withoutProperty = testList "withoutProperty" [
testCase "Remove Non-Existing" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "quack!" "hello"
+ |> DynObj.withProperty "quack!" "hello"
|> DynObj.withoutProperty "quecky!"
- let b = DynamicObj () |> DynObj.withValue "quack!" "hello"
+ let b = DynamicObj () |> DynObj.withProperty "quack!" "hello"
Expect.equal a b "Values should be equal"
@@ -640,9 +639,9 @@ let tests_withoutProperty = testList "withoutProperty" [
testCase "Remove only on one" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "quack!" "hello"
+ |> DynObj.withProperty "quack!" "hello"
|> DynObj.withoutProperty "quack!"
- let b = DynamicObj () |> DynObj.withValue "quack!" "hello"
+ let b = DynamicObj () |> DynObj.withProperty "quack!" "hello"
Expect.notEqual a b "Values should be unequal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be unequal"
@@ -650,14 +649,14 @@ let tests_withoutProperty = testList "withoutProperty" [
testCase "Nested Remove Non-Existing" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aaa" (DynamicObj ())
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aaa" (DynamicObj ())
|> DynObj.withoutProperty "quack!"
let b =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aaa" (DynamicObj ())
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aaa" (DynamicObj ())
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -665,14 +664,14 @@ let tests_withoutProperty = testList "withoutProperty" [
testCase "Nested Remove only on one" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aaa" (DynamicObj ())
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aaa" (DynamicObj ())
|> DynObj.withoutProperty "a"
let b =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aaa" (DynamicObj ())
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aaa" (DynamicObj ())
Expect.notEqual a b "Values should be unequal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be unequal"
@@ -680,14 +679,14 @@ let tests_withoutProperty = testList "withoutProperty" [
testCase "Nested Remove on both" <| fun _ ->
let a =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aaa" (DynamicObj ())
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aaa" (DynamicObj ())
|> DynObj.withoutProperty "a"
let b =
DynamicObj ()
- |> DynObj.withValue "a" [1; 2; 3]
- |> DynObj.withValue "aaa" (DynamicObj ())
+ |> DynObj.withProperty "a" [1; 2; 3]
+ |> DynObj.withProperty "aaa" (DynamicObj ())
|> DynObj.withoutProperty "a"
Expect.equal a b "Values should be equal"
@@ -700,18 +699,18 @@ let tests_formatString = testList "FormatString" [
testCase "Format string 1" <| fun _ ->
let foo = DynamicObj()
let list = [1;2;3;4]
- foo.SetValue("bar", list)
+ foo.SetProperty("bar", list)
let expected = $"?bar: {list}"
Expect.equal (foo |> DynObj.format) expected "Format string 1 failed"
testCase "Format string 2" <| fun _ ->
let foo = DynamicObj()
let corgi = "corgi"
- foo.SetValue("corgi", corgi)
+ foo.SetProperty("corgi", corgi)
let inner = DynamicObj()
let baz = "baz"
- inner.SetValue("bar", baz)
- foo.SetValue("foo", inner)
+ inner.SetProperty("bar", baz)
+ foo.SetProperty("foo", inner)
let expected = $"""?corgi: {corgi}{Environment.NewLine}?foo:{Environment.NewLine} ?bar: {baz}"""
Expect.equal (foo |> DynObj.format) expected "Format string 2 failed"
@@ -722,9 +721,9 @@ let tests_print = testList "Print" [
testCase "Test Print For Issue 14" <| fun _ ->
let outer = DynamicObj()
let inner = DynamicObj()
- inner.SetValue("Level", "Information")
- inner.SetValue("MessageTemplate","{Method} Request at {Path}")
- outer.SetValue("serilog", inner)
+ inner.SetProperty("Level", "Information")
+ inner.SetProperty("MessageTemplate","{Method} Request at {Path}")
+ outer.SetProperty("serilog", inner)
let print =
try
@@ -742,14 +741,14 @@ let main = testList "DynObj (Module)" [
tests_ofList
tests_ofArray
tests_combine
- tests_tryGetTypedValue
- tests_setValue
- tests_withValue
- tests_setValueOpt
- tests_withValueOpt
- tests_setValueOptBy
- tests_withValueOptBy
- tests_tryGetValue
+ tests_tryGetTypedPropertyValue
+ tests_setProperty
+ tests_withProperty
+ tests_setOptionalProperty
+ tests_withOptionalProperty
+ tests_setOptionalPropertyBy
+ tests_withOptionalPropertyBy
+ tests_tryGetPropertyValue
tests_withoutProperty
tests_formatString
tests_print
diff --git a/tests/DynamicObject.Tests/DynamicObjs.fs b/tests/DynamicObject.Tests/DynamicObjs.fs
index 2e02d43..7dc02a1 100644
--- a/tests/DynamicObject.Tests/DynamicObjs.fs
+++ b/tests/DynamicObject.Tests/DynamicObjs.fs
@@ -12,116 +12,116 @@ let tests_TryGetPropertyValue = testList "TryGetPropertyValue" [
testCase "Correct boxed Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
let b = a.TryGetPropertyValue "a"
Expect.equal (b) (Some (box 1)) "Value should be 1"
testCase "Correct unboxed Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
let b = a.TryGetPropertyValue "a"
Expect.equal (b |> Option.map unbox) (Some 1) "Value should be 1"
testCase "Correct boxed String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
+ a.SetProperty("a", "1")
let b = a.TryGetPropertyValue "a"
Expect.equal (b) (Some (box "1")) "Value should be '1'"
testCase "Correct unboxed String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
+ a.SetProperty("a", "1")
let b = a.TryGetPropertyValue "a"
Expect.equal (b |> Option.map unbox) (Some "1") "Value should be '1'"
testCase "Correct boxed List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
+ a.SetProperty("a", [1; 2; 3])
let b = a.TryGetPropertyValue "a"
Expect.equal (b) (Some (box [1; 2; 3])) "Value should be [1; 2; 3]"
testCase "Correct unboxed List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
+ a.SetProperty("a", [1; 2; 3])
let b = a.TryGetPropertyValue "a"
Expect.equal (b |> Option.map unbox) (Some [1; 2; 3]) "Value should be [1; 2; 3]"
testCase "Correct boxed DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
+ a.SetProperty("a", b)
let c = a.TryGetPropertyValue "a"
Expect.equal (c) (Some (box b)) "Value should be a DynamicObj"
testCase "Correct unboxed DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
+ a.SetProperty("a", b)
let c = a.TryGetPropertyValue "a"
Expect.equal (c |> Option.map unbox) (Some b) "Value should be a DynamicObj"
]
-let tests_GetValue = testList "GetValue" [
+let tests_GetPropertyValue = testList "GetPropertyValue" [
testCase "NonExisting" <| fun _ ->
let a = DynamicObj()
- Expect.throws (fun () -> a.GetValue("b") |> ignore) "Value should not exist"
+ Expect.throws (fun () -> a.GetPropertyValue("b") |> ignore) "Value should not exist"
testCase "Correct boxed Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a.GetValue "a"
+ a.SetProperty("a", 1)
+ let b = a.GetPropertyValue "a"
Expect.equal (b) (box 1) "Value should be 1"
testCase "Correct unboxed Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a.GetValue "a"
+ a.SetProperty("a", 1)
+ let b = a.GetPropertyValue "a"
Expect.equal (b |> unbox) (1) "Value should be 1"
testCase "Correct boxed String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = a.GetValue "a"
+ a.SetProperty("a", "1")
+ let b = a.GetPropertyValue "a"
Expect.equal (b) (box "1") "Value should be '1'"
testCase "Correct unboxed String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = a.GetValue "a"
+ a.SetProperty("a", "1")
+ let b = a.GetPropertyValue "a"
Expect.equal (b |> unbox) ("1") "Value should be '1'"
testCase "Correct boxed List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = a.GetValue "a"
+ a.SetProperty("a", [1; 2; 3])
+ let b = a.GetPropertyValue "a"
Expect.equal (b) (box [1; 2; 3]) "Value should be [1; 2; 3]"
testCase "Correct unboxed List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = a.GetValue "a"
+ a.SetProperty("a", [1; 2; 3])
+ let b = a.GetPropertyValue "a"
Expect.equal (b |> unbox) ([1; 2; 3]) "Value should be [1; 2; 3]"
testCase "Correct boxed DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
- let c = a.GetValue "a"
+ a.SetProperty("a", b)
+ let c = a.GetPropertyValue "a"
Expect.equal (c) (box b) "Value should be a DynamicObj"
testCase "Correct unboxed DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
- let c = a.GetValue "a"
+ a.SetProperty("a", b)
+ let c = a.GetPropertyValue "a"
Expect.equal (c |> unbox) (b) "Value should be a DynamicObj"
]
#if !FABLE_COMPILER
-// instance method TryGetTypedValue is not Fable-compatible
-let tests_TryGetTypedValue = testList "TryGetTypedValue" [
+// instance method TryGetTypedPropertyValue is not Fable-compatible
+let tests_TryGetTypedPropertyValue = testList "TryGetTypedPropertyValue" [
testCase "typeof" <| fun _ ->
let a = typeof
@@ -129,56 +129,56 @@ let tests_TryGetTypedValue = testList "TryGetTypedValue" [
testCase "NonExisting" <| fun _ ->
let a = DynamicObj()
- let b = a.TryGetTypedValue "a"
+ let b = a.TryGetTypedPropertyValue "a"
Expect.isNone b "Value should not exist"
testCase "Correct Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", 1)
+ let b = a.TryGetTypedPropertyValue "a"
Expect.equal b (Some 1) "Value should be 1"
testCase "Incorrect Int" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", "1")
+ let b = a.TryGetTypedPropertyValue "a"
Expect.isNone b "Value should not be an int"
testCase "Correct String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", "1")
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", "1")
+ let b = a.TryGetTypedPropertyValue "a"
Expect.equal b (Some "1") "Value should be '1'"
testCase "Incorrect String" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", 1)
+ let b = a.TryGetTypedPropertyValue "a"
Expect.isNone b "Value should not be a string"
testCase "Correct List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", [1; 2; 3])
+ let b = a.TryGetTypedPropertyValue "a"
Expect.equal b (Some [1; 2; 3]) "Value should be [1; 2; 3]"
testCase "Incorrect List" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", [1; 2; 3])
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", [1; 2; 3])
+ let b = a.TryGetTypedPropertyValue "a"
Expect.isNone b "Value should not be a string list"
testCase "Correct DynamicObj" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- a.SetValue("a", b)
- let c = a.TryGetTypedValue "a"
+ a.SetProperty("a", b)
+ let c = a.TryGetTypedPropertyValue "a"
Expect.equal c (Some b) "Value should be a DynamicObj"
testCase "Incorrect DynamicObj" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- let b = a.TryGetTypedValue "a"
+ a.SetProperty("a", 1)
+ let b = a.TryGetTypedPropertyValue "a"
Expect.isNone b "Value should not be a DynamicObj"
]
#endif
@@ -199,7 +199,7 @@ let tests_TryGetStaticPropertyHelper = testList "TryGetStaticPropertyHelper" [
testCase "dynamic property not retrieved as static" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
Expect.isNone (a.TryGetStaticPropertyHelper("a")) "dynamic property should not be retrieved via TryGetStaticPropertyInfo"
]
@@ -211,7 +211,7 @@ let tests_TryGetDynamicPropertyHelper = testList "TryGetDynamicPropertyHelper" [
testCase "Existing dynamic property" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
let b = Expect.wantSome (a.TryGetDynamicPropertyHelper("a")) "Value should exist"
Expect.isFalse b.IsStatic "Properties should be static"
Expect.isTrue b.IsDynamic "Properties should not be dynamic"
@@ -231,7 +231,7 @@ let tests_TryGetPropertyHelper = testList "TryGetPropertyHelper" [
testCase "Existing dynamic property" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
let b = Expect.wantSome (a.TryGetPropertyHelper("a")) "Value should exist"
Expect.isFalse b.IsStatic "Properties should be static"
Expect.isTrue b.IsDynamic "Properties should not be dynamic"
@@ -247,30 +247,29 @@ let tests_TryGetPropertyHelper = testList "TryGetPropertyHelper" [
Expect.isFalse b.IsImmutable "Properties should not be immutable"
]
-let tests_SetValue = testList "SetValue" [
+let tests_SetProperty = testList "SetProperty" [
- ler
- //TODO: static member accession!
+ //TODO: static property accession!
testCase "Same String" <| fun _ ->
let a = DynamicObj ()
- a.SetValue("aaa", 5)
+ a.SetProperty("aaa", 5)
let b = DynamicObj ()
- b.SetValue("aaa", 5)
+ b.SetProperty("aaa", 5)
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
testCase "Different Strings" <| fun _ ->
let a = DynamicObj ()
- a.SetValue("aaa", 1212)
+ a.SetProperty("aaa", 1212)
let b = DynamicObj ()
- b.SetValue("aaa", 5)
+ b.SetProperty("aaa", 5)
Expect.notEqual a b "Values should not be equal"
testCase "String only on one" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- b.SetValue("aaa", 5)
+ b.SetProperty("aaa", 5)
Expect.notEqual a b "Values should not be equal"
Expect.notEqual b a "Values should not be equal (Reversed equality)"
@@ -278,15 +277,15 @@ let tests_SetValue = testList "SetValue" [
testCase "Same lists different keys" <| fun _ ->
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!1", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!1", [1; 2; 3])
Expect.notEqual (a'.GetHashCode()) (b'.GetHashCode()) "Hash codes should not be equal"
testCase "Different lists" <| fun _ ->
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3; 4; 34])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3; 4; 34])
Expect.notEqual (a'.GetHashCode()) (b'.GetHashCode()) "Hash codes should not be equal"
testCase "Nested Same List Same String" <| fun _ ->
@@ -295,11 +294,11 @@ let tests_SetValue = testList "SetValue" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- b.SetValue("aaa", b')
+ a.SetProperty("aaa", a')
+ b.SetProperty("aaa", b')
Expect.equal a' b' "New Values should be equal"
Expect.equal a b "Old Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Old Hash codes should be equal"
@@ -311,25 +310,27 @@ let tests_SetValue = testList "SetValue" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- b.SetValue("aaa1", b')
+ a.SetProperty("aaa", a')
+ b.SetProperty("aaa1", b')
Expect.equal a' b' "New Values should be equal"
Expect.notEqual a b "Old Values should not be equal"
Expect.equal (a'.GetHashCode()) (b'.GetHashCode()) "New Hash codes should be equal"
]
-let tests_Remove = testList "Remove" [
+let tests_RemoveProperty = testList "RemoveProperty" [
+ //TODO: static property removal!
+
testCase "Remove" <| fun _ ->
let a = DynamicObj ()
let b = DynamicObj ()
- a.SetValue("quack!", "hello")
+ a.SetProperty("quack!", "hello")
- a.Remove "quack!" |> ignore
+ a.RemoveProperty "quack!" |> ignore
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -338,10 +339,10 @@ let tests_Remove = testList "Remove" [
let a = DynamicObj ()
let b = DynamicObj ()
- a.SetValue("quack!", "hello")
- b.SetValue("quack!", "hello")
+ a.SetProperty("quack!", "hello")
+ b.SetProperty("quack!", "hello")
- a.Remove "quecky!" |> ignore
+ a.RemoveProperty "quecky!" |> ignore
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -350,10 +351,10 @@ let tests_Remove = testList "Remove" [
let a = DynamicObj ()
let b = DynamicObj ()
- a.SetValue("quack!", "hello")
- b.SetValue("quack!", "hello")
+ a.SetProperty("quack!", "hello")
+ b.SetProperty("quack!", "hello")
- a.Remove "quack!" |> ignore
+ a.RemoveProperty "quack!" |> ignore
Expect.notEqual a b "Values should be unequal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be unequal"
@@ -364,12 +365,12 @@ let tests_Remove = testList "Remove" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- a.Remove "quack!" |> ignore
- b.SetValue("aaa", b')
+ a.SetProperty("aaa", a')
+ a.RemoveProperty "quack!" |> ignore
+ b.SetProperty("aaa", b')
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -380,12 +381,12 @@ let tests_Remove = testList "Remove" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- a'.Remove "quack!" |> ignore
- b.SetValue("aaa", b')
+ a.SetProperty("aaa", a')
+ a'.RemoveProperty "quack!" |> ignore
+ b.SetProperty("aaa", b')
Expect.notEqual a b "Values should be unequal"
Expect.notEqual (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be unequal"
@@ -396,13 +397,13 @@ let tests_Remove = testList "Remove" [
let a' = DynamicObj ()
let b' = DynamicObj ()
- a'.SetValue("quack!", [1; 2; 3])
- b'.SetValue("quack!", [1; 2; 3])
+ a'.SetProperty("quack!", [1; 2; 3])
+ b'.SetProperty("quack!", [1; 2; 3])
- a.SetValue("aaa", a')
- a.Remove "quack!" |> ignore
- b.SetValue("aaa", b')
- b.Remove "quack!" |> ignore
+ a.SetProperty("aaa", a')
+ a.RemoveProperty "quack!" |> ignore
+ b.SetProperty("aaa", b')
+ b.RemoveProperty "quack!" |> ignore
Expect.equal a b "Values should be equal"
Expect.equal (a.GetHashCode()) (b.GetHashCode()) "Hash codes should be equal"
@@ -412,8 +413,8 @@ let tests_Remove = testList "Remove" [
let tests_GetPropertyHelpers = testList "GetPropertyHelpers" [
testCase "GetPropertyHelpers" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- a.SetValue("b", 2)
+ a.SetProperty("a", 1)
+ a.SetProperty("b", 2)
let properties = a.GetPropertyHelpers(true)
let names = properties |> Seq.map (fun p -> p.Name)
Expect.equal (Seq.toList names) ["a"; "b"] "Should have all properties"
@@ -422,8 +423,8 @@ let tests_GetPropertyHelpers = testList "GetPropertyHelpers" [
let tests_GetProperties = testList "GetProperties" [
testCase "GetProperties" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- a.SetValue("b", 2)
+ a.SetProperty("a", 1)
+ a.SetProperty("b", 2)
let properties = a.GetProperties(true) |> List.ofSeq
let expected = [
System.Collections.Generic.KeyValuePair("a", box 1)
@@ -435,28 +436,28 @@ let tests_GetProperties = testList "GetProperties" [
let tests_CopyDynamicPropertiesTo = testList "CopyDynamicPropertiesTo" [
testCase "ExistingObject" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- a.SetValue("b", 2)
+ a.SetProperty("a", 1)
+ a.SetProperty("b", 2)
let b = DynamicObj()
- b.SetValue("c", 3)
+ b.SetProperty("c", 3)
a.CopyDynamicPropertiesTo(b)
- Expect.equal (b.GetValue("a")) 1 "Value a should be copied"
- Expect.equal (b.GetValue("b")) 2 "Value b should be copied"
- Expect.equal (b.GetValue("c")) 3 "Value c should be unaffected"
+ Expect.equal (b.GetPropertyValue("a")) 1 "Value a should be copied"
+ Expect.equal (b.GetPropertyValue("b")) 2 "Value b should be copied"
+ Expect.equal (b.GetPropertyValue("c")) 3 "Value c should be unaffected"
testCase "NoOverwrite throws" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
let b = DynamicObj()
- b.SetValue("a", 3)
+ b.SetProperty("a", 3)
let f = fun () -> a.CopyDynamicPropertiesTo(b)
Expect.throws f "Should throw because property exists"
testCase "Overwrite" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
+ a.SetProperty("a", 1)
let b = DynamicObj()
- b.SetValue("a", 3)
+ b.SetProperty("a", 3)
Expect.notEqual a b "Values should not be equal before copying"
a.CopyDynamicPropertiesTo(b, true)
Expect.equal a b "Values should be equal"
@@ -465,8 +466,8 @@ let tests_CopyDynamicPropertiesTo = testList "CopyDynamicPropertiesTo" [
let tests_CopyDynamicProperties = testList "CopyDynamicProperties" [
testCase "NewObject" <| fun _ ->
let a = DynamicObj()
- a.SetValue("a", 1)
- a.SetValue("b", 2)
+ a.SetProperty("a", 1)
+ a.SetProperty("b", 2)
let b = a.CopyDynamicProperties()
Expect.equal a b "Values should be equal"
]
@@ -474,32 +475,32 @@ let tests_CopyDynamicProperties = testList "CopyDynamicProperties" [
let tests_Equals = testList "Equals" [
testCase "Same Object" <| fun _ ->
let a = DynamicObj()
- a.SetValue("b", 2)
+ a.SetProperty("b", 2)
Expect.isTrue (a.Equals(a)) "Values should be equal"
testCase "Different Equal Objects" <| fun _ ->
let a = DynamicObj()
- a.SetValue("b", 2)
+ a.SetProperty("b", 2)
let a2 = DynamicObj()
- a2.SetValue("b", 2)
+ a2.SetProperty("b", 2)
Expect.isTrue (a.Equals(a2)) "Values should be equal"
testCase "Different Unequal Objects" <| fun _ ->
let a = DynamicObj()
- a.SetValue("b", 2)
+ a.SetProperty("b", 2)
let a2 = DynamicObj()
- a2.SetValue("b", 3)
+ a2.SetProperty("b", 3)
Expect.isFalse (a.Equals(a2)) "Values should not be equal"
testCase "nested DynamicObjs" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- b.SetValue("c", 2)
- a.SetValue("b", b)
+ b.SetProperty("c", 2)
+ a.SetProperty("b", b)
let a2 = DynamicObj()
let b2 = DynamicObj()
- b2.SetValue("c", 2)
- a2.SetValue("b", b2)
+ b2.SetProperty("c", 2)
+ a2.SetProperty("b", b2)
Expect.isTrue (a.Equals(a2)) "Values should be equal"
]
@@ -507,49 +508,49 @@ let tests_Equals = testList "Equals" [
let tests_GetHashCode = testList "GetHashCode" [
testCase "Same Object" <| fun _ ->
let a = DynamicObj()
- a.SetValue("b", 2)
+ a.SetProperty("b", 2)
Expect.equal (a.GetHashCode()) (a.GetHashCode()) "Values should be equal"
testCase "Different Equal Objects" <| fun _ ->
let a = DynamicObj()
- a.SetValue("b", 2)
+ a.SetProperty("b", 2)
let a2 = DynamicObj()
- a2.SetValue("b", 2)
+ a2.SetProperty("b", 2)
Expect.equal (a.GetHashCode()) (a2.GetHashCode()) "Values should be equal"
testCase "Different Unequal Objects" <| fun _ ->
let a = DynamicObj()
- a.SetValue("b", 2)
+ a.SetProperty("b", 2)
let a2 = DynamicObj()
- a.SetValue("b", 3)
+ a.SetProperty("b", 3)
Expect.notEqual (a.GetHashCode()) (a2.GetHashCode()) "Values should not be equal"
testCase "nested DynamicObjs" <| fun _ ->
let a = DynamicObj()
let b = DynamicObj()
- b.SetValue("c", 2)
- a.SetValue("b", b)
+ b.SetProperty("c", 2)
+ a.SetProperty("b", b)
let a2 = DynamicObj()
let b2 = DynamicObj()
- b2.SetValue("c", 2)
- a2.SetValue("b", b2)
+ b2.SetProperty("c", 2)
+ a2.SetProperty("b", b2)
Expect.equal (a.GetHashCode()) (a2.GetHashCode()) "Values should be equal"
]
let main = testList "DynamicObj (Class)" [
- tests_TryGetValue
- tests_GetValue
+ tests_TryGetPropertyValue
+ tests_GetPropertyValue
#if !FABLE_COMPILER
// instance method TryGetTypedValue is not Fable-compatible
- tests_TryGetTypedValue
+ tests_TryGetTypedPropertyValue
#endif
- tests_TryGetStaticPropertyInfo
- tests_TryGetDynamicPropertyInfo
- tests_TryGetPropertyInfo
- tests_SetValue
- tests_Remove
+ tests_TryGetStaticPropertyHelper
+ tests_TryGetDynamicPropertyHelper
+ tests_TryGetPropertyHelper
+ tests_SetProperty
+ tests_RemoveProperty
tests_GetPropertyHelpers
tests_GetProperties
tests_CopyDynamicPropertiesTo
diff --git a/tests/DynamicObject.Tests/Inheritance.fs b/tests/DynamicObject.Tests/Inheritance.fs
index 6a2cdfd..7689c1d 100644
--- a/tests/DynamicObject.Tests/Inheritance.fs
+++ b/tests/DynamicObject.Tests/Inheritance.fs
@@ -24,27 +24,27 @@ let tests_set = testList "Set" [
testCase "Static Property" <| fun _ ->
let p = Person("123","John")
- p.SetValue("FirstName", "Jane")
+ p.SetProperty("FirstName", "Jane")
Expect.equal p.FirstName "Jane" "Static property should be set"
- Expect.equal (p.TryGetValue("FirstName")) (Some "Jane") "Static property should be retreivable dynamically"
+ Expect.equal (p.TryGetPropertyValue("FirstName")) (Some "Jane") "Static property should be retreivable dynamically"
testCase "Static Immutable Property" <| fun _ ->
let p = Person("123","John")
- let f = fun () -> p.SetValue("Id", "321")
+ let f = fun () -> p.SetProperty("Id", "321")
Expect.throws f "Cannot set static property"
testCase "Dynamic Property" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Age", 42)
- Expect.equal (p.TryGetValue("Age")) (Some 42) "Dynamic property should be set"
- Expect.equal (p.TryGetValue("FirstName")) (Some "John") "Static property should be retreivable dynamically"
+ p.SetProperty("Age", 42)
+ Expect.equal (p.TryGetPropertyValue("Age")) (Some 42) "Dynamic property should be set"
+ Expect.equal (p.TryGetPropertyValue("FirstName")) (Some "John") "Static property should be retreivable dynamically"
testCase "Dynamic Property Equality" <| fun _ ->
let p1 = Person("123","John")
let p2 = Person("123","John")
- p1.SetValue("Age", 42)
- p2.SetValue("Age", 42)
+ p1.SetProperty("Age", 42)
+ p2.SetProperty("Age", 42)
Expect.equal p1 p2 "Values should be equal"
Expect.equal (p1.GetHashCode()) (p2.GetHashCode()) "Hash codes should be equal"
@@ -53,7 +53,7 @@ let tests_set = testList "Set" [
let p1 = Person("123","John")
let p2 = Person("123","John")
- p1.SetValue("Age", 42)
+ p1.SetProperty("Age", 42)
Expect.notEqual p1 p2 "Values should not be equal"
Expect.notEqual p2 p1 "Values should not be equal (Reversed equality)"
@@ -64,23 +64,23 @@ let tests_remove = testList "Remove" [
testCase "Remove Static" <| fun _ ->
let p = Person("123","John")
- p.Remove("FirstName") |> ignore
+ p.RemoveProperty("FirstName") |> ignore
Expect.equal p.FirstName null "Static property should "
testCase "Remove Static Immutable" <| fun _ ->
let p = Person("123","John")
- let f = fun () -> p.Remove("Id") |> ignore
+ let f = fun () -> p.RemoveProperty("Id") |> ignore
Expect.throws f "Cannot remove static property"
testCase "Remove Dynamic" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Age", 42)
+ p.SetProperty("Age", 42)
- p.Remove "Age" |> ignore
+ p.RemoveProperty "Age" |> ignore
- let r = p.TryGetValue("Age")
+ let r = p.TryGetPropertyValue("Age")
Expect.isNone r "Dynamic property should be removed"
@@ -88,10 +88,10 @@ let tests_remove = testList "Remove" [
let p1 = Person("123","John")
let p2 = Person("123","John")
- p1.SetValue("Age", 42)
- p2.SetValue("Age", 42)
+ p1.SetProperty("Age", 42)
+ p2.SetProperty("Age", 42)
- p1.Remove "Age" |> ignore
+ p1.RemoveProperty "Age" |> ignore
Expect.notEqual p1 p2 "Values should be unequal"
Expect.notEqual (p1.GetHashCode()) (p2.GetHashCode()) "Hash codes should be unequal"
@@ -103,7 +103,7 @@ let tests_getProperties = testList "GetProperties" [
testCase "Get Properties" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Age", 42)
+ p.SetProperty("Age", 42)
let properties = p.GetPropertyHelpers(true)
let names = properties |> Seq.map (fun p -> p.Name)
Expect.equal (Seq.toList names) ["Id"; "FirstName"; "Age"] "Should have all properties"
@@ -118,7 +118,7 @@ let tests_formatString = testList "FormatString" [
let firstName = "John"
let age = 20
let p = Person(id, firstName)
- p.SetValue("age", age)
+ p.SetProperty("age", age)
let expected = $"Id: {id}{System.Environment.NewLine}FirstName: {firstName}{System.Environment.NewLine}?age: {age}"
Expect.equal (p |> DynObj.format) expected "Format string 1 failed"
]
@@ -129,9 +129,9 @@ let tests_print = testList "Print" [
testCase "Test Print For Issue 14" <| fun _ ->
let outer = DynamicObj()
let inner = DynamicObj()
- inner.SetValue("Level", "Information")
- inner.SetValue("MessageTemplate","{Method} Request at {Path}")
- outer.SetValue("serilog", inner)
+ inner.SetProperty("Level", "Information")
+ inner.SetProperty("MessageTemplate","{Method} Request at {Path}")
+ outer.SetProperty("serilog", inner)
let print =
try
diff --git a/tests/DynamicObject.Tests/Interface.fs b/tests/DynamicObject.Tests/Interface.fs
index babae99..51269e7 100644
--- a/tests/DynamicObject.Tests/Interface.fs
+++ b/tests/DynamicObject.Tests/Interface.fs
@@ -28,27 +28,27 @@ let tests_set = testList "Set" [
testCase "Static Property" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Name", "Jane")
+ p.SetProperty("Name", "Jane")
Expect.equal (p : IPerson).Name "Jane" "Static property should be set"
- Expect.equal (p.TryGetValue("Name")) (Some "Jane") "Static property should be retreivable dynamically"
+ Expect.equal (p.TryGetPropertyValue("Name")) (Some "Jane") "Static property should be retreivable dynamically"
testCase "Static Immutable Property" <| fun _ ->
let p = Person("123","John")
- let f = fun () -> p.SetValue("Id", "321")
+ let f = fun () -> p.SetProperty("Id", "321")
Expect.throws f "Cannot set static property"
testCase "Dynamic Property" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Age", 42)
- Expect.equal (p.TryGetValue("Age")) (Some 42) "Dynamic property should be set"
- Expect.equal (p.TryGetValue("Name")) (Some "John") "Static property should be retreivable dynamically"
+ p.SetProperty("Age", 42)
+ Expect.equal (p.TryGetPropertyValue("Age")) (Some 42) "Dynamic property should be set"
+ Expect.equal (p.TryGetPropertyValue("Name")) (Some "John") "Static property should be retreivable dynamically"
testCase "Dynamic Property Equality" <| fun _ ->
let p1 = Person("123","John")
let p2 = Person("123","John")
- p1.SetValue("Age", 42)
- p2.SetValue("Age", 42)
+ p1.SetProperty("Age", 42)
+ p2.SetProperty("Age", 42)
Expect.equal p1 p2 "Values should be equal"
Expect.equal (p1.GetHashCode()) (p2.GetHashCode()) "Hash codes should be equal"
@@ -57,7 +57,7 @@ let tests_set = testList "Set" [
let p1 = Person("123","John")
let p2 = Person("123","John")
- p1.SetValue("Age", 42)
+ p1.SetProperty("Age", 42)
Expect.notEqual p1 p2 "Values should not be equal"
Expect.notEqual p2 p1 "Values should not be equal (Reversed equality)"
@@ -68,23 +68,23 @@ let tests_remove = testList "Remove" [
testCase "Remove Static" <| fun _ ->
let p = Person("123","John")
- p.Remove("Name") |> ignore
+ p.RemoveProperty("Name") |> ignore
Expect.equal (p : IPerson).Name null "Static property should "
testCase "Remove Static Immutable" <| fun _ ->
let p = Person("123","John")
- let f = fun () -> p.Remove("Id") |> ignore
+ let f = fun () -> p.RemoveProperty("Id") |> ignore
Expect.throws f "Cannot remove static property"
testCase "Remove Dynamic" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Age", 42)
+ p.SetProperty("Age", 42)
- p.Remove "Age" |> ignore
+ p.RemoveProperty "Age" |> ignore
- let r = p.TryGetValue("Age")
+ let r = p.TryGetPropertyValue("Age")
Expect.isNone r "Dynamic property should be removed"
@@ -92,10 +92,10 @@ let tests_remove = testList "Remove" [
let p1 = Person("123","John")
let p2 = Person("123","John")
- p1.SetValue("Age", 42)
- p2.SetValue("Age", 42)
+ p1.SetProperty("Age", 42)
+ p2.SetProperty("Age", 42)
- p1.Remove "Age" |> ignore
+ p1.RemoveProperty "Age" |> ignore
Expect.notEqual p1 p2 "Values should be unequal"
Expect.notEqual (p1.GetHashCode()) (p2.GetHashCode()) "Hash codes should be unequal"
@@ -106,7 +106,7 @@ let tests_getProperties = testList "GetProperties" [
testCase "Get Properties" <| fun _ ->
let p = Person("123","John")
- p.SetValue("Age", 42)
+ p.SetProperty("Age", 42)
let properties = p.GetPropertyHelpers(true)
let names = properties |> Seq.map (fun p -> p.Name)
Expect.equal (Seq.toList names) ["Id"; "Name"; "Age"] "Should have all properties"
@@ -122,7 +122,7 @@ let tests_formatString = testList "FormatString" [
let name = "John"
let age = 20
let p = Person(id, name)
- p.SetValue("age", age)
+ p.SetProperty("age", age)
let expected = $"Id: {id}{System.Environment.NewLine}Name: {name}{System.Environment.NewLine}?age: {age}"
Expect.equal (p |> DynObj.format) expected "Format string 1 failed"
]
@@ -133,9 +133,9 @@ let tests_print = testList "Print" [
testCase "Test Print For Issue 14" <| fun _ ->
let outer = DynamicObj()
let inner = DynamicObj()
- inner.SetValue("Level", "Information")
- inner.SetValue("MessageTemplate","{Method} Request at {Path}")
- outer.SetValue("serilog", inner)
+ inner.SetProperty("Level", "Information")
+ inner.SetProperty("MessageTemplate","{Method} Request at {Path}")
+ outer.SetProperty("serilog", inner)
let print =
try