Skip to content

Commit

Permalink
Add '@context' support:
Browse files Browse the repository at this point in the history
- instance methods and static methods for set/tryGet/remove
- tests for all classes
  • Loading branch information
kMutagene committed Sep 6, 2024
1 parent 8b4368a commit ac7e6d2
Show file tree
Hide file tree
Showing 13 changed files with 473 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ROCrate/ROCrateObject.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,20 @@ type ROCrateObject(id:string, schemaType: string, ?additionalType) =

member this.AdditionalType
with get() = _additionalType
and set(value) = _additionalType <- value
and set(value) = _additionalType <- value

member this.SetContext (context: #DynamicObj) =
this.SetValue("@context", context)

static member setContext (context: #DynamicObj) =
fun (roc: #ROCrateObject) -> roc.SetContext(context)

member this.TryGetContext() =
DynObj.tryGetTypedValue<DynamicObj>("@context") this

static member tryGetContext (roc: #ROCrateObject) = roc.TryGetContext()

member this.RemoveContext() =
this.Remove("@context")

static member removeContext (roc: #ROCrateObject) = roc.RemoveContext()
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/Assay.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "Assay" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/Data.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "Data" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/Dataset.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "Dataset" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/Investigation.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "Investigation" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/LabProcess.tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "LabProcess" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/LabProtocol.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "LabProtocol" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
38 changes: 38 additions & 0 deletions tests/ROCrate/ISAProfile/Person.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,46 @@ let tests_dynamic_members = testSequenced (
]
)

let tests_instance_methods = testSequenced (
testList "instance methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
mandatory_properties.SetContext context
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = mandatory_properties.TryGetContext()
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
mandatory_properties.RemoveContext()
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let tests_static_methods = testSequenced (
testList "static methods" [

let context = new DynamicObj()
context.SetValue("more", "context")

testCase "can set context" <| fun _ ->
ROCrateObject.setContext context mandatory_properties
Expect.ROCrateObjectHasDynamicProperty "@context" context mandatory_properties
testCase "can get context" <| fun _ ->
let ctx = ROCrateObject.tryGetContext mandatory_properties
Expect.equal ctx (Some context) "context was not set correctly"
testCase "can remove context" <| fun _ ->
ROCrateObject.removeContext mandatory_properties
Expect.isNone (DynObj.tryGetTypedValue<DynamicObj> "@context" mandatory_properties) "context was not removed correctly"
]
)

let main = testList "Person" [
tests_profile_object_is_valid
tests_interface_members
tests_dynamic_members
tests_instance_methods
tests_static_methods
]
Loading

0 comments on commit ac7e6d2

Please sign in to comment.