From 28cfd133152fa3cdc6606b4ccb7cda3c340e8f62 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 3 Jul 2024 08:28:02 +0200 Subject: [PATCH 01/15] add rocrate project --- src/ROCrate/ARCtrl.ROCrate.fsproj | 24 ++++++++++++++++++++++++ src/ROCrate/Library.fs | 5 +++++ 2 files changed, 29 insertions(+) create mode 100644 src/ROCrate/ARCtrl.ROCrate.fsproj create mode 100644 src/ROCrate/Library.fs diff --git a/src/ROCrate/ARCtrl.ROCrate.fsproj b/src/ROCrate/ARCtrl.ROCrate.fsproj new file mode 100644 index 00000000..c5ba9b84 --- /dev/null +++ b/src/ROCrate/ARCtrl.ROCrate.fsproj @@ -0,0 +1,24 @@ + + + + netstandard2.0 + true + + + + + + + + + + Kevin Schneider, nfdi4plants, DataPLANT OSS contributors + A data model of the ARC concept via it's RO Crate profile + MIT + logo.png + ARC F# FSharp dotnet .Net bioinformatics biology fable-library datascience dataplant nfdi metadata + https://github.com/nfdi4plants/ARCtrl/tree/main/src/CWL + https://github.com/nfdi4plants/ARCtrl + git + + diff --git a/src/ROCrate/Library.fs b/src/ROCrate/Library.fs new file mode 100644 index 00000000..b50c5b70 --- /dev/null +++ b/src/ROCrate/Library.fs @@ -0,0 +1,5 @@ +namespace ARCtrl.ROCrate + +module Say = + let hello name = + printfn "Hello %s" name From f71faea334538425d5f92e81c650b1cdd46446ef Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 26 Aug 2024 15:19:53 +0200 Subject: [PATCH 02/15] rocrate datamodel wip based on inheritance and single interface --- src/ROCrate/playground.fsx | 405 +++++++++++++++++++++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 src/ROCrate/playground.fsx diff --git a/src/ROCrate/playground.fsx b/src/ROCrate/playground.fsx new file mode 100644 index 00000000..35876a56 --- /dev/null +++ b/src/ROCrate/playground.fsx @@ -0,0 +1,405 @@ +#r "nuget: DynamicObj, 3.0.0" + +open DynamicObj + +type IROCrateObject = + abstract member SchemaType : string + abstract member Id: string + abstract member AdditionalType: string option + +type Dataset (id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "schema.org/Dataset" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + +type InvestigationDataset(id: string) = + // inheritance + inherit Dataset(id, "Investigation") + static member create( + // mandatory + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + ?citation, + ?comment, + ?creator, + ?dateCreated, + ?dateModified, + ?datePublished, + ?hasPart, + ?headline, + ?mentions, + ?url, + // Properties from Thing + ?description + ) = + let ds = InvestigationDataset(id = id) + + // Properties from CreativeWork + DynObj.setValueOpt ds (nameof citation) citation + DynObj.setValueOpt ds (nameof comment) comment + DynObj.setValueOpt ds (nameof creator) creator + DynObj.setValueOpt ds (nameof dateCreated) dateCreated + DynObj.setValueOpt ds (nameof dateModified) dateModified + DynObj.setValueOpt ds (nameof datePublished) datePublished + DynObj.setValueOpt ds (nameof hasPart) hasPart + DynObj.setValueOpt ds (nameof headline) headline + DynObj.setValueOpt ds (nameof mentions) mentions + DynObj.setValueOpt ds (nameof url) url + + // Properties from Thing + DynObj.setValueOpt ds (nameof description) description + DynObj.setValue ds (nameof identifier) identifier + + ds + + static member tryGetCitation (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "citation" with + | Some value -> Some value + | None -> None + + static member tryGetComment (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "comment" with + | Some value -> Some value + | None -> None + + static member tryGetCreator (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "creator" with + | Some value -> Some value + | None -> None + + static member tryGetDateCreated (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "dateCreated" with + | Some value -> Some value + | None -> None + + static member tryGetDateModified (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "dateModified" with + | Some value -> Some value + | None -> None + + static member tryGetDatePublished (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "datePublished" with + | Some value -> Some value + | None -> None + + static member tryGetHasPart (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "hasPart" with + | Some value -> Some value + | None -> None + + static member tryGetHeadline (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "headline" with + | Some value -> Some value + | None -> None + + static member tryGetMentions (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "mentions" with + | Some value -> Some value + | None -> None + + static member tryGetUrl (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "url" with + | Some value -> Some value + | None -> None + + static member tryGetDescription (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "description" with + | Some value -> Some value + | None -> None + + static member tryGetIdentifier (ds: InvestigationDataset) = + match DynObj.tryGetValue ds "identifier" with + | Some value -> Some value + | None -> None + + +type StudyDataset(id: string) = + // inheritance + inherit Dataset(id, "Study") + static member create( + // mandatory + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + ?about, + ?citation, + ?comment, + ?creator, + ?dateCreated, + ?dateModified, + ?datePublished, + ?hasPart, + ?headline, + ?url, + // Properties from Thing + ?description + ) = + let ds = StudyDataset(id = id) + + // Properties from CreativeWork + DynObj.setValueOpt ds (nameof about) about + DynObj.setValueOpt ds (nameof citation) citation + DynObj.setValueOpt ds (nameof comment) comment + DynObj.setValueOpt ds (nameof creator) creator + DynObj.setValueOpt ds (nameof dateCreated) dateCreated + DynObj.setValueOpt ds (nameof dateModified) dateModified + DynObj.setValueOpt ds (nameof datePublished) datePublished + DynObj.setValueOpt ds (nameof hasPart) hasPart + DynObj.setValueOpt ds (nameof headline) headline + DynObj.setValueOpt ds (nameof url) url + + // Properties from Thing + DynObj.setValueOpt ds (nameof description) description + DynObj.setValue ds (nameof identifier) identifier + + ds + + static member tryGetAbout (ds: StudyDataset) = + match DynObj.tryGetValue ds "about" with + | Some value -> Some value + | None -> None + + static member tryGetCitation (ds: StudyDataset) = + match DynObj.tryGetValue ds "citation" with + | Some value -> Some value + | None -> None + + static member tryGetComment (ds: StudyDataset) = + match DynObj.tryGetValue ds "comment" with + | Some value -> Some value + | None -> None + + static member tryGetCreator (ds: StudyDataset) = + match DynObj.tryGetValue ds "creator" with + | Some value -> Some value + | None -> None + + static member tryGetDateCreated (ds: StudyDataset) = + match DynObj.tryGetValue ds "dateCreated" with + | Some value -> Some value + | None -> None + + static member tryGetDateModified (ds: StudyDataset) = + match DynObj.tryGetValue ds "dateModified" with + | Some value -> Some value + | None -> None + + static member tryGetDatePublished (ds: StudyDataset) = + match DynObj.tryGetValue ds "datePublished" with + | Some value -> Some value + | None -> None + + static member tryGetHasPart (ds: StudyDataset) = + match DynObj.tryGetValue ds "hasPart" with + | Some value -> Some value + | None -> None + + static member tryGetHeadline (ds: StudyDataset) = + match DynObj.tryGetValue ds "headline" with + | Some value -> Some value + | None -> None + + static member tryGetMentions (ds: StudyDataset) = + match DynObj.tryGetValue ds "mentions" with + | Some value -> Some value + | None -> None + + static member tryGetUrl (ds: StudyDataset) = + match DynObj.tryGetValue ds "url" with + | Some value -> Some value + | None -> None + + static member tryGetIdentifier (ds: StudyDataset) = + match DynObj.tryGetValue ds "identifier" with + | Some value -> Some value + | None -> None + + static member tryGetDescription (ds: StudyDataset) = + match DynObj.tryGetValue ds "description" with + | Some value -> Some value + | None -> None + + +type AssayDataset(id: string) = + // inheritance + inherit Dataset(id, "Assay") + static member create( + // mandatory + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + // Properties from Dataset + ?measurementMethod, + ?measurementTechnique, + ?variableMeasured, + // Properties from CreativeWork + ?about, + ?comment, + ?creator, + ?hasPart, + ?url + ) : AssayDataset = + let ds = AssayDataset(id = id) + + // Properties from Dataset + DynObj.setValueOpt ds (nameof measurementMethod) measurementMethod + DynObj.setValueOpt ds (nameof measurementTechnique) measurementTechnique + DynObj.setValueOpt ds (nameof variableMeasured) variableMeasured + + // Properties from CreativeWork + DynObj.setValueOpt ds (nameof about) about + DynObj.setValueOpt ds (nameof comment) comment + DynObj.setValueOpt ds (nameof creator) creator + DynObj.setValueOpt ds (nameof hasPart) hasPart + DynObj.setValueOpt ds (nameof url) url + + // Properties from Thing + DynObj.setValue ds (nameof identifier) identifier + + ds + + static member tryGetMeasurementMethod (ds: AssayDataset) = + match DynObj.tryGetValue ds "measurementMethod" with + | Some value -> Some value + | None -> None + + static member tryGetMeasurementTechnique (ds: AssayDataset) = + match DynObj.tryGetValue ds "measurementTechnique" with + | Some value -> Some value + | None -> None + + static member tryGetVariableMeasured (ds: AssayDataset) = + match DynObj.tryGetValue ds "variableMeasured" with + | Some value -> Some value + | None -> None + + static member tryGetAbout (ds: AssayDataset) = + match DynObj.tryGetValue ds "about" with + | Some value -> Some value + | None -> None + + static member tryGetComment (ds: AssayDataset) = + match DynObj.tryGetValue ds "comment" with + | Some value -> Some value + | None -> None + + static member tryGetCreator (ds: AssayDataset) = + match DynObj.tryGetValue ds "creator" with + | Some value -> Some value + | None -> None + + static member tryGetHasPart (ds: AssayDataset) = + match DynObj.tryGetValue ds "hasPart" with + | Some value -> Some value + | None -> None + + static member tryGetUrl (ds: AssayDataset) = + match DynObj.tryGetValue ds "url" with + | Some value -> Some value + | None -> None + + static member tryGetIdentifier (ds: AssayDataset) = + match DynObj.tryGetValue ds "identifier" with + | Some value -> Some value + | None -> None + +let interfaceOnly: IROCrateObject list = + [ + InvestigationDataset.create(id = "./", identifier = "inv") + StudyDataset.create(id ="./studies/study1", identifier = "study1") + AssayDataset.create(id ="./assays/assay1", identifier = "assay1") + ] + +module ROCrateObject = + + let tryAsDataset (roco: IROCrateObject) = + match roco with + | :? Dataset as ds when ds.SchemaType = "schema.org/Dataset" -> Some ds + | _ -> None + + let tryAsInvestigationDataset (roco: IROCrateObject) = + match roco.AdditionalType, roco.SchemaType with + | Some "Investigation", "schema.org/Dataset" -> + roco :?> InvestigationDataset |> Some // both type annotations are present + | _ -> + None + let tryAsStudyDataset (roco: IROCrateObject) = + match roco.AdditionalType, roco.SchemaType with + | Some "Study", "schema.org/Dataset" -> + roco :?> StudyDataset |> Some // both type annotations are present + | _ -> + None + + let tryAsAssayDataset (roco: IROCrateObject) = + match roco.AdditionalType, roco.SchemaType with + | Some "Assay", "schema.org/Dataset" -> + roco :?> AssayDataset |> Some // both type annotations are present + | _ -> + None + +type LabProcess(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "bioschemas.org/LabProcess" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + agent, + object, + result, + // optional + ?additionalType, + ?executesLabProtocol, + ?parameterValue, + ?endTime, + ?disambiguatingDescription + ) = + let lp = LabProcess(id) + + DynObj.setValue lp (nameof id) id + DynObj.setValue lp (nameof name) name + DynObj.setValue lp (nameof agent) agent + DynObj.setValue lp (nameof object) object + DynObj.setValue lp (nameof result) result + + DynObj.setValueOpt lp (nameof additionalType) additionalType + DynObj.setValueOpt lp (nameof executesLabProtocol) executesLabProtocol + DynObj.setValueOpt lp (nameof parameterValue) parameterValue + DynObj.setValueOpt lp (nameof endTime) endTime + DynObj.setValueOpt lp (nameof disambiguatingDescription) disambiguatingDescription + + lp + From ef15f35779606a1bfcaecdadfc7532886466ec46 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 27 Aug 2024 12:46:18 +0200 Subject: [PATCH 03/15] implement first POC of ISA ROCrate profile --- src/ROCrate/ARCtrl.ROCrate.fsproj | 17 +- src/ROCrate/IROCrateObject.fs | 7 + src/ROCrate/ISAProfile/Assay.fs | 46 +++ src/ROCrate/ISAProfile/Data.fs | 47 +++ src/ROCrate/ISAProfile/Dataset.fs | 29 ++ src/ROCrate/ISAProfile/Investigation.fs | 49 +++ src/ROCrate/ISAProfile/LabProcess.fs | 58 ++++ src/ROCrate/ISAProfile/LabProtocol.fs | 56 +++ src/ROCrate/ISAProfile/Person.fs | 61 ++++ src/ROCrate/ISAProfile/PropertyValue.fs | 52 +++ src/ROCrate/ISAProfile/Sample.fs | 45 +++ src/ROCrate/ISAProfile/ScholarlyArticle.fs | 51 +++ src/ROCrate/ISAProfile/Study.fs | 49 +++ src/ROCrate/Library.fs | 5 - src/ROCrate/ROCrateObject.fs | 35 ++ src/ROCrate/playground.fsx | 386 ++++++++++++++------- 16 files changed, 854 insertions(+), 139 deletions(-) create mode 100644 src/ROCrate/IROCrateObject.fs create mode 100644 src/ROCrate/ISAProfile/Assay.fs create mode 100644 src/ROCrate/ISAProfile/Data.fs create mode 100644 src/ROCrate/ISAProfile/Dataset.fs create mode 100644 src/ROCrate/ISAProfile/Investigation.fs create mode 100644 src/ROCrate/ISAProfile/LabProcess.fs create mode 100644 src/ROCrate/ISAProfile/LabProtocol.fs create mode 100644 src/ROCrate/ISAProfile/Person.fs create mode 100644 src/ROCrate/ISAProfile/PropertyValue.fs create mode 100644 src/ROCrate/ISAProfile/Sample.fs create mode 100644 src/ROCrate/ISAProfile/ScholarlyArticle.fs create mode 100644 src/ROCrate/ISAProfile/Study.fs delete mode 100644 src/ROCrate/Library.fs create mode 100644 src/ROCrate/ROCrateObject.fs diff --git a/src/ROCrate/ARCtrl.ROCrate.fsproj b/src/ROCrate/ARCtrl.ROCrate.fsproj index c5ba9b84..960e4df5 100644 --- a/src/ROCrate/ARCtrl.ROCrate.fsproj +++ b/src/ROCrate/ARCtrl.ROCrate.fsproj @@ -5,11 +5,24 @@ true - + + + + + + + + + + + + + + - + Kevin Schneider, nfdi4plants, DataPLANT OSS contributors diff --git a/src/ROCrate/IROCrateObject.fs b/src/ROCrate/IROCrateObject.fs new file mode 100644 index 00000000..d4152b86 --- /dev/null +++ b/src/ROCrate/IROCrateObject.fs @@ -0,0 +1,7 @@ +namespace ARCtrl.ROCrate + +/// Base interface implemented by all explicitly known objects in our ROCrate profiles. +type IROCrateObject = + abstract member SchemaType : string + abstract member Id: string + abstract member AdditionalType: string option \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Assay.fs b/src/ROCrate/ISAProfile/Assay.fs new file mode 100644 index 00000000..1acc3200 --- /dev/null +++ b/src/ROCrate/ISAProfile/Assay.fs @@ -0,0 +1,46 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Assay(id: string) = + // inheritance + inherit Dataset(id, "Assay") + static member create( + // mandatory + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + // Properties from Dataset + ?measurementMethod, + ?measurementTechnique, + ?variableMeasured, + // Properties from CreativeWork + ?about, + ?comment, + ?creator, + ?hasPart, + ?url + ) = + let ds = Assay(id = id) + + // Properties from Dataset + DynObj.setValueOpt ds (nameof measurementMethod) measurementMethod + DynObj.setValueOpt ds (nameof measurementTechnique) measurementTechnique + DynObj.setValueOpt ds (nameof variableMeasured) variableMeasured + + // Properties from CreativeWork + DynObj.setValueOpt ds (nameof about) about + DynObj.setValueOpt ds (nameof comment) comment + DynObj.setValueOpt ds (nameof creator) creator + DynObj.setValueOpt ds (nameof hasPart) hasPart + DynObj.setValueOpt ds (nameof url) url + + // Properties from Thing + DynObj.setValue ds (nameof identifier) identifier + + ds \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Data.fs b/src/ROCrate/ISAProfile/Data.fs new file mode 100644 index 00000000..2e364633 --- /dev/null +++ b/src/ROCrate/ISAProfile/Data.fs @@ -0,0 +1,47 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Data(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "schema.org/MediaObject" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + ?comment, + ?encodingFormat, + ?disambiguatingDescription + ) = + let d = Data(id) + + DynObj.setValue d (nameof name) name + + DynObj.setValueOpt d (nameof comment) comment + DynObj.setValueOpt d (nameof encodingFormat) encodingFormat + DynObj.setValueOpt d (nameof disambiguatingDescription) disambiguatingDescription + + d \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Dataset.fs b/src/ROCrate/ISAProfile/Dataset.fs new file mode 100644 index 00000000..4b6043da --- /dev/null +++ b/src/ROCrate/ISAProfile/Dataset.fs @@ -0,0 +1,29 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Dataset (id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "schema.org/Dataset" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Investigation.fs b/src/ROCrate/ISAProfile/Investigation.fs new file mode 100644 index 00000000..2c748685 --- /dev/null +++ b/src/ROCrate/ISAProfile/Investigation.fs @@ -0,0 +1,49 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Investigation(id: string) = + + inherit Dataset(id, "Investigation") + + static member create( + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + ?citation, + ?comment, + ?creator, + ?dateCreated, + ?dateModified, + ?datePublished, + ?hasPart, + ?headline, + ?mentions, + ?url, + // Properties from Thing + ?description + ) = + let ds = Investigation(id = id) + + // Properties from CreativeWork + DynObj.setValueOpt ds (nameof citation) citation + DynObj.setValueOpt ds (nameof comment) comment + DynObj.setValueOpt ds (nameof creator) creator + DynObj.setValueOpt ds (nameof dateCreated) dateCreated + DynObj.setValueOpt ds (nameof dateModified) dateModified + DynObj.setValueOpt ds (nameof datePublished) datePublished + DynObj.setValueOpt ds (nameof hasPart) hasPart + DynObj.setValueOpt ds (nameof headline) headline + DynObj.setValueOpt ds (nameof mentions) mentions + DynObj.setValueOpt ds (nameof url) url + + // Properties from Thing + DynObj.setValueOpt ds (nameof description) description + DynObj.setValue ds (nameof identifier) identifier + + ds diff --git a/src/ROCrate/ISAProfile/LabProcess.fs b/src/ROCrate/ISAProfile/LabProcess.fs new file mode 100644 index 00000000..1c51884a --- /dev/null +++ b/src/ROCrate/ISAProfile/LabProcess.fs @@ -0,0 +1,58 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type LabProcess(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "bioschemas.org/LabProcess" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + agent, + object, + result, + // optional + ?additionalType, + ?executesLabProtocol, + ?parameterValue, + ?endTime, + ?disambiguatingDescription + ) = + let lp = LabProcess(id) + + DynObj.setValue lp (nameof name) name + DynObj.setValue lp (nameof agent) agent + DynObj.setValue lp (nameof object) object + DynObj.setValue lp (nameof result) result + + DynObj.setValueOpt lp (nameof additionalType) additionalType + DynObj.setValueOpt lp (nameof executesLabProtocol) executesLabProtocol + DynObj.setValueOpt lp (nameof parameterValue) parameterValue + DynObj.setValueOpt lp (nameof endTime) endTime + DynObj.setValueOpt lp (nameof disambiguatingDescription) disambiguatingDescription + + lp \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/LabProtocol.fs b/src/ROCrate/ISAProfile/LabProtocol.fs new file mode 100644 index 00000000..1cf5e599 --- /dev/null +++ b/src/ROCrate/ISAProfile/LabProtocol.fs @@ -0,0 +1,56 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type LabProtocol(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "bioschemas.org/LabProtocol" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + ?name, + ?intendedUse, + ?description, + ?url, + ?comment, + ?version, + ?labEquipment, + ?reagent, + ?computationalTool + ) = + let lp = LabProcess(id) + + DynObj.setValueOpt lp (nameof name) name + DynObj.setValueOpt lp (nameof intendedUse) intendedUse + DynObj.setValueOpt lp (nameof description) description + DynObj.setValueOpt lp (nameof url) url + DynObj.setValueOpt lp (nameof comment) comment + DynObj.setValueOpt lp (nameof version) version + DynObj.setValueOpt lp (nameof labEquipment) labEquipment + DynObj.setValueOpt lp (nameof reagent) reagent + DynObj.setValueOpt lp (nameof computationalTool) computationalTool + + lp diff --git a/src/ROCrate/ISAProfile/Person.fs b/src/ROCrate/ISAProfile/Person.fs new file mode 100644 index 00000000..d8f3fbab --- /dev/null +++ b/src/ROCrate/ISAProfile/Person.fs @@ -0,0 +1,61 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Person(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "schema.org/Person" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + givenName, + ?familyName, + ?email, + ?identifier, + ?affiliation, + ?jobTitle, + ?additionalName, + ?address, + ?telephone, + ?faxNumber, + ?disambiguatingDescription + ) = + let p = Person(id) + + DynObj.setValue p (nameof givenName) givenName + + DynObj.setValueOpt p (nameof familyName) familyName + DynObj.setValueOpt p (nameof email) email + DynObj.setValueOpt p (nameof identifier) identifier + DynObj.setValueOpt p (nameof affiliation) affiliation + DynObj.setValueOpt p (nameof jobTitle) jobTitle + DynObj.setValueOpt p (nameof additionalName) additionalName + DynObj.setValueOpt p (nameof address) address + DynObj.setValueOpt p (nameof telephone) telephone + DynObj.setValueOpt p (nameof faxNumber) faxNumber + DynObj.setValueOpt p (nameof disambiguatingDescription) disambiguatingDescription + + p diff --git a/src/ROCrate/ISAProfile/PropertyValue.fs b/src/ROCrate/ISAProfile/PropertyValue.fs new file mode 100644 index 00000000..98374604 --- /dev/null +++ b/src/ROCrate/ISAProfile/PropertyValue.fs @@ -0,0 +1,52 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type PropertyValue(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "schema.org/PropertyValue" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + value, + ?propertyID, + ?unitCode, + ?unitText, + ?valueReference, + ?additionalType + ) = + let pv = PropertyValue(id, ?additionalType = additionalType) + + DynObj.setValue pv (nameof name) name + DynObj.setValue pv (nameof value) value + + DynObj.setValueOpt pv (nameof propertyID) propertyID + DynObj.setValueOpt pv (nameof unitCode) unitCode + DynObj.setValueOpt pv (nameof unitText) unitText + DynObj.setValueOpt pv (nameof valueReference) valueReference + + pv \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Sample.fs b/src/ROCrate/ISAProfile/Sample.fs new file mode 100644 index 00000000..bdc75e4a --- /dev/null +++ b/src/ROCrate/ISAProfile/Sample.fs @@ -0,0 +1,45 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Sample(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "bioschemas.org/Sample" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + ?additionalProperty, + ?derivesFrom + ) = + let s = Sample(id) + + DynObj.setValue s (nameof name) name + + DynObj.setValueOpt s (nameof additionalProperty) additionalProperty + DynObj.setValueOpt s (nameof derivesFrom) derivesFrom + + s \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/ScholarlyArticle.fs b/src/ROCrate/ISAProfile/ScholarlyArticle.fs new file mode 100644 index 00000000..2e73c18c --- /dev/null +++ b/src/ROCrate/ISAProfile/ScholarlyArticle.fs @@ -0,0 +1,51 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type ScholarlyArticle(id: string, ?additionalType: string) = + inherit DynamicObj() + + let mutable _schemaType = "schema.org/ScholarlyArticle" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + headline, + identifier, + ?author, + ?url, + ?creativeWorkStatus, + ?disambiguatingDescription + ) = + let sa = ScholarlyArticle(id) + + DynObj.setValue sa (nameof headline) headline + DynObj.setValue sa (nameof identifier) identifier + + DynObj.setValueOpt sa (nameof author) author + DynObj.setValueOpt sa (nameof url) url + DynObj.setValueOpt sa (nameof creativeWorkStatus) creativeWorkStatus + DynObj.setValueOpt sa (nameof disambiguatingDescription) disambiguatingDescription + + sa \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Study.fs b/src/ROCrate/ISAProfile/Study.fs new file mode 100644 index 00000000..2f2d8549 --- /dev/null +++ b/src/ROCrate/ISAProfile/Study.fs @@ -0,0 +1,49 @@ +namespace ARCtrl.ROCrate + +open DynamicObj +open Fable.Core + +/// +[] +type Study(id: string) = + // inheritance + inherit Dataset(id, "Study") + static member create( + // mandatory + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + ?about, + ?citation, + ?comment, + ?creator, + ?dateCreated, + ?dateModified, + ?datePublished, + ?hasPart, + ?headline, + ?url, + // Properties from Thing + ?description + ) = + let ds = Study(id = id) + + // Properties from CreativeWork + DynObj.setValueOpt ds (nameof about) about + DynObj.setValueOpt ds (nameof citation) citation + DynObj.setValueOpt ds (nameof comment) comment + DynObj.setValueOpt ds (nameof creator) creator + DynObj.setValueOpt ds (nameof dateCreated) dateCreated + DynObj.setValueOpt ds (nameof dateModified) dateModified + DynObj.setValueOpt ds (nameof datePublished) datePublished + DynObj.setValueOpt ds (nameof hasPart) hasPart + DynObj.setValueOpt ds (nameof headline) headline + DynObj.setValueOpt ds (nameof url) url + + // Properties from Thing + DynObj.setValueOpt ds (nameof description) description + DynObj.setValue ds (nameof identifier) identifier + + ds diff --git a/src/ROCrate/Library.fs b/src/ROCrate/Library.fs deleted file mode 100644 index b50c5b70..00000000 --- a/src/ROCrate/Library.fs +++ /dev/null @@ -1,5 +0,0 @@ -namespace ARCtrl.ROCrate - -module Say = - let hello name = - printfn "Hello %s" name diff --git a/src/ROCrate/ROCrateObject.fs b/src/ROCrate/ROCrateObject.fs new file mode 100644 index 00000000..cb84b65c --- /dev/null +++ b/src/ROCrate/ROCrateObject.fs @@ -0,0 +1,35 @@ +namespace ARCtrl.ROCrate + +module ROCrateObject = + + let tryAsDataset (roco: IROCrateObject) = + match roco with + | :? Dataset as ds when ds.SchemaType = "schema.org/Dataset" -> Some ds + | _ -> None + + let tryAsInvestigation (roco: IROCrateObject) = + match roco.AdditionalType, roco.SchemaType with + | Some "Investigation", "schema.org/Dataset" -> + match roco with + | :? Investigation as ids -> Some ids + | _ -> None + | _ -> + None + + let tryAsStudy (roco: IROCrateObject) = + match roco.AdditionalType, roco.SchemaType with + | Some "Study", "schema.org/Dataset" -> + match roco with + | :? Study as sds -> Some sds + | _ -> None + | _ -> + None + + let tryAsAssay (roco: IROCrateObject) = + match roco.AdditionalType, roco.SchemaType with + | Some "Assay", "schema.org/Dataset" -> + match roco with + | :? Assay as ads -> Some ads + | _ -> None + | _ -> + None \ No newline at end of file diff --git a/src/ROCrate/playground.fsx b/src/ROCrate/playground.fsx index 35876a56..ac59fea0 100644 --- a/src/ROCrate/playground.fsx +++ b/src/ROCrate/playground.fsx @@ -10,11 +10,14 @@ type IROCrateObject = type Dataset (id: string, ?additionalType: string) = inherit DynamicObj() + let mutable _schemaType = "schema.org/Dataset" + member this.Id with get() = id member this.SchemaType - with get() = "schema.org/Dataset" + with get() = _schemaType + and set(value) = _schemaType <- value member this.AdditionalType = additionalType @@ -67,67 +70,6 @@ type InvestigationDataset(id: string) = ds - static member tryGetCitation (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "citation" with - | Some value -> Some value - | None -> None - - static member tryGetComment (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "comment" with - | Some value -> Some value - | None -> None - - static member tryGetCreator (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "creator" with - | Some value -> Some value - | None -> None - - static member tryGetDateCreated (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "dateCreated" with - | Some value -> Some value - | None -> None - - static member tryGetDateModified (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "dateModified" with - | Some value -> Some value - | None -> None - - static member tryGetDatePublished (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "datePublished" with - | Some value -> Some value - | None -> None - - static member tryGetHasPart (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "hasPart" with - | Some value -> Some value - | None -> None - - static member tryGetHeadline (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "headline" with - | Some value -> Some value - | None -> None - - static member tryGetMentions (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "mentions" with - | Some value -> Some value - | None -> None - - static member tryGetUrl (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "url" with - | Some value -> Some value - | None -> None - - static member tryGetDescription (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "description" with - | Some value -> Some value - | None -> None - - static member tryGetIdentifier (ds: InvestigationDataset) = - match DynObj.tryGetValue ds "identifier" with - | Some value -> Some value - | None -> None - - type StudyDataset(id: string) = // inheritance inherit Dataset(id, "Study") @@ -171,72 +113,6 @@ type StudyDataset(id: string) = ds - static member tryGetAbout (ds: StudyDataset) = - match DynObj.tryGetValue ds "about" with - | Some value -> Some value - | None -> None - - static member tryGetCitation (ds: StudyDataset) = - match DynObj.tryGetValue ds "citation" with - | Some value -> Some value - | None -> None - - static member tryGetComment (ds: StudyDataset) = - match DynObj.tryGetValue ds "comment" with - | Some value -> Some value - | None -> None - - static member tryGetCreator (ds: StudyDataset) = - match DynObj.tryGetValue ds "creator" with - | Some value -> Some value - | None -> None - - static member tryGetDateCreated (ds: StudyDataset) = - match DynObj.tryGetValue ds "dateCreated" with - | Some value -> Some value - | None -> None - - static member tryGetDateModified (ds: StudyDataset) = - match DynObj.tryGetValue ds "dateModified" with - | Some value -> Some value - | None -> None - - static member tryGetDatePublished (ds: StudyDataset) = - match DynObj.tryGetValue ds "datePublished" with - | Some value -> Some value - | None -> None - - static member tryGetHasPart (ds: StudyDataset) = - match DynObj.tryGetValue ds "hasPart" with - | Some value -> Some value - | None -> None - - static member tryGetHeadline (ds: StudyDataset) = - match DynObj.tryGetValue ds "headline" with - | Some value -> Some value - | None -> None - - static member tryGetMentions (ds: StudyDataset) = - match DynObj.tryGetValue ds "mentions" with - | Some value -> Some value - | None -> None - - static member tryGetUrl (ds: StudyDataset) = - match DynObj.tryGetValue ds "url" with - | Some value -> Some value - | None -> None - - static member tryGetIdentifier (ds: StudyDataset) = - match DynObj.tryGetValue ds "identifier" with - | Some value -> Some value - | None -> None - - static member tryGetDescription (ds: StudyDataset) = - match DynObj.tryGetValue ds "description" with - | Some value -> Some value - | None -> None - - type AssayDataset(id: string) = // inheritance inherit Dataset(id, "Assay") @@ -339,20 +215,27 @@ module ROCrateObject = let tryAsInvestigationDataset (roco: IROCrateObject) = match roco.AdditionalType, roco.SchemaType with | Some "Investigation", "schema.org/Dataset" -> - roco :?> InvestigationDataset |> Some // both type annotations are present + match roco with + | :? InvestigationDataset as ids -> Some ids + | _ -> None | _ -> None + let tryAsStudyDataset (roco: IROCrateObject) = match roco.AdditionalType, roco.SchemaType with | Some "Study", "schema.org/Dataset" -> - roco :?> StudyDataset |> Some // both type annotations are present + match roco with + | :? StudyDataset as sds -> Some sds + | _ -> None | _ -> None let tryAsAssayDataset (roco: IROCrateObject) = match roco.AdditionalType, roco.SchemaType with | Some "Assay", "schema.org/Dataset" -> - roco :?> AssayDataset |> Some // both type annotations are present + match roco with + | :? AssayDataset as ads -> Some ads + | _ -> None | _ -> None @@ -389,7 +272,6 @@ type LabProcess(id: string, ?additionalType: string) = ) = let lp = LabProcess(id) - DynObj.setValue lp (nameof id) id DynObj.setValue lp (nameof name) name DynObj.setValue lp (nameof agent) agent DynObj.setValue lp (nameof object) object @@ -403,3 +285,243 @@ type LabProcess(id: string, ?additionalType: string) = lp +type LabProtocol(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "bioschemas.org/LabProtocol" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + ?name, + ?intendedUse, + ?description, + ?url, + ?comment, + ?version, + ?labEquipment, + ?reagent, + ?computationalTool + ) = + let lp = LabProcess(id) + + DynObj.setValueOpt lp (nameof name) name + DynObj.setValueOpt lp (nameof intendedUse) intendedUse + DynObj.setValueOpt lp (nameof description) description + DynObj.setValueOpt lp (nameof url) url + DynObj.setValueOpt lp (nameof comment) comment + DynObj.setValueOpt lp (nameof version) version + DynObj.setValueOpt lp (nameof labEquipment) labEquipment + DynObj.setValueOpt lp (nameof reagent) reagent + DynObj.setValueOpt lp (nameof computationalTool) computationalTool + + lp + +type Sample(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "bioschemas.org/Sample" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + ?additionalProperty, + ?derivesFrom + ) = + let s = Sample(id) + + DynObj.setValue s (nameof name) name + + DynObj.setValueOpt s (nameof additionalProperty) additionalProperty + DynObj.setValueOpt s (nameof derivesFrom) derivesFrom + + s + +type Data(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "schema.org/MediaObject" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + ?comment, + ?encodingFormat, + ?disambiguatingDescription + ) = + let d = Data(id) + + DynObj.setValue d (nameof name) name + + DynObj.setValueOpt d (nameof comment) comment + DynObj.setValueOpt d (nameof encodingFormat) encodingFormat + DynObj.setValueOpt d (nameof disambiguatingDescription) disambiguatingDescription + + d + +type PropertyValue(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "schema.org/PropertyValue" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + name, + value, + ?propertyID, + ?unitCode, + ?unitText, + ?valueReference, + ?additionalType + ) = + let pv = PropertyValue(id, ?additionalType = additionalType) + + DynObj.setValue pv (nameof name) name + DynObj.setValue pv (nameof value) value + + DynObj.setValueOpt pv (nameof propertyID) propertyID + DynObj.setValueOpt pv (nameof unitCode) unitCode + DynObj.setValueOpt pv (nameof unitText) unitText + DynObj.setValueOpt pv (nameof valueReference) valueReference + + pv + +type Person(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "schema.org/Person" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + givenName, + ?familyName, + ?email, + ?identifier, + ?affiliation, + ?jobTitle, + ?additionalName, + ?address, + ?telephone, + ?faxNumber, + ?disambiguatingDescription + ) = + let p = Person(id) + + DynObj.setValue p (nameof givenName) givenName + + DynObj.setValueOpt p (nameof familyName) familyName + DynObj.setValueOpt p (nameof email) email + DynObj.setValueOpt p (nameof identifier) identifier + DynObj.setValueOpt p (nameof affiliation) affiliation + DynObj.setValueOpt p (nameof jobTitle) jobTitle + DynObj.setValueOpt p (nameof additionalName) additionalName + DynObj.setValueOpt p (nameof address) address + DynObj.setValueOpt p (nameof telephone) telephone + DynObj.setValueOpt p (nameof faxNumber) faxNumber + DynObj.setValueOpt p (nameof disambiguatingDescription) disambiguatingDescription + + p + + +type ScholarlyArticle(id: string, ?additionalType: string) = + inherit DynamicObj() + + member this.Id + with get() = id + + member this.SchemaType + with get() = "schema.org/ScholarlyArticle" + + member this.AdditionalType = additionalType + + //interface implementations + interface IROCrateObject with + member this.Id with get () = this.Id + member this.SchemaType with get (): string = this.SchemaType + member this.AdditionalType with get (): string option = this.AdditionalType + + static member create( + // mandatory + id, + headline, + identifier, + ?author, + ?url, + ?creativeWorkStatus, + ?disambiguatingDescription + ) = + let sa = ScholarlyArticle(id) + + DynObj.setValue sa (nameof headline) headline + DynObj.setValue sa (nameof identifier) identifier + + DynObj.setValueOpt sa (nameof author) author + DynObj.setValueOpt sa (nameof url) url + DynObj.setValueOpt sa (nameof creativeWorkStatus) creativeWorkStatus + DynObj.setValueOpt sa (nameof disambiguatingDescription) disambiguatingDescription + + sa \ No newline at end of file From 168ead84ca93dc0fae911e760673ef6e33180447 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 27 Aug 2024 12:52:04 +0200 Subject: [PATCH 04/15] add test project --- tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj | 20 ++++++++++++++++++++ tests/ROCrate/Main.fs | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj create mode 100644 tests/ROCrate/Main.fs diff --git a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj new file mode 100644 index 00000000..adc1a1b0 --- /dev/null +++ b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj @@ -0,0 +1,20 @@ + + + + Exe + net6.0 + false + + + + + + + + + + + + + + diff --git a/tests/ROCrate/Main.fs b/tests/ROCrate/Main.fs new file mode 100644 index 00000000..907f1d4f --- /dev/null +++ b/tests/ROCrate/Main.fs @@ -0,0 +1,8 @@ +module ROCrate.Tests + +open Fable.Pyxpecto + +let all = testSequenced <| testList "ROCrate" [] + +[] +let main argv = Pyxpecto.runTests [||] all From 2cea57cc1415310e36f5931ef376ea183b85fb71 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 27 Aug 2024 12:55:27 +0200 Subject: [PATCH 05/15] update solution --- ARCtrl.sln | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ARCtrl.sln b/ARCtrl.sln index 82ac26ff..e6c5457b 100644 --- a/ARCtrl.sln +++ b/ARCtrl.sln @@ -82,6 +82,10 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ARCtrl.Yaml.Tests", "tests\ EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ARCtrl.Contract.Tests", "tests\Contract\ARCtrl.Contract.Tests.fsproj", "{D10D12C7-B877-423B-867D-161D99E673C9}" EndProject +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ARCtrl.ROCrate", "src\ROCrate\ARCtrl.ROCrate.fsproj", "{658BF141-B4B5-4B90-891D-AC36A3FD7574}" +EndProject +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ARCtrl.ROCrate.Tests", "tests\ROCrate\ARCtrl.ROCrate.Tests.fsproj", "{212A1C64-02FC-465A-B0FA-F69735F37ACC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -168,6 +172,14 @@ Global {D10D12C7-B877-423B-867D-161D99E673C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {D10D12C7-B877-423B-867D-161D99E673C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {D10D12C7-B877-423B-867D-161D99E673C9}.Release|Any CPU.Build.0 = Release|Any CPU + {658BF141-B4B5-4B90-891D-AC36A3FD7574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {658BF141-B4B5-4B90-891D-AC36A3FD7574}.Debug|Any CPU.Build.0 = Debug|Any CPU + {658BF141-B4B5-4B90-891D-AC36A3FD7574}.Release|Any CPU.ActiveCfg = Release|Any CPU + {658BF141-B4B5-4B90-891D-AC36A3FD7574}.Release|Any CPU.Build.0 = Release|Any CPU + {212A1C64-02FC-465A-B0FA-F69735F37ACC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {212A1C64-02FC-465A-B0FA-F69735F37ACC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {212A1C64-02FC-465A-B0FA-F69735F37ACC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {212A1C64-02FC-465A-B0FA-F69735F37ACC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -194,6 +206,8 @@ Global {1CA11165-4B70-41D2-A846-50374E85385E} = {64B34A6E-318D-4E6E-9262-CE52C9B85A38} {5810EF87-4F85-4B4C-98E3-833AE914C628} = {64B34A6E-318D-4E6E-9262-CE52C9B85A38} {D10D12C7-B877-423B-867D-161D99E673C9} = {64B34A6E-318D-4E6E-9262-CE52C9B85A38} + {658BF141-B4B5-4B90-891D-AC36A3FD7574} = {6DA2330B-D407-4FB1-AF05-B0184034EC44} + {212A1C64-02FC-465A-B0FA-F69735F37ACC} = {64B34A6E-318D-4E6E-9262-CE52C9B85A38} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1E354DE6-99BA-421E-9EF8-E808B855A85F} From ccd18053a83c80f4ca4b7a2ac7008a4a0cf3d348 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 27 Aug 2024 16:20:07 +0200 Subject: [PATCH 06/15] Unify Inheritance to ROCrateObject --- tests/ROCrate/ISAProfile/Assay.Tests.fs | 30 ++++++++++++++++ tests/ROCrate/ISAProfile/Data.Tests.fs | 21 +++++++++++ tests/ROCrate/ISAProfile/Dataset.Tests.fs | 24 +++++++++++++ .../ROCrate/ISAProfile/Investigation.Tests.fs | 30 ++++++++++++++++ tests/ROCrate/ISAProfile/LabProcess.tests.fs | 20 +++++++++++ tests/ROCrate/ISAProfile/LabProtocol.Tests.fs | 20 +++++++++++ tests/ROCrate/ISAProfile/Person.Tests.fs | 20 +++++++++++ .../ROCrate/ISAProfile/PropertyValue.Tests.fs | 21 +++++++++++ tests/ROCrate/ISAProfile/Sample.tests.fs | 20 +++++++++++ .../ISAProfile/ScholarlyArticle.Tests.fs | 20 +++++++++++ tests/ROCrate/ISAProfile/Study.Tests.fs | 36 +++++++++++++++++++ 11 files changed, 262 insertions(+) create mode 100644 tests/ROCrate/ISAProfile/Assay.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/Data.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/Dataset.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/Investigation.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/LabProcess.tests.fs create mode 100644 tests/ROCrate/ISAProfile/LabProtocol.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/Person.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/PropertyValue.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/Sample.tests.fs create mode 100644 tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs create mode 100644 tests/ROCrate/ISAProfile/Study.Tests.fs diff --git a/tests/ROCrate/ISAProfile/Assay.Tests.fs b/tests/ROCrate/ISAProfile/Assay.Tests.fs new file mode 100644 index 00000000..db030b9c --- /dev/null +++ b/tests/ROCrate/ISAProfile/Assay.Tests.fs @@ -0,0 +1,30 @@ +module Tests.Assay + +open ARCtrl.ROCrate + +open TestingUtils + +let default_constructor = Assay("id") + +let tests_profile_object_is_valid = testList "profile object is valid" [ + testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory field Id was not correct" + testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory field SchemaType was not correct" + testCase "AdditionalType" <| fun _ -> Expect.equal default_constructor.AdditionalType (Some "Assay") "optional field AdditionalType was not correct" + testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" + + // default constructors are missing mandatory fields from the profile. This is by design. + testCase "missing identifier" <| fun _ -> Expect.throws (fun _ -> default_constructor.GetValue("identifier") |> ignore) "mandatory profile field identifier was present althoughit was expected to be missing" +] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Assay" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Data.Tests.fs b/tests/ROCrate/ISAProfile/Data.Tests.fs new file mode 100644 index 00000000..67935a70 --- /dev/null +++ b/tests/ROCrate/ISAProfile/Data.Tests.fs @@ -0,0 +1,21 @@ +module Tests.Data + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Data" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] + diff --git a/tests/ROCrate/ISAProfile/Dataset.Tests.fs b/tests/ROCrate/ISAProfile/Dataset.Tests.fs new file mode 100644 index 00000000..310f0e3a --- /dev/null +++ b/tests/ROCrate/ISAProfile/Dataset.Tests.fs @@ -0,0 +1,24 @@ +module Tests.Dataset + +open ARCtrl.ROCrate + +open TestingUtils + +let default_constructor = Dataset("id") + +let tests_profile_object_is_valid = testList "profile object is valid" [ + testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory field Id was not correct" + testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory field SchemaType was not correct" + testCase "AdditionalType" <| fun _ -> Expect.isNone default_constructor.AdditionalType "optional field AdditionalType was not correct" + testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" +] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Dataset" [ + tests_profile_object_is_valid + tests_interface_members + tests_dynamic_members +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Investigation.Tests.fs b/tests/ROCrate/ISAProfile/Investigation.Tests.fs new file mode 100644 index 00000000..ab58d9ca --- /dev/null +++ b/tests/ROCrate/ISAProfile/Investigation.Tests.fs @@ -0,0 +1,30 @@ +module Tests.Investigation + +open ARCtrl.ROCrate + +open TestingUtils + +let default_constructor = Investigation("id") + +let tests_profile_object_is_valid = testList "profile object is valid" [ + testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory field Id was not correct" + testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory field SchemaType was not correct" + testCase "AdditionalType" <| fun _ -> Expect.equal default_constructor.AdditionalType (Some "Investigation") "mandatory field AdditionalType was not correct" + testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" + + // default constructors are missing mandatory fields from the profile. This is by design. + testCase "missing identifier" <| fun _ -> Expect.throws (fun _ -> default_constructor.GetValue("identifier") |> ignore) "mandatory profile field identifier was present althoughit was expected to be missing" +] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Investigation" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/LabProcess.tests.fs b/tests/ROCrate/ISAProfile/LabProcess.tests.fs new file mode 100644 index 00000000..5053165b --- /dev/null +++ b/tests/ROCrate/ISAProfile/LabProcess.tests.fs @@ -0,0 +1,20 @@ +module Tests.LabProcess + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "LabProcess" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs b/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs new file mode 100644 index 00000000..af6106a3 --- /dev/null +++ b/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs @@ -0,0 +1,20 @@ +module Tests.LabProtocol + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "LabProtocol" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Person.Tests.fs b/tests/ROCrate/ISAProfile/Person.Tests.fs new file mode 100644 index 00000000..7d0bce7e --- /dev/null +++ b/tests/ROCrate/ISAProfile/Person.Tests.fs @@ -0,0 +1,20 @@ +module Tests.Person + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Person" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] diff --git a/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs b/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs new file mode 100644 index 00000000..00db974b --- /dev/null +++ b/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs @@ -0,0 +1,21 @@ +module Tests.PropertyValue + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "PropertyValue" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] + diff --git a/tests/ROCrate/ISAProfile/Sample.tests.fs b/tests/ROCrate/ISAProfile/Sample.tests.fs new file mode 100644 index 00000000..be83c15b --- /dev/null +++ b/tests/ROCrate/ISAProfile/Sample.tests.fs @@ -0,0 +1,20 @@ +module Tests.Sample + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Sample" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] diff --git a/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs b/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs new file mode 100644 index 00000000..014cdd00 --- /dev/null +++ b/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs @@ -0,0 +1,20 @@ +module Tests.ScholarlyArticle + +open ARCtrl.ROCrate + +open TestingUtils + +let tests_profile_object_is_valid = testList "profile object is valid" [] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "ScholarlyArticle" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] diff --git a/tests/ROCrate/ISAProfile/Study.Tests.fs b/tests/ROCrate/ISAProfile/Study.Tests.fs new file mode 100644 index 00000000..00a2f982 --- /dev/null +++ b/tests/ROCrate/ISAProfile/Study.Tests.fs @@ -0,0 +1,36 @@ +module Tests.Study + +open ARCtrl.ROCrate + +open TestingUtils + +let default_constructor = Study("id") + +let mandatory_properties = + +let all_properties = () + +let tests_profile_object_is_valid = testList "profile object is valid" [ + testList "default constructor" [ + testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory properties Id was not correct" + testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory property SchemaType was not correct" + testCase "AdditionalType" <| fun _ -> Expect.equal default_constructor.AdditionalType (Some "Study") "mandatory property AdditionalType was not correct" + testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" + + // default constructors are missing mandatory propertys from the profile. This is by design. + testCase "missing identifier" <| fun _ -> Expect.throws (fun _ -> default_constructor.GetValue("identifier") |> ignore) "mandatory profile property identifier was present althoughit was expected to be missing" + ] +] + +let tests_static_methods = testList "static methods" [] + +let tests_interface_members = testList "interface members" [] + +let tests_dynamic_members = testList "dynamic members" [] + +let main = testList "Study" [ + tests_profile_object_is_valid + tests_static_methods + tests_interface_members + tests_dynamic_members +] \ No newline at end of file From 95cab6f0f85f71a7adea887a25bd47c714e5af35 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 27 Aug 2024 17:25:49 +0200 Subject: [PATCH 07/15] wip ro-crate tests --- build/ProjectInfo.fs | 1 + src/ROCrate/ARCtrl.ROCrate.fsproj | 3 +- src/ROCrate/IROCrateObject.fs | 7 --- src/ROCrate/ISAProfile/Data.fs | 27 ++------- src/ROCrate/ISAProfile/Dataset.fs | 18 +----- src/ROCrate/ISAProfile/LabProcess.fs | 26 +------- src/ROCrate/ISAProfile/LabProtocol.fs | 27 ++------- src/ROCrate/ISAProfile/Person.fs | 27 ++------- src/ROCrate/ISAProfile/PropertyValue.fs | 24 +------- src/ROCrate/ISAProfile/Sample.fs | 27 ++------- src/ROCrate/ISAProfile/ScholarlyArticle.fs | 27 ++------- src/ROCrate/ROCrateObject.fs | 60 +++++++++---------- tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj | 20 ++++--- tests/ROCrate/Main.fs | 16 ++++- .../TestObjects.ROCrate/Common.fs | 4 ++ .../TestObjects.ROCrate/LabProcess.fs | 21 +++++++ .../TestObjects.ROCrate/Person.fs | 31 ++++++++++ .../TestObjects.ROCrate/PropertyValue.fs | 27 +++++++++ .../TestObjects.ROCrate/Sample.fs | 15 +++++ .../TestObjects.ROCrate/ScholarlyArtice.fs | 26 ++++++++ .../TestingUtils/TestObjects.ROCrate/Study.fs | 31 ++++++++++ tests/TestingUtils/TestingUtils.fsproj | 8 +++ 22 files changed, 248 insertions(+), 225 deletions(-) delete mode 100644 src/ROCrate/IROCrateObject.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/Common.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/Person.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/Sample.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/Study.fs diff --git a/build/ProjectInfo.fs b/build/ProjectInfo.fs index c74d1f2e..4101ad6b 100644 --- a/build/ProjectInfo.fs +++ b/build/ProjectInfo.fs @@ -16,6 +16,7 @@ let testProjects = "tests/Yaml" "tests/ValidationPackages" "tests/Contract" + "tests/ROCrate" ] /// Native JS test paths diff --git a/src/ROCrate/ARCtrl.ROCrate.fsproj b/src/ROCrate/ARCtrl.ROCrate.fsproj index 960e4df5..570746a1 100644 --- a/src/ROCrate/ARCtrl.ROCrate.fsproj +++ b/src/ROCrate/ARCtrl.ROCrate.fsproj @@ -5,7 +5,7 @@ true - + @@ -17,7 +17,6 @@ - diff --git a/src/ROCrate/IROCrateObject.fs b/src/ROCrate/IROCrateObject.fs deleted file mode 100644 index d4152b86..00000000 --- a/src/ROCrate/IROCrateObject.fs +++ /dev/null @@ -1,7 +0,0 @@ -namespace ARCtrl.ROCrate - -/// Base interface implemented by all explicitly known objects in our ROCrate profiles. -type IROCrateObject = - abstract member SchemaType : string - abstract member Id: string - abstract member AdditionalType: string option \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Data.fs b/src/ROCrate/ISAProfile/Data.fs index 2e364633..120146bf 100644 --- a/src/ROCrate/ISAProfile/Data.fs +++ b/src/ROCrate/ISAProfile/Data.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,37 +6,18 @@ open Fable.Core /// [] type Data(id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "schema.org/MediaObject" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "schema.org/MediaObject", ?additionalType = additionalType) static member create( // mandatory id, name, + ?additionalType, ?comment, ?encodingFormat, ?disambiguatingDescription ) = - let d = Data(id) + let d = Data(id, ?additionalType = additionalType) DynObj.setValue d (nameof name) name diff --git a/src/ROCrate/ISAProfile/Dataset.fs b/src/ROCrate/ISAProfile/Dataset.fs index 4b6043da..06923629 100644 --- a/src/ROCrate/ISAProfile/Dataset.fs +++ b/src/ROCrate/ISAProfile/Dataset.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,21 +6,7 @@ open Fable.Core /// [] type Dataset (id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "schema.org/Dataset" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value + inherit ROCrateObject(id = id, schemaType = "schema.org/Dataset", ?additionalType = additionalType) //interface implementations interface IROCrateObject with diff --git a/src/ROCrate/ISAProfile/LabProcess.fs b/src/ROCrate/ISAProfile/LabProcess.fs index 1c51884a..0a12e64b 100644 --- a/src/ROCrate/ISAProfile/LabProcess.fs +++ b/src/ROCrate/ISAProfile/LabProcess.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,27 +6,8 @@ open Fable.Core /// [] type LabProcess(id: string, ?additionalType: string) = - inherit DynamicObj() - let mutable _schemaType = "bioschemas.org/LabProcess" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "bioschemas.org/LabProcess", ?additionalType = additionalType) static member create( // mandatory @@ -42,14 +23,13 @@ type LabProcess(id: string, ?additionalType: string) = ?endTime, ?disambiguatingDescription ) = - let lp = LabProcess(id) + let lp = LabProcess(id, ?additionalType = additionalType) DynObj.setValue lp (nameof name) name DynObj.setValue lp (nameof agent) agent DynObj.setValue lp (nameof object) object DynObj.setValue lp (nameof result) result - DynObj.setValueOpt lp (nameof additionalType) additionalType DynObj.setValueOpt lp (nameof executesLabProtocol) executesLabProtocol DynObj.setValueOpt lp (nameof parameterValue) parameterValue DynObj.setValueOpt lp (nameof endTime) endTime diff --git a/src/ROCrate/ISAProfile/LabProtocol.fs b/src/ROCrate/ISAProfile/LabProtocol.fs index 1cf5e599..dec25a06 100644 --- a/src/ROCrate/ISAProfile/LabProtocol.fs +++ b/src/ROCrate/ISAProfile/LabProtocol.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,31 +6,12 @@ open Fable.Core /// [] type LabProtocol(id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "bioschemas.org/LabProtocol" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "bioschemas.org/LabProtocol", ?additionalType = additionalType) static member create( // mandatory id, + ?additionalType, ?name, ?intendedUse, ?description, @@ -41,7 +22,7 @@ type LabProtocol(id: string, ?additionalType: string) = ?reagent, ?computationalTool ) = - let lp = LabProcess(id) + let lp = LabProcess(id, ?additionalType = additionalType) DynObj.setValueOpt lp (nameof name) name DynObj.setValueOpt lp (nameof intendedUse) intendedUse diff --git a/src/ROCrate/ISAProfile/Person.fs b/src/ROCrate/ISAProfile/Person.fs index d8f3fbab..2b83bc23 100644 --- a/src/ROCrate/ISAProfile/Person.fs +++ b/src/ROCrate/ISAProfile/Person.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,32 +6,13 @@ open Fable.Core /// [] type Person(id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "schema.org/Person" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "schema.org/Person", ?additionalType = additionalType) static member create( // mandatory id, givenName, + ?additionalType, ?familyName, ?email, ?identifier, @@ -43,7 +24,7 @@ type Person(id: string, ?additionalType: string) = ?faxNumber, ?disambiguatingDescription ) = - let p = Person(id) + let p = Person(id, ?additionalType = additionalType) DynObj.setValue p (nameof givenName) givenName diff --git a/src/ROCrate/ISAProfile/PropertyValue.fs b/src/ROCrate/ISAProfile/PropertyValue.fs index 98374604..f99254f4 100644 --- a/src/ROCrate/ISAProfile/PropertyValue.fs +++ b/src/ROCrate/ISAProfile/PropertyValue.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,27 +6,7 @@ open Fable.Core /// [] type PropertyValue(id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "schema.org/PropertyValue" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "schema.org/PropertyValue", ?additionalType = additionalType) static member create( // mandatory diff --git a/src/ROCrate/ISAProfile/Sample.fs b/src/ROCrate/ISAProfile/Sample.fs index bdc75e4a..74410480 100644 --- a/src/ROCrate/ISAProfile/Sample.fs +++ b/src/ROCrate/ISAProfile/Sample.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,36 +6,17 @@ open Fable.Core /// [] type Sample(id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "bioschemas.org/Sample" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "bioschemas.org/Sample", ?additionalType = additionalType) static member create( // mandatory id, name, + ?additionalType, ?additionalProperty, ?derivesFrom ) = - let s = Sample(id) + let s = Sample(id, ?additionalType = additionalType) DynObj.setValue s (nameof name) name diff --git a/src/ROCrate/ISAProfile/ScholarlyArticle.fs b/src/ROCrate/ISAProfile/ScholarlyArticle.fs index 2e73c18c..877e8c6f 100644 --- a/src/ROCrate/ISAProfile/ScholarlyArticle.fs +++ b/src/ROCrate/ISAProfile/ScholarlyArticle.fs @@ -1,4 +1,4 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core @@ -6,39 +6,20 @@ open Fable.Core /// [] type ScholarlyArticle(id: string, ?additionalType: string) = - inherit DynamicObj() - - let mutable _schemaType = "schema.org/ScholarlyArticle" - let mutable _additionalType = additionalType - - member this.Id - with get() = id - - member this.SchemaType - with get() = _schemaType - and set(value) = _schemaType <- value - - member this.AdditionalType - with get() = _additionalType - and set(value) = _additionalType <- value - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType + inherit ROCrateObject(id = id, schemaType = "schema.org/ScholarlyArticle", ?additionalType = additionalType) static member create( // mandatory id, headline, identifier, + ?additionalType, ?author, ?url, ?creativeWorkStatus, ?disambiguatingDescription ) = - let sa = ScholarlyArticle(id) + let sa = ScholarlyArticle(id, ?additionalType = additionalType) DynObj.setValue sa (nameof headline) headline DynObj.setValue sa (nameof identifier) identifier diff --git a/src/ROCrate/ROCrateObject.fs b/src/ROCrate/ROCrateObject.fs index cb84b65c..5f9c57de 100644 --- a/src/ROCrate/ROCrateObject.fs +++ b/src/ROCrate/ROCrateObject.fs @@ -1,35 +1,33 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate -module ROCrateObject = - - let tryAsDataset (roco: IROCrateObject) = - match roco with - | :? Dataset as ds when ds.SchemaType = "schema.org/Dataset" -> Some ds - | _ -> None +open DynamicObj + +/// Base interface implemented by all explicitly known objects in our ROCrate profiles. +type IROCrateObject = + abstract member SchemaType : string + abstract member Id: string + abstract member AdditionalType: string option + +/// Base class for all explicitly known objects in our ROCrate profiles to inherit from. +/// Basically a DynamicObj that implements the IROPCrateObject interface. +type ROCrateObject(id:string, schemaType: string, ?additionalType) = + inherit DynamicObj() - let tryAsInvestigation (roco: IROCrateObject) = - match roco.AdditionalType, roco.SchemaType with - | Some "Investigation", "schema.org/Dataset" -> - match roco with - | :? Investigation as ids -> Some ids - | _ -> None - | _ -> - None + let mutable _schemaType = "schema.org/Dataset" + let mutable _additionalType = additionalType + + member this.Id + with get() = id + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value - let tryAsStudy (roco: IROCrateObject) = - match roco.AdditionalType, roco.SchemaType with - | Some "Study", "schema.org/Dataset" -> - match roco with - | :? Study as sds -> Some sds - | _ -> None - | _ -> - None + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value - let tryAsAssay (roco: IROCrateObject) = - match roco.AdditionalType, roco.SchemaType with - | Some "Assay", "schema.org/Dataset" -> - match roco with - | :? Assay as ads -> Some ads - | _ -> None - | _ -> - None \ No newline at end of file + interface IROCrateObject with + member this.SchemaType = schemaType + member this.Id = id + member this.AdditionalType = additionalType \ No newline at end of file diff --git a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj index adc1a1b0..5f30bba0 100644 --- a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj +++ b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj @@ -1,20 +1,26 @@ - + Exe - net6.0 + net8.0 false - + + + + + + + + + + + - - - - diff --git a/tests/ROCrate/Main.fs b/tests/ROCrate/Main.fs index 907f1d4f..7cc29817 100644 --- a/tests/ROCrate/Main.fs +++ b/tests/ROCrate/Main.fs @@ -1,8 +1,20 @@ -module ROCrate.Tests +module ROCrate.Tests open Fable.Pyxpecto -let all = testSequenced <| testList "ROCrate" [] +let all = testSequenced <| testList "ROCrate" [ + Tests.Dataset.main + Tests.Investigation.main + Tests.Study.main + Tests.Assay.main + Tests.LabProcess.main + Tests.LabProtocol.main + Tests.Sample.main + Tests.Data.main + Tests.PropertyValue.main + Tests.Person.main + Tests.ScholarlyArticle.main +] [] let main argv = Pyxpecto.runTests [||] all diff --git a/tests/TestingUtils/TestObjects.ROCrate/Common.fs b/tests/TestingUtils/TestObjects.ROCrate/Common.fs new file mode 100644 index 00000000..37c88778 --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/Common.fs @@ -0,0 +1,4 @@ +module TestObjects.ROCrate.Common + +let testDateTime = System.DateTime.Parse("01/01/2024").ToString("s", System.Globalization.CultureInfo.InvariantCulture) +let testDate = System.DateTime.Parse("01/01/2024").ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs b/tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs new file mode 100644 index 00000000..38c7a751 --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs @@ -0,0 +1,21 @@ +module TestObjects.ROCrate.LabProcess + +open ARCtrl.ROCrate + +let mandatory_properties() = + + let lp = LabProcess("lab_process_id_1") + + lp.SetValue("name","name") + lp.SetValue("agent","name") + lp.SetValue("object", Sample.mandatory_properties()) + lp.SetValue("result","name") + + + lp + +let all_properties() = + + let lp = LabProcess("lab_process_id_2", "additionalType") + + lp \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Person.fs b/tests/TestingUtils/TestObjects.ROCrate/Person.fs new file mode 100644 index 00000000..eb6f2d25 --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/Person.fs @@ -0,0 +1,31 @@ +module TestObjects.ROCrate.Person + +open ARCtrl.ROCrate +open DynamicObj + +let mandatory_properties() = + + let s = Person("person_id_1") + + s.SetValue("givenName","givenName") + + s + +let all_properties() = + + let s = Person("person_id_2", "additionalType") + + s.SetValue("givenName","givenName") + + s.SetValue("familyName","familyName") + s.SetValue("email","email") + s.SetValue("identifier","identifier") + s.SetValue("affiliation", ROCrateObject("organization_id","schema.org/Organization")) + s.SetValue("jobTitle", ROCrateObject("defined_term_id","schema.org/DefinedTerm")) + s.SetValue("additionalName","additionalName") + s.SetValue("address","address") + s.SetValue("telephone","telephone") + s.SetValue("faxNumber","faxNumber") + s.SetValue("disambiguatingDescription","disambiguatingDescription") + + s \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs b/tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs new file mode 100644 index 00000000..abedb02b --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs @@ -0,0 +1,27 @@ +module TestObjects.ROCrate.PropertyValue + +open ARCtrl.ROCrate +open DynamicObj + +let mandatory_properties() = + + let pv = PropertyValue("property_value_id_1") + + pv.SetValue("name","name") + pv.SetValue("value","value") + + pv + +let all_properties() = + + let pv = PropertyValue("property_value_id_2", "additionalType") + + pv.SetValue("name","name") + pv.SetValue("value","value") + + pv.SetValue("propertyID","propertyID") + pv.SetValue("unitCode","unitCode") + pv.SetValue("unitText","unitText") + pv.SetValue("valueReference","valueReference") + + pv \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Sample.fs b/tests/TestingUtils/TestObjects.ROCrate/Sample.fs new file mode 100644 index 00000000..3345700b --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/Sample.fs @@ -0,0 +1,15 @@ +module TestObjects.ROCrate.Sample + +open ARCtrl.ROCrate + +let mandatory_properties() = + + let s = Sample("sample_id_1") + + s + +let all_properties() = + + let s = Sample("sample_id_2", "additionalType") + + s \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs b/tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs new file mode 100644 index 00000000..ca478a0a --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs @@ -0,0 +1,26 @@ +module TestObjects.ROCrate.ScholarlyArticle + +open ARCtrl.ROCrate +open DynamicObj + +let mandatory_properties() = + + let s = ScholarlyArticle("scholarly_article_id_1") + + s.SetValue("headline","headline") + s.SetValue("identifier","identifier") + + s + +let all_properties() = + + let s = ScholarlyArticle("scholarly_article_id_2", "additionalType") + + s.SetValue("headline","headline") + s.SetValue("identifier","identifier") + + s.SetValue("author",(TestObjects.ROCrate.Person.all_properties())) + s.SetValue("creativeWorkStatus", ROCrateObject("defined_term_id","schema.org/DefinedTerm")) + s.SetValue("disambiguatingDescription", "disambiguatingDescription") + + s \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Study.fs b/tests/TestingUtils/TestObjects.ROCrate/Study.fs new file mode 100644 index 00000000..9899a6fd --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/Study.fs @@ -0,0 +1,31 @@ +module TestObjects.ROCrate.Study + +open ARCtrl.ROCrate + +let mandatory_properties() = + + let s = Study("study_id_1") + + s.SetValue("identifier", "identifier") + + s + +let all_properties() = + + let s = Study("study_id_2") + + s.SetValue("identifier", "identifier") + + s.SetValue("creator", Person.all_properties()) + s.SetValue("headline", "headline") + s.SetValue("hasPart", ROCrateObject("file_id_1","schema.org/MediaObject")) + s.SetValue("about", LabProcess.all_properties()) + s.SetValue("description", "description") + s.SetValue("dateCreated", Common.testDateTime) + s.SetValue("datePublished", Common.testDate) + s.SetValue("dateModified", Common.testDate) + s.SetValue("citation", ScholarlyArticle.all_properties()) + s.SetValue("comment", "") + s.SetValue("url", "url") + + s \ No newline at end of file diff --git a/tests/TestingUtils/TestingUtils.fsproj b/tests/TestingUtils/TestingUtils.fsproj index 782d49df..b3382527 100644 --- a/tests/TestingUtils/TestingUtils.fsproj +++ b/tests/TestingUtils/TestingUtils.fsproj @@ -5,6 +5,13 @@ true + + + + + + + @@ -32,5 +39,6 @@ + \ No newline at end of file From 9ef48d75f5439d3a71ca943941b70c5af3ff9261 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 28 Aug 2024 15:38:01 +0200 Subject: [PATCH 08/15] only use primary constructor --- src/ROCrate/ISAProfile/Assay.fs | 61 +++++++----------- src/ROCrate/ISAProfile/Data.fs | 31 ++++------ src/ROCrate/ISAProfile/Dataset.fs | 2 +- src/ROCrate/ISAProfile/Investigation.fs | 72 ++++++++++------------ src/ROCrate/ISAProfile/LabProcess.fs | 50 +++++++-------- src/ROCrate/ISAProfile/LabProtocol.fs | 52 +++++++--------- src/ROCrate/ISAProfile/Person.fs | 59 ++++++++---------- src/ROCrate/ISAProfile/PropertyValue.fs | 39 +++++------- src/ROCrate/ISAProfile/Sample.fs | 28 ++++----- src/ROCrate/ISAProfile/ScholarlyArticle.fs | 40 ++++++------ src/ROCrate/ISAProfile/Study.fs | 69 +++++++++------------ 11 files changed, 216 insertions(+), 287 deletions(-) diff --git a/src/ROCrate/ISAProfile/Assay.fs b/src/ROCrate/ISAProfile/Assay.fs index 1acc3200..152c9403 100644 --- a/src/ROCrate/ISAProfile/Assay.fs +++ b/src/ROCrate/ISAProfile/Assay.fs @@ -1,46 +1,31 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core /// [] -type Assay(id: string) = - // inheritance +type Assay( + id, + identifier, + ?about, + ?comment, + ?creator, + ?hasPart, + ?measurementMethod, + ?measurementTechnique, + ?url, + ?variableMeasured +) as this = inherit Dataset(id, "Assay") - static member create( - // mandatory - id, - // Properties from Thing - identifier, - // optional - // Properties from CreativeWork - // Properties from Dataset - ?measurementMethod, - ?measurementTechnique, - ?variableMeasured, - // Properties from CreativeWork - ?about, - ?comment, - ?creator, - ?hasPart, - ?url - ) = - let ds = Assay(id = id) + do + DynObj.setValue this (nameof identifier) identifier - // Properties from Dataset - DynObj.setValueOpt ds (nameof measurementMethod) measurementMethod - DynObj.setValueOpt ds (nameof measurementTechnique) measurementTechnique - DynObj.setValueOpt ds (nameof variableMeasured) variableMeasured - - // Properties from CreativeWork - DynObj.setValueOpt ds (nameof about) about - DynObj.setValueOpt ds (nameof comment) comment - DynObj.setValueOpt ds (nameof creator) creator - DynObj.setValueOpt ds (nameof hasPart) hasPart - DynObj.setValueOpt ds (nameof url) url - - // Properties from Thing - DynObj.setValue ds (nameof identifier) identifier - - ds \ No newline at end of file + DynObj.setValueOpt this (nameof measurementMethod) measurementMethod + DynObj.setValueOpt this (nameof measurementTechnique) measurementTechnique + DynObj.setValueOpt this (nameof variableMeasured) variableMeasured + DynObj.setValueOpt this (nameof about) about + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof creator) creator + DynObj.setValueOpt this (nameof hasPart) hasPart + DynObj.setValueOpt this (nameof url) url \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Data.fs b/src/ROCrate/ISAProfile/Data.fs index 120146bf..476e9d68 100644 --- a/src/ROCrate/ISAProfile/Data.fs +++ b/src/ROCrate/ISAProfile/Data.fs @@ -5,24 +5,19 @@ open Fable.Core /// [] -type Data(id: string, ?additionalType: string) = +type Data( + id, + name, + ?additionalType, + ?comment, + ?encodingFormat, + ?disambiguatingDescription +) as this = inherit ROCrateObject(id = id, schemaType = "schema.org/MediaObject", ?additionalType = additionalType) + do + DynObj.setValue this (nameof name) name - static member create( - // mandatory - id, - name, - ?additionalType, - ?comment, - ?encodingFormat, - ?disambiguatingDescription - ) = - let d = Data(id, ?additionalType = additionalType) + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof encodingFormat) encodingFormat + DynObj.setValueOpt this (nameof disambiguatingDescription) disambiguatingDescription - DynObj.setValue d (nameof name) name - - DynObj.setValueOpt d (nameof comment) comment - DynObj.setValueOpt d (nameof encodingFormat) encodingFormat - DynObj.setValueOpt d (nameof disambiguatingDescription) disambiguatingDescription - - d \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Dataset.fs b/src/ROCrate/ISAProfile/Dataset.fs index 06923629..fd85b239 100644 --- a/src/ROCrate/ISAProfile/Dataset.fs +++ b/src/ROCrate/ISAProfile/Dataset.fs @@ -2,7 +2,7 @@ namespace ARCtrl.ROCrate open DynamicObj open Fable.Core - + /// [] type Dataset (id: string, ?additionalType: string) = diff --git a/src/ROCrate/ISAProfile/Investigation.fs b/src/ROCrate/ISAProfile/Investigation.fs index 2c748685..31213679 100644 --- a/src/ROCrate/ISAProfile/Investigation.fs +++ b/src/ROCrate/ISAProfile/Investigation.fs @@ -1,49 +1,43 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core /// [] -type Investigation(id: string) = - +type Investigation( + id, + // Properties from Thing + identifier, + // optional + // Properties from CreativeWork + ?citation, + ?comment, + ?creator, + ?dateCreated, + ?dateModified, + ?datePublished, + ?hasPart, + ?headline, + ?mentions, + ?url, + // Properties from Thing + ?description +) as this = inherit Dataset(id, "Investigation") - - static member create( - id, - // Properties from Thing - identifier, - // optional + do // Properties from CreativeWork - ?citation, - ?comment, - ?creator, - ?dateCreated, - ?dateModified, - ?datePublished, - ?hasPart, - ?headline, - ?mentions, - ?url, - // Properties from Thing - ?description - ) = - let ds = Investigation(id = id) - - // Properties from CreativeWork - DynObj.setValueOpt ds (nameof citation) citation - DynObj.setValueOpt ds (nameof comment) comment - DynObj.setValueOpt ds (nameof creator) creator - DynObj.setValueOpt ds (nameof dateCreated) dateCreated - DynObj.setValueOpt ds (nameof dateModified) dateModified - DynObj.setValueOpt ds (nameof datePublished) datePublished - DynObj.setValueOpt ds (nameof hasPart) hasPart - DynObj.setValueOpt ds (nameof headline) headline - DynObj.setValueOpt ds (nameof mentions) mentions - DynObj.setValueOpt ds (nameof url) url + DynObj.setValueOpt this (nameof citation) citation + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof creator) creator + DynObj.setValueOpt this (nameof dateCreated) dateCreated + DynObj.setValueOpt this (nameof dateModified) dateModified + DynObj.setValueOpt this (nameof datePublished) datePublished + DynObj.setValueOpt this (nameof hasPart) hasPart + DynObj.setValueOpt this (nameof headline) headline + DynObj.setValueOpt this (nameof mentions) mentions + DynObj.setValueOpt this (nameof url) url // Properties from Thing - DynObj.setValueOpt ds (nameof description) description - DynObj.setValue ds (nameof identifier) identifier - - ds + DynObj.setValueOpt this (nameof description) description + DynObj.setValue this (nameof identifier) identifier diff --git a/src/ROCrate/ISAProfile/LabProcess.fs b/src/ROCrate/ISAProfile/LabProcess.fs index 0a12e64b..a92bb6b9 100644 --- a/src/ROCrate/ISAProfile/LabProcess.fs +++ b/src/ROCrate/ISAProfile/LabProcess.fs @@ -5,34 +5,26 @@ open Fable.Core /// [] -type LabProcess(id: string, ?additionalType: string) = - +type LabProcess( + id, + name, + agent, + object, + result, + ?additionalType, + ?executesLabProtocol, + ?parameterValue, + ?endTime, + ?disambiguatingDescription +) as this = inherit ROCrateObject(id = id, schemaType = "bioschemas.org/LabProcess", ?additionalType = additionalType) + do + DynObj.setValue this (nameof name) name + DynObj.setValue this (nameof agent) agent + DynObj.setValue this (nameof object) object + DynObj.setValue this (nameof result) result - static member create( - // mandatory - id, - name, - agent, - object, - result, - // optional - ?additionalType, - ?executesLabProtocol, - ?parameterValue, - ?endTime, - ?disambiguatingDescription - ) = - let lp = LabProcess(id, ?additionalType = additionalType) - - DynObj.setValue lp (nameof name) name - DynObj.setValue lp (nameof agent) agent - DynObj.setValue lp (nameof object) object - DynObj.setValue lp (nameof result) result - - DynObj.setValueOpt lp (nameof executesLabProtocol) executesLabProtocol - DynObj.setValueOpt lp (nameof parameterValue) parameterValue - DynObj.setValueOpt lp (nameof endTime) endTime - DynObj.setValueOpt lp (nameof disambiguatingDescription) disambiguatingDescription - - lp \ No newline at end of file + DynObj.setValueOpt this (nameof executesLabProtocol) executesLabProtocol + DynObj.setValueOpt this (nameof parameterValue) parameterValue + DynObj.setValueOpt this (nameof endTime) endTime + DynObj.setValueOpt this (nameof disambiguatingDescription) disambiguatingDescription \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/LabProtocol.fs b/src/ROCrate/ISAProfile/LabProtocol.fs index dec25a06..ec830005 100644 --- a/src/ROCrate/ISAProfile/LabProtocol.fs +++ b/src/ROCrate/ISAProfile/LabProtocol.fs @@ -5,33 +5,27 @@ open Fable.Core /// [] -type LabProtocol(id: string, ?additionalType: string) = +type LabProtocol( + id, + ?additionalType, + ?name, + ?intendedUse, + ?description, + ?url, + ?comment, + ?version, + ?labEquipment, + ?reagent, + ?computationalTool +) as this = inherit ROCrateObject(id = id, schemaType = "bioschemas.org/LabProtocol", ?additionalType = additionalType) - - static member create( - // mandatory - id, - ?additionalType, - ?name, - ?intendedUse, - ?description, - ?url, - ?comment, - ?version, - ?labEquipment, - ?reagent, - ?computationalTool - ) = - let lp = LabProcess(id, ?additionalType = additionalType) - - DynObj.setValueOpt lp (nameof name) name - DynObj.setValueOpt lp (nameof intendedUse) intendedUse - DynObj.setValueOpt lp (nameof description) description - DynObj.setValueOpt lp (nameof url) url - DynObj.setValueOpt lp (nameof comment) comment - DynObj.setValueOpt lp (nameof version) version - DynObj.setValueOpt lp (nameof labEquipment) labEquipment - DynObj.setValueOpt lp (nameof reagent) reagent - DynObj.setValueOpt lp (nameof computationalTool) computationalTool - - lp + do + DynObj.setValueOpt this (nameof name) name + DynObj.setValueOpt this (nameof intendedUse) intendedUse + DynObj.setValueOpt this (nameof description) description + DynObj.setValueOpt this (nameof url) url + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof version) version + DynObj.setValueOpt this (nameof labEquipment) labEquipment + DynObj.setValueOpt this (nameof reagent) reagent + DynObj.setValueOpt this (nameof computationalTool) computationalTool diff --git a/src/ROCrate/ISAProfile/Person.fs b/src/ROCrate/ISAProfile/Person.fs index 2b83bc23..39aa17be 100644 --- a/src/ROCrate/ISAProfile/Person.fs +++ b/src/ROCrate/ISAProfile/Person.fs @@ -5,38 +5,33 @@ open Fable.Core /// [] -type Person(id: string, ?additionalType: string) = +type Person( + id, + givenName, + ?additionalType, + ?familyName, + ?email, + ?identifier, + ?affiliation, + ?jobTitle, + ?additionalName, + ?address, + ?telephone, + ?faxNumber, + ?disambiguatingDescription +) as this= inherit ROCrateObject(id = id, schemaType = "schema.org/Person", ?additionalType = additionalType) + do - static member create( - // mandatory - id, - givenName, - ?additionalType, - ?familyName, - ?email, - ?identifier, - ?affiliation, - ?jobTitle, - ?additionalName, - ?address, - ?telephone, - ?faxNumber, - ?disambiguatingDescription - ) = - let p = Person(id, ?additionalType = additionalType) + DynObj.setValue this (nameof givenName) givenName - DynObj.setValue p (nameof givenName) givenName - - DynObj.setValueOpt p (nameof familyName) familyName - DynObj.setValueOpt p (nameof email) email - DynObj.setValueOpt p (nameof identifier) identifier - DynObj.setValueOpt p (nameof affiliation) affiliation - DynObj.setValueOpt p (nameof jobTitle) jobTitle - DynObj.setValueOpt p (nameof additionalName) additionalName - DynObj.setValueOpt p (nameof address) address - DynObj.setValueOpt p (nameof telephone) telephone - DynObj.setValueOpt p (nameof faxNumber) faxNumber - DynObj.setValueOpt p (nameof disambiguatingDescription) disambiguatingDescription - - p + DynObj.setValueOpt this (nameof familyName) familyName + DynObj.setValueOpt this (nameof email) email + DynObj.setValueOpt this (nameof identifier) identifier + DynObj.setValueOpt this (nameof affiliation) affiliation + DynObj.setValueOpt this (nameof jobTitle) jobTitle + DynObj.setValueOpt this (nameof additionalName) additionalName + DynObj.setValueOpt this (nameof address) address + DynObj.setValueOpt this (nameof telephone) telephone + DynObj.setValueOpt this (nameof faxNumber) faxNumber + DynObj.setValueOpt this (nameof disambiguatingDescription) disambiguatingDescription diff --git a/src/ROCrate/ISAProfile/PropertyValue.fs b/src/ROCrate/ISAProfile/PropertyValue.fs index f99254f4..886d694f 100644 --- a/src/ROCrate/ISAProfile/PropertyValue.fs +++ b/src/ROCrate/ISAProfile/PropertyValue.fs @@ -5,28 +5,23 @@ open Fable.Core /// [] -type PropertyValue(id: string, ?additionalType: string) = +type PropertyValue( + id, + name, + value, + ?propertyID, + ?unitCode, + ?unitText, + ?valueReference, + ?additionalType +) as this = inherit ROCrateObject(id = id, schemaType = "schema.org/PropertyValue", ?additionalType = additionalType) + do - static member create( - // mandatory - id, - name, - value, - ?propertyID, - ?unitCode, - ?unitText, - ?valueReference, - ?additionalType - ) = - let pv = PropertyValue(id, ?additionalType = additionalType) + DynObj.setValue this (nameof name) name + DynObj.setValue this (nameof value) value - DynObj.setValue pv (nameof name) name - DynObj.setValue pv (nameof value) value - - DynObj.setValueOpt pv (nameof propertyID) propertyID - DynObj.setValueOpt pv (nameof unitCode) unitCode - DynObj.setValueOpt pv (nameof unitText) unitText - DynObj.setValueOpt pv (nameof valueReference) valueReference - - pv \ No newline at end of file + DynObj.setValueOpt this (nameof propertyID) propertyID + DynObj.setValueOpt this (nameof unitCode) unitCode + DynObj.setValueOpt this (nameof unitText) unitText + DynObj.setValueOpt this (nameof valueReference) valueReference diff --git a/src/ROCrate/ISAProfile/Sample.fs b/src/ROCrate/ISAProfile/Sample.fs index 74410480..e03deab3 100644 --- a/src/ROCrate/ISAProfile/Sample.fs +++ b/src/ROCrate/ISAProfile/Sample.fs @@ -5,22 +5,16 @@ open Fable.Core /// [] -type Sample(id: string, ?additionalType: string) = +type Sample( + id, + name, + ?additionalType, + ?additionalProperty, + ?derivesFrom +) as this = inherit ROCrateObject(id = id, schemaType = "bioschemas.org/Sample", ?additionalType = additionalType) + do + DynObj.setValue this (nameof name) name - static member create( - // mandatory - id, - name, - ?additionalType, - ?additionalProperty, - ?derivesFrom - ) = - let s = Sample(id, ?additionalType = additionalType) - - DynObj.setValue s (nameof name) name - - DynObj.setValueOpt s (nameof additionalProperty) additionalProperty - DynObj.setValueOpt s (nameof derivesFrom) derivesFrom - - s \ No newline at end of file + DynObj.setValueOpt this (nameof additionalProperty) additionalProperty + DynObj.setValueOpt this (nameof derivesFrom) derivesFrom diff --git a/src/ROCrate/ISAProfile/ScholarlyArticle.fs b/src/ROCrate/ISAProfile/ScholarlyArticle.fs index 877e8c6f..797b611a 100644 --- a/src/ROCrate/ISAProfile/ScholarlyArticle.fs +++ b/src/ROCrate/ISAProfile/ScholarlyArticle.fs @@ -5,28 +5,24 @@ open Fable.Core /// [] -type ScholarlyArticle(id: string, ?additionalType: string) = - inherit ROCrateObject(id = id, schemaType = "schema.org/ScholarlyArticle", ?additionalType = additionalType) - - static member create( - // mandatory - id, - headline, - identifier, - ?additionalType, - ?author, - ?url, - ?creativeWorkStatus, - ?disambiguatingDescription - ) = - let sa = ScholarlyArticle(id, ?additionalType = additionalType) +type ScholarlyArticle( + id, + headline, + identifier, + ?additionalType, + ?author, + ?url, + ?creativeWorkStatus, + ?disambiguatingDescription - DynObj.setValue sa (nameof headline) headline - DynObj.setValue sa (nameof identifier) identifier +) as this = + inherit ROCrateObject(id = id, schemaType = "schema.org/ScholarlyArticle", ?additionalType = additionalType) + do - DynObj.setValueOpt sa (nameof author) author - DynObj.setValueOpt sa (nameof url) url - DynObj.setValueOpt sa (nameof creativeWorkStatus) creativeWorkStatus - DynObj.setValueOpt sa (nameof disambiguatingDescription) disambiguatingDescription + DynObj.setValue this (nameof headline) headline + DynObj.setValue this (nameof identifier) identifier - sa \ No newline at end of file + DynObj.setValueOpt this (nameof author) author + DynObj.setValueOpt this (nameof url) url + DynObj.setValueOpt this (nameof creativeWorkStatus) creativeWorkStatus + DynObj.setValueOpt this (nameof disambiguatingDescription) disambiguatingDescription \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Study.fs b/src/ROCrate/ISAProfile/Study.fs index 2f2d8549..e8007004 100644 --- a/src/ROCrate/ISAProfile/Study.fs +++ b/src/ROCrate/ISAProfile/Study.fs @@ -1,49 +1,38 @@ -namespace ARCtrl.ROCrate +namespace ARCtrl.ROCrate open DynamicObj open Fable.Core /// [] -type Study(id: string) = - // inheritance +type Study( + id, + identifier, + ?about, + ?citation, + ?comment, + ?creator, + ?dateCreated, + ?dateModified, + ?datePublished, + ?description, + ?hasPart, + ?headline, + ?url +) as this = inherit Dataset(id, "Study") - static member create( - // mandatory - id, - // Properties from Thing - identifier, - // optional - // Properties from CreativeWork - ?about, - ?citation, - ?comment, - ?creator, - ?dateCreated, - ?dateModified, - ?datePublished, - ?hasPart, - ?headline, - ?url, - // Properties from Thing - ?description - ) = - let ds = Study(id = id) + do + DynObj.setValue this (nameof identifier) identifier - // Properties from CreativeWork - DynObj.setValueOpt ds (nameof about) about - DynObj.setValueOpt ds (nameof citation) citation - DynObj.setValueOpt ds (nameof comment) comment - DynObj.setValueOpt ds (nameof creator) creator - DynObj.setValueOpt ds (nameof dateCreated) dateCreated - DynObj.setValueOpt ds (nameof dateModified) dateModified - DynObj.setValueOpt ds (nameof datePublished) datePublished - DynObj.setValueOpt ds (nameof hasPart) hasPart - DynObj.setValueOpt ds (nameof headline) headline - DynObj.setValueOpt ds (nameof url) url + DynObj.setValueOpt this (nameof about) about + DynObj.setValueOpt this (nameof citation) citation + DynObj.setValueOpt this (nameof comment) comment + DynObj.setValueOpt this (nameof creator) creator + DynObj.setValueOpt this (nameof dateCreated) dateCreated + DynObj.setValueOpt this (nameof dateModified) dateModified + DynObj.setValueOpt this (nameof datePublished) datePublished + DynObj.setValueOpt this (nameof description) description + DynObj.setValueOpt this (nameof hasPart) hasPart + DynObj.setValueOpt this (nameof headline) headline + DynObj.setValueOpt this (nameof url) url - // Properties from Thing - DynObj.setValueOpt ds (nameof description) description - DynObj.setValue ds (nameof identifier) identifier - - ds From 9deffb7ea81f76c067de5618f2b3388303402191 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 28 Aug 2024 16:13:02 +0200 Subject: [PATCH 09/15] Add basic tests for I/S/A ROCrateObjects --- src/ROCrate/playground.fsx | 499 ++---------------- tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj | 1 + tests/ROCrate/Common.fs | 27 + tests/ROCrate/ISAProfile/Assay.Tests.fs | 60 ++- tests/ROCrate/ISAProfile/Dataset.Tests.fs | 24 +- .../ROCrate/ISAProfile/Investigation.Tests.fs | 60 ++- tests/ROCrate/ISAProfile/Study.Tests.fs | 64 ++- ...7c83e7858a974bf913de2e27d8e44191fc73f.json | 193 +++++++ .../TestObjects.ROCrate/Common.fs | 4 - .../TestObjects.ROCrate/LabProcess.fs | 21 - .../TestObjects.ROCrate/Person.fs | 31 -- .../TestObjects.ROCrate/PropertyValue.fs | 27 - .../TestObjects.ROCrate/Sample.fs | 15 - .../TestObjects.ROCrate/ScholarlyArtice.fs | 26 - .../TestingUtils/TestObjects.ROCrate/Study.fs | 31 -- tests/TestingUtils/TestingUtils.fsproj | 8 +- 16 files changed, 431 insertions(+), 660 deletions(-) create mode 100644 tests/ROCrate/Common.fs create mode 100644 tests/TestingUtils/TestObjects.ROCrate/ArcPrototype@70a7c83e7858a974bf913de2e27d8e44191fc73f.json delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/Common.fs delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/Person.fs delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/Sample.fs delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs delete mode 100644 tests/TestingUtils/TestObjects.ROCrate/Study.fs diff --git a/src/ROCrate/playground.fsx b/src/ROCrate/playground.fsx index ac59fea0..4b939a85 100644 --- a/src/ROCrate/playground.fsx +++ b/src/ROCrate/playground.fsx @@ -7,10 +7,11 @@ type IROCrateObject = abstract member Id: string abstract member AdditionalType: string option -type Dataset (id: string, ?additionalType: string) = +type ROCrateObject(id:string, schemaType: string, ?additionalType) = inherit DynamicObj() let mutable _schemaType = "schema.org/Dataset" + let mutable _additionalType = additionalType member this.Id with get() = id @@ -19,7 +20,17 @@ type Dataset (id: string, ?additionalType: string) = with get() = _schemaType and set(value) = _schemaType <- value - member this.AdditionalType = additionalType + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value + + interface IROCrateObject with + member this.SchemaType = schemaType + member this.Id = id + member this.AdditionalType = additionalType + +type Dataset (id: string, ?additionalType: string) = + inherit ROCrateObject(id = id, schemaType = "schema.org/Dataset", ?additionalType = additionalType) //interface implementations interface IROCrateObject with @@ -27,9 +38,10 @@ type Dataset (id: string, ?additionalType: string) = member this.SchemaType with get (): string = this.SchemaType member this.AdditionalType with get (): string option = this.AdditionalType -type InvestigationDataset(id: string) = +/// +type Study(id: string) = // inheritance - inherit Dataset(id, "Investigation") + inherit Dataset(id, "Study") static member create( // mandatory id, @@ -37,6 +49,7 @@ type InvestigationDataset(id: string) = identifier, // optional // Properties from CreativeWork + ?about, ?citation, ?comment, ?creator, @@ -45,14 +58,14 @@ type InvestigationDataset(id: string) = ?datePublished, ?hasPart, ?headline, - ?mentions, ?url, // Properties from Thing ?description ) = - let ds = InvestigationDataset(id = id) + let ds = Study(id = id) // Properties from CreativeWork + DynObj.setValueOpt ds (nameof about) about DynObj.setValueOpt ds (nameof citation) citation DynObj.setValueOpt ds (nameof comment) comment DynObj.setValueOpt ds (nameof creator) creator @@ -61,7 +74,6 @@ type InvestigationDataset(id: string) = DynObj.setValueOpt ds (nameof datePublished) datePublished DynObj.setValueOpt ds (nameof hasPart) hasPart DynObj.setValueOpt ds (nameof headline) headline - DynObj.setValueOpt ds (nameof mentions) mentions DynObj.setValueOpt ds (nameof url) url // Properties from Thing @@ -70,17 +82,13 @@ type InvestigationDataset(id: string) = ds -type StudyDataset(id: string) = - // inheritance - inherit Dataset(id, "Study") - static member create( - // mandatory +module I = + type Investigation( id, // Properties from Thing - identifier, + identifier: obj, // optional // Properties from CreativeWork - ?about, ?citation, ?comment, ?creator, @@ -89,439 +97,36 @@ type StudyDataset(id: string) = ?datePublished, ?hasPart, ?headline, + ?mentions, ?url, // Properties from Thing ?description - ) = - let ds = StudyDataset(id = id) - - // Properties from CreativeWork - DynObj.setValueOpt ds (nameof about) about - DynObj.setValueOpt ds (nameof citation) citation - DynObj.setValueOpt ds (nameof comment) comment - DynObj.setValueOpt ds (nameof creator) creator - DynObj.setValueOpt ds (nameof dateCreated) dateCreated - DynObj.setValueOpt ds (nameof dateModified) dateModified - DynObj.setValueOpt ds (nameof datePublished) datePublished - DynObj.setValueOpt ds (nameof hasPart) hasPart - DynObj.setValueOpt ds (nameof headline) headline - DynObj.setValueOpt ds (nameof url) url - - // Properties from Thing - DynObj.setValueOpt ds (nameof description) description - DynObj.setValue ds (nameof identifier) identifier - - ds - -type AssayDataset(id: string) = - // inheritance - inherit Dataset(id, "Assay") - static member create( - // mandatory - id, - // Properties from Thing - identifier, - // optional - // Properties from CreativeWork - // Properties from Dataset - ?measurementMethod, - ?measurementTechnique, - ?variableMeasured, - // Properties from CreativeWork - ?about, - ?comment, - ?creator, - ?hasPart, - ?url - ) : AssayDataset = - let ds = AssayDataset(id = id) - - // Properties from Dataset - DynObj.setValueOpt ds (nameof measurementMethod) measurementMethod - DynObj.setValueOpt ds (nameof measurementTechnique) measurementTechnique - DynObj.setValueOpt ds (nameof variableMeasured) variableMeasured - - // Properties from CreativeWork - DynObj.setValueOpt ds (nameof about) about - DynObj.setValueOpt ds (nameof comment) comment - DynObj.setValueOpt ds (nameof creator) creator - DynObj.setValueOpt ds (nameof hasPart) hasPart - DynObj.setValueOpt ds (nameof url) url - - // Properties from Thing - DynObj.setValue ds (nameof identifier) identifier - - ds - - static member tryGetMeasurementMethod (ds: AssayDataset) = - match DynObj.tryGetValue ds "measurementMethod" with - | Some value -> Some value - | None -> None - - static member tryGetMeasurementTechnique (ds: AssayDataset) = - match DynObj.tryGetValue ds "measurementTechnique" with - | Some value -> Some value - | None -> None - - static member tryGetVariableMeasured (ds: AssayDataset) = - match DynObj.tryGetValue ds "variableMeasured" with - | Some value -> Some value - | None -> None - - static member tryGetAbout (ds: AssayDataset) = - match DynObj.tryGetValue ds "about" with - | Some value -> Some value - | None -> None - - static member tryGetComment (ds: AssayDataset) = - match DynObj.tryGetValue ds "comment" with - | Some value -> Some value - | None -> None - - static member tryGetCreator (ds: AssayDataset) = - match DynObj.tryGetValue ds "creator" with - | Some value -> Some value - | None -> None - - static member tryGetHasPart (ds: AssayDataset) = - match DynObj.tryGetValue ds "hasPart" with - | Some value -> Some value - | None -> None - - static member tryGetUrl (ds: AssayDataset) = - match DynObj.tryGetValue ds "url" with - | Some value -> Some value - | None -> None - - static member tryGetIdentifier (ds: AssayDataset) = - match DynObj.tryGetValue ds "identifier" with - | Some value -> Some value - | None -> None - -let interfaceOnly: IROCrateObject list = - [ - InvestigationDataset.create(id = "./", identifier = "inv") - StudyDataset.create(id ="./studies/study1", identifier = "study1") - AssayDataset.create(id ="./assays/assay1", identifier = "assay1") - ] - -module ROCrateObject = - - let tryAsDataset (roco: IROCrateObject) = - match roco with - | :? Dataset as ds when ds.SchemaType = "schema.org/Dataset" -> Some ds - | _ -> None - - let tryAsInvestigationDataset (roco: IROCrateObject) = - match roco.AdditionalType, roco.SchemaType with - | Some "Investigation", "schema.org/Dataset" -> - match roco with - | :? InvestigationDataset as ids -> Some ids - | _ -> None - | _ -> - None - - let tryAsStudyDataset (roco: IROCrateObject) = - match roco.AdditionalType, roco.SchemaType with - | Some "Study", "schema.org/Dataset" -> - match roco with - | :? StudyDataset as sds -> Some sds - | _ -> None - | _ -> - None - - let tryAsAssayDataset (roco: IROCrateObject) = - match roco.AdditionalType, roco.SchemaType with - | Some "Assay", "schema.org/Dataset" -> - match roco with - | :? AssayDataset as ads -> Some ads - | _ -> None - | _ -> - None - -type LabProcess(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "bioschemas.org/LabProcess" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - name, - agent, - object, - result, - // optional - ?additionalType, - ?executesLabProtocol, - ?parameterValue, - ?endTime, - ?disambiguatingDescription - ) = - let lp = LabProcess(id) - - DynObj.setValue lp (nameof name) name - DynObj.setValue lp (nameof agent) agent - DynObj.setValue lp (nameof object) object - DynObj.setValue lp (nameof result) result - - DynObj.setValueOpt lp (nameof additionalType) additionalType - DynObj.setValueOpt lp (nameof executesLabProtocol) executesLabProtocol - DynObj.setValueOpt lp (nameof parameterValue) parameterValue - DynObj.setValueOpt lp (nameof endTime) endTime - DynObj.setValueOpt lp (nameof disambiguatingDescription) disambiguatingDescription - - lp - -type LabProtocol(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "bioschemas.org/LabProtocol" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - ?name, - ?intendedUse, - ?description, - ?url, - ?comment, - ?version, - ?labEquipment, - ?reagent, - ?computationalTool - ) = - let lp = LabProcess(id) - - DynObj.setValueOpt lp (nameof name) name - DynObj.setValueOpt lp (nameof intendedUse) intendedUse - DynObj.setValueOpt lp (nameof description) description - DynObj.setValueOpt lp (nameof url) url - DynObj.setValueOpt lp (nameof comment) comment - DynObj.setValueOpt lp (nameof version) version - DynObj.setValueOpt lp (nameof labEquipment) labEquipment - DynObj.setValueOpt lp (nameof reagent) reagent - DynObj.setValueOpt lp (nameof computationalTool) computationalTool - - lp - -type Sample(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "bioschemas.org/Sample" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - name, - ?additionalProperty, - ?derivesFrom - ) = - let s = Sample(id) - - DynObj.setValue s (nameof name) name - - DynObj.setValueOpt s (nameof additionalProperty) additionalProperty - DynObj.setValueOpt s (nameof derivesFrom) derivesFrom - - s - -type Data(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "schema.org/MediaObject" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - name, - ?comment, - ?encodingFormat, - ?disambiguatingDescription - ) = - let d = Data(id) - - DynObj.setValue d (nameof name) name - - DynObj.setValueOpt d (nameof comment) comment - DynObj.setValueOpt d (nameof encodingFormat) encodingFormat - DynObj.setValueOpt d (nameof disambiguatingDescription) disambiguatingDescription - - d - -type PropertyValue(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "schema.org/PropertyValue" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - name, - value, - ?propertyID, - ?unitCode, - ?unitText, - ?valueReference, - ?additionalType - ) = - let pv = PropertyValue(id, ?additionalType = additionalType) - - DynObj.setValue pv (nameof name) name - DynObj.setValue pv (nameof value) value - - DynObj.setValueOpt pv (nameof propertyID) propertyID - DynObj.setValueOpt pv (nameof unitCode) unitCode - DynObj.setValueOpt pv (nameof unitText) unitText - DynObj.setValueOpt pv (nameof valueReference) valueReference - - pv - -type Person(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "schema.org/Person" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - givenName, - ?familyName, - ?email, - ?identifier, - ?affiliation, - ?jobTitle, - ?additionalName, - ?address, - ?telephone, - ?faxNumber, - ?disambiguatingDescription - ) = - let p = Person(id) - - DynObj.setValue p (nameof givenName) givenName - - DynObj.setValueOpt p (nameof familyName) familyName - DynObj.setValueOpt p (nameof email) email - DynObj.setValueOpt p (nameof identifier) identifier - DynObj.setValueOpt p (nameof affiliation) affiliation - DynObj.setValueOpt p (nameof jobTitle) jobTitle - DynObj.setValueOpt p (nameof additionalName) additionalName - DynObj.setValueOpt p (nameof address) address - DynObj.setValueOpt p (nameof telephone) telephone - DynObj.setValueOpt p (nameof faxNumber) faxNumber - DynObj.setValueOpt p (nameof disambiguatingDescription) disambiguatingDescription - - p - - -type ScholarlyArticle(id: string, ?additionalType: string) = - inherit DynamicObj() - - member this.Id - with get() = id - - member this.SchemaType - with get() = "schema.org/ScholarlyArticle" - - member this.AdditionalType = additionalType - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType - - static member create( - // mandatory - id, - headline, - identifier, - ?author, - ?url, - ?creativeWorkStatus, - ?disambiguatingDescription - ) = - let sa = ScholarlyArticle(id) - - DynObj.setValue sa (nameof headline) headline - DynObj.setValue sa (nameof identifier) identifier - - DynObj.setValueOpt sa (nameof author) author - DynObj.setValueOpt sa (nameof url) url - DynObj.setValueOpt sa (nameof creativeWorkStatus) creativeWorkStatus - DynObj.setValueOpt sa (nameof disambiguatingDescription) disambiguatingDescription - - sa \ No newline at end of file + ) as i = + + inherit Dataset(id, "Investigation") + + do + + // Properties from CreativeWork + DynObj.setValueOpt i (nameof citation) citation + DynObj.setValueOpt i (nameof comment) comment + DynObj.setValueOpt i (nameof creator) creator + DynObj.setValueOpt i (nameof dateCreated) dateCreated + DynObj.setValueOpt i (nameof dateModified) dateModified + DynObj.setValueOpt i (nameof datePublished) datePublished + DynObj.setValueOpt i (nameof hasPart) hasPart + DynObj.setValueOpt i (nameof headline) headline + DynObj.setValueOpt i (nameof mentions) mentions + DynObj.setValueOpt i (nameof url) url + + // Properties from Thing + DynObj.setValueOpt i (nameof description) description + DynObj.setValue i (nameof identifier) identifier + +I.Investigation("lol", [1.]) +I.Investigation("lol", "") +I.Investigation("lol", [2]) + +Study.create("lol", [2]) +Study.create("lol", [2.]) +Study.create("lol", "") \ No newline at end of file diff --git a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj index 5f30bba0..c8771272 100644 --- a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj +++ b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj @@ -6,6 +6,7 @@ false + diff --git a/tests/ROCrate/Common.fs b/tests/ROCrate/Common.fs new file mode 100644 index 00000000..f05bc2e3 --- /dev/null +++ b/tests/ROCrate/Common.fs @@ -0,0 +1,27 @@ +module Tests.Common + +open ARCtrl.ROCrate + +open TestingUtils + +module Expect = + + let inline ROCrateObjectHasId (expectedId:string) (roc:#ROCrateObject) = + Expect.equal roc.Id expectedId "object did not contain correct @id" + + let inline ROCrateObjectHasType (expectedType:string) (roc:#ROCrateObject) = + Expect.equal roc.SchemaType expectedType "object did not contain correct @type" + + let inline ROCrateObjectHasAdditionalType (expectedAdditionalType:string) (roc:#ROCrateObject) = + Expect.isSome roc.AdditionalType "additionalType was None" + Expect.equal roc.AdditionalType (Some expectedAdditionalType) "object did not contain correct additionalType" + + let inline ROCrateObjectHasProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = + Expect.isTrue (roc.Properties.ContainsKey expectedPropertyName) $"object did not contain the property 'expectedPropertyName'" + Expect.equal (roc.TryGetTypedValue<'P>(expectedPropertyName)) (Some expectedPropertyValue) "property value of 'expectedPropertyName' was not correct" + + let inline ROCrateObjectHasExpectedInterfaceMembers (expectedType:string) (expectedId:string) (expectedAdditionalType:string option) (roc:#ROCrateObject) = + let interfacerino = roc :> IROCrateObject + Expect.equal interfacerino.SchemaType expectedType "object did not contain correct @type via interface access" + Expect.equal interfacerino.Id expectedId "object did not contain correct @id via interface access" + Expect.equal interfacerino.AdditionalType expectedAdditionalType "object did not contain correct additionalType via interface access" diff --git a/tests/ROCrate/ISAProfile/Assay.Tests.fs b/tests/ROCrate/ISAProfile/Assay.Tests.fs index db030b9c..e534e3f9 100644 --- a/tests/ROCrate/ISAProfile/Assay.Tests.fs +++ b/tests/ROCrate/ISAProfile/Assay.Tests.fs @@ -3,28 +3,58 @@ module Tests.Assay open ARCtrl.ROCrate open TestingUtils - -let default_constructor = Assay("id") - -let tests_profile_object_is_valid = testList "profile object is valid" [ - testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory field Id was not correct" - testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory field SchemaType was not correct" - testCase "AdditionalType" <| fun _ -> Expect.equal default_constructor.AdditionalType (Some "Assay") "optional field AdditionalType was not correct" - testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" - - // default constructors are missing mandatory fields from the profile. This is by design. - testCase "missing identifier" <| fun _ -> Expect.throws (fun _ -> default_constructor.GetValue("identifier") |> ignore) "mandatory profile field identifier was present althoughit was expected to be missing" +open Common + +let mandatory_properties = Assay( + id = "assay_mandatory_properties_id", + identifier = "identifier" +) + +let all_properties = Assay( + id = "assay_all_properties_id", + identifier = "identifier", + about = "about", + comment = "comment", + creator = "creator", + hasPart = "hasPart", + measurementMethod = "measurementMethod", + measurementTechnique = "measurementTechnique", + url = "url", + variableMeasured = "variableMeasured" +) + +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "assay_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Assay" mandatory_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "assay_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Assay" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" all_properties + testCase "about" <| fun _ -> Expect.ROCrateObjectHasProperty "about" "about" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasProperty "comment" "comment" all_properties + testCase "creator" <| fun _ -> Expect.ROCrateObjectHasProperty "creator" "creator" all_properties + testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasProperty "hasPart" "hasPart" all_properties + testCase "measurementMethod" <| fun _ -> Expect.ROCrateObjectHasProperty "measurementMethod" "measurementMethod" all_properties + testCase "measurementTechnique" <| fun _ -> Expect.ROCrateObjectHasProperty "measurementTechnique" "measurementTechnique" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasProperty "url" "url" all_properties + testCase "variableMeasured" <| fun _ -> Expect.ROCrateObjectHasProperty "variableMeasured" "variableMeasured" all_properties + ] ] -let tests_static_methods = testList "static methods" [] - -let tests_interface_members = testList "interface members" [] +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "assay_mandatory_properties_id" (Some "Assay") mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "assay_all_properties_id" (Some "Assay") all_properties +] let tests_dynamic_members = testList "dynamic members" [] let main = testList "Assay" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members ] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Dataset.Tests.fs b/tests/ROCrate/ISAProfile/Dataset.Tests.fs index 310f0e3a..b0292166 100644 --- a/tests/ROCrate/ISAProfile/Dataset.Tests.fs +++ b/tests/ROCrate/ISAProfile/Dataset.Tests.fs @@ -3,17 +3,27 @@ module Tests.Dataset open ARCtrl.ROCrate open TestingUtils +open Common -let default_constructor = Dataset("id") +let mandatory_properties = Dataset("dataset_mandatory_properties_id") +let all_properties = Dataset("dataset_all_properties_id", additionalType = "additionalType") -let tests_profile_object_is_valid = testList "profile object is valid" [ - testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory field Id was not correct" - testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory field SchemaType was not correct" - testCase "AdditionalType" <| fun _ -> Expect.isNone default_constructor.AdditionalType "optional field AdditionalType was not correct" - testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "dataset_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "dataset_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + ] ] -let tests_interface_members = testList "interface members" [] +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "dataset_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "dataset_all_properties_id" (Some "additionalType") all_properties +] let tests_dynamic_members = testList "dynamic members" [] diff --git a/tests/ROCrate/ISAProfile/Investigation.Tests.fs b/tests/ROCrate/ISAProfile/Investigation.Tests.fs index ab58d9ca..5ddc3dfa 100644 --- a/tests/ROCrate/ISAProfile/Investigation.Tests.fs +++ b/tests/ROCrate/ISAProfile/Investigation.Tests.fs @@ -3,28 +3,64 @@ module Tests.Investigation open ARCtrl.ROCrate open TestingUtils +open Common -let default_constructor = Investigation("id") +let mandatory_properties = Investigation( + id = "investigation_mandatory_properties_id", + identifier = "identifier" +) -let tests_profile_object_is_valid = testList "profile object is valid" [ - testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory field Id was not correct" - testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory field SchemaType was not correct" - testCase "AdditionalType" <| fun _ -> Expect.equal default_constructor.AdditionalType (Some "Investigation") "mandatory field AdditionalType was not correct" - testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" +let all_properties = Investigation( + id = "investigation_all_properties_id", + identifier = "identifier", + citation = "citation", + comment = "comment", + creator = "creator", + dateCreated = "dateCreated", + dateModified = "dateModified", + datePublished = "datePublished", + hasPart = "hasPart", + headline = "headline", + mentions = "mentions", + url = "url", + description = "description" +) - // default constructors are missing mandatory fields from the profile. This is by design. - testCase "missing identifier" <| fun _ -> Expect.throws (fun _ -> default_constructor.GetValue("identifier") |> ignore) "mandatory profile field identifier was present althoughit was expected to be missing" +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "investigation_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Investigation" mandatory_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "investigation_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Investigation" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" all_properties + testCase "citation" <| fun _ -> Expect.ROCrateObjectHasProperty "citation" "citation" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasProperty "comment" "comment" all_properties + testCase "creator" <| fun _ -> Expect.ROCrateObjectHasProperty "creator" "creator" all_properties + testCase "dateCreated" <| fun _ -> Expect.ROCrateObjectHasProperty "dateCreated" "dateCreated" all_properties + testCase "dateModified" <| fun _ -> Expect.ROCrateObjectHasProperty "dateModified" "dateModified" all_properties + testCase "datePublished" <| fun _ -> Expect.ROCrateObjectHasProperty "datePublished" "datePublished" all_properties + testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasProperty "hasPart" "hasPart" all_properties + testCase "headline" <| fun _ -> Expect.ROCrateObjectHasProperty "headline" "headline" all_properties + testCase "mentions" <| fun _ -> Expect.ROCrateObjectHasProperty "mentions" "mentions" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasProperty "url" "url" all_properties + testCase "description" <| fun _ -> Expect.ROCrateObjectHasProperty "description" "description" all_properties + ] ] -let tests_static_methods = testList "static methods" [] - -let tests_interface_members = testList "interface members" [] +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "investigation_mandatory_properties_id" (Some "Investigation") mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "investigation_all_properties_id" (Some "Investigation") all_properties +] let tests_dynamic_members = testList "dynamic members" [] let main = testList "Investigation" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members ] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Study.Tests.fs b/tests/ROCrate/ISAProfile/Study.Tests.fs index 00a2f982..20f6a041 100644 --- a/tests/ROCrate/ISAProfile/Study.Tests.fs +++ b/tests/ROCrate/ISAProfile/Study.Tests.fs @@ -3,34 +3,64 @@ module Tests.Study open ARCtrl.ROCrate open TestingUtils +open Common -let default_constructor = Study("id") +let mandatory_properties = Study( + id = "study_mandatory_properties_id", + identifier = "identifier" +) -let mandatory_properties = +let all_properties = Study( + id = "study_all_properties_id", + identifier = "identifier", + about = "about", + citation = "citation", + comment = "comment", + creator = "creator", + dateCreated = "dateCreated", + dateModified = "dateModified", + datePublished = "datePublished", + description = "description", + hasPart = "hasPart", + headline = "headline", + url = "url" +) -let all_properties = () - -let tests_profile_object_is_valid = testList "profile object is valid" [ - testList "default constructor" [ - testCase "Id" <| fun _ -> Expect.equal default_constructor.Id "id" "mandatory properties Id was not correct" - testCase "SchemaType" <| fun _ -> Expect.equal default_constructor.SchemaType "schema.org/Dataset" "mandatory property SchemaType was not correct" - testCase "AdditionalType" <| fun _ -> Expect.equal default_constructor.AdditionalType (Some "Study") "mandatory property AdditionalType was not correct" - testCase "Properties" <| fun _ -> Expect.isEmpty default_constructor.Properties "Dynamic properties were not empty" - - // default constructors are missing mandatory propertys from the profile. This is by design. - testCase "missing identifier" <| fun _ -> Expect.throws (fun _ -> default_constructor.GetValue("identifier") |> ignore) "mandatory profile property identifier was present althoughit was expected to be missing" +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "study_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Study" mandatory_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "study_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Study" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" all_properties + testCase "about" <| fun _ -> Expect.ROCrateObjectHasProperty "about" "about" all_properties + testCase "citation" <| fun _ -> Expect.ROCrateObjectHasProperty "citation" "citation" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasProperty "comment" "comment" all_properties + testCase "creator" <| fun _ -> Expect.ROCrateObjectHasProperty "creator" "creator" all_properties + testCase "dateCreated" <| fun _ -> Expect.ROCrateObjectHasProperty "dateCreated" "dateCreated" all_properties + testCase "dateModified" <| fun _ -> Expect.ROCrateObjectHasProperty "dateModified" "dateModified" all_properties + testCase "datePublished" <| fun _ -> Expect.ROCrateObjectHasProperty "datePublished" "datePublished" all_properties + testCase "description" <| fun _ -> Expect.ROCrateObjectHasProperty "description" "description" all_properties + testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasProperty "hasPart" "hasPart" all_properties + testCase "headline" <| fun _ -> Expect.ROCrateObjectHasProperty "headline" "headline" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasProperty "url" "url" all_properties ] ] -let tests_static_methods = testList "static methods" [] - -let tests_interface_members = testList "interface members" [] +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "study_mandatory_properties_id" (Some "Study") mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "study_all_properties_id" (Some "Study") all_properties +] let tests_dynamic_members = testList "dynamic members" [] let main = testList "Study" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members ] \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/ArcPrototype@70a7c83e7858a974bf913de2e27d8e44191fc73f.json b/tests/TestingUtils/TestObjects.ROCrate/ArcPrototype@70a7c83e7858a974bf913de2e27d8e44191fc73f.json new file mode 100644 index 00000000..380e2f56 --- /dev/null +++ b/tests/TestingUtils/TestObjects.ROCrate/ArcPrototype@70a7c83e7858a974bf913de2e27d8e44191fc73f.json @@ -0,0 +1,193 @@ +{ + "@type": "CreativeWork", + "@id": "ro-crate-metadata.json", + "about": { + "@id": "./", + "@type": "Investigation", + "additionalType": "Investigation", + "identifier": "ArcPrototype", + "filename": "isa.investigation.xlsx", + "title": "ArcPrototype", + "description": "A prototypic ARC that implements all specification standards accordingly", + "people": [ + { + "@id": "timo.muehlhaus@rptu.de", + "@type": "Person", + "orcid": "http://orcid.org/0000-0003-3925-6778", + "firstName": "Timo", + "lastName": "Mühlhaus", + "email": "timo.muehlhaus@rptu.de", + "phone": "0 49 (0)631 205 4657", + "address": "RPTU University of Kaiserslautern, Paul-Ehrlich-Str. 23 , 67663 Kaiserslautern", + "affiliation": { + "@type": "Organization", + "@id": "#Organization_RPTU_University_of_Kaiserslautern", + "name": "RPTU University of Kaiserslautern", + "@context": { + "sdo": "http://schema.org/", + "Organization": "sdo:Organization", + "name": "sdo:name" + } + }, + "roles": [ + { + "@id": "http://purl.org/spar/scoro/principal-investigator", + "@type": "OntologyAnnotation", + "annotationValue": "principal investigator", + "termSource": "scoro", + "termAccession": "http://purl.org/spar/scoro/principal-investigator", + "@context": { + "sdo": "http://schema.org/", + "OntologyAnnotation": "sdo:DefinedTerm", + "annotationValue": "sdo:name", + "termSource": "sdo:inDefinedTermSet", + "termAccession": "sdo:termCode", + "comments": "sdo:disambiguatingDescription" + } + } + ], + "@context": { + "sdo": "http://schema.org/", + "Person": "sdo:Person", + "orcid": "sdo:identifier", + "firstName": "sdo:givenName", + "lastName": "sdo:familyName", + "midInitials": "sdo:additionalName", + "email": "sdo:email", + "address": "sdo:address", + "phone": "sdo:telephone", + "fax": "sdo:faxNumber", + "comments": "sdo:disambiguatingDescription", + "roles": "sdo:jobTitle", + "affiliation": "sdo:affiliation" + } + }, + { + "@id": "garth@rptu.de", + "@type": "Person", + "firstName": "Christoph", + "lastName": "Garth", + "email": "garth@rptu.de", + "affiliation": { + "@type": "Organization", + "@id": "#Organization_RPTU_University_of_Kaiserslautern", + "name": "RPTU University of Kaiserslautern", + "@context": { + "sdo": "http://schema.org/", + "Organization": "sdo:Organization", + "name": "sdo:name" + } + }, + "roles": [ + { + "@id": "http://purl.org/spar/scoro/principal-investigator", + "@type": "OntologyAnnotation", + "annotationValue": "principal investigator", + "termSource": "scoro", + "termAccession": "http://purl.org/spar/scoro/principal-investigator", + "@context": { + "sdo": "http://schema.org/", + "OntologyAnnotation": "sdo:DefinedTerm", + "annotationValue": "sdo:name", + "termSource": "sdo:inDefinedTermSet", + "termAccession": "sdo:termCode", + "comments": "sdo:disambiguatingDescription" + } + } + ], + "@context": { + "sdo": "http://schema.org/", + "Person": "sdo:Person", + "orcid": "sdo:identifier", + "firstName": "sdo:givenName", + "lastName": "sdo:familyName", + "midInitials": "sdo:additionalName", + "email": "sdo:email", + "address": "sdo:address", + "phone": "sdo:telephone", + "fax": "sdo:faxNumber", + "comments": "sdo:disambiguatingDescription", + "roles": "sdo:jobTitle", + "affiliation": "sdo:affiliation" + } + }, + { + "@id": "maus@nfdi4plants.org", + "@type": "Person", + "orcid": "0000-0002-8241-5300", + "firstName": "Oliver", + "lastName": "Maus", + "email": "maus@nfdi4plants.org", + "address": "RPTU University of Kaiserslautern, Erwin-Schrödinger-Str. 56 , 67663 Kaiserslautern", + "affiliation": { + "@type": "Organization", + "@id": "#Organization_RPTU_University_of_Kaiserslautern", + "name": "RPTU University of Kaiserslautern", + "@context": { + "sdo": "http://schema.org/", + "Organization": "sdo:Organization", + "name": "sdo:name" + } + }, + "roles": [ + { + "@id": "http://purl.org/spar/scoro/research-assistant", + "@type": "OntologyAnnotation", + "annotationValue": "research assistant", + "termSource": "scoro", + "termAccession": "http://purl.org/spar/scoro/research-assistant", + "@context": { + "sdo": "http://schema.org/", + "OntologyAnnotation": "sdo:DefinedTerm", + "annotationValue": "sdo:name", + "termSource": "sdo:inDefinedTermSet", + "termAccession": "sdo:termCode", + "comments": "sdo:disambiguatingDescription" + } + } + ], + "@context": { + "sdo": "http://schema.org/", + "Person": "sdo:Person", + "orcid": "sdo:identifier", + "firstName": "sdo:givenName", + "lastName": "sdo:familyName", + "midInitials": "sdo:additionalName", + "email": "sdo:email", + "address": "sdo:address", + "phone": "sdo:telephone", + "fax": "sdo:faxNumber", + "comments": "sdo:disambiguatingDescription", + "roles": "sdo:jobTitle", + "affiliation": "sdo:affiliation" + } + } + ], + "@context": { + "sdo": "http://schema.org/", + "Investigation": "sdo:Dataset", + "identifier": "sdo:identifier", + "title": "sdo:headline", + "additionalType": "sdo:additionalType", + "description": "sdo:description", + "submissionDate": "sdo:dateCreated", + "publicReleaseDate": "sdo:datePublished", + "publications": "sdo:citation", + "people": "sdo:creator", + "studies": "sdo:hasPart", + "ontologySourceReferences": "sdo:mentions", + "comments": "sdo:comment", + "filename": "sdo:alternateName" + } + }, + "conformsTo": { + "@id": "https://w3id.org/ro/crate/1.1" + }, + "@context": { + "sdo": "http://schema.org/", + "arc": "http://purl.org/nfdi4plants/ontology/", + "CreativeWork": "sdo:CreativeWork", + "about": "sdo:about", + "conformsTo": "sdo:conformsTo" + } +} \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Common.fs b/tests/TestingUtils/TestObjects.ROCrate/Common.fs deleted file mode 100644 index 37c88778..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/Common.fs +++ /dev/null @@ -1,4 +0,0 @@ -module TestObjects.ROCrate.Common - -let testDateTime = System.DateTime.Parse("01/01/2024").ToString("s", System.Globalization.CultureInfo.InvariantCulture) -let testDate = System.DateTime.Parse("01/01/2024").ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs b/tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs deleted file mode 100644 index 38c7a751..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/LabProcess.fs +++ /dev/null @@ -1,21 +0,0 @@ -module TestObjects.ROCrate.LabProcess - -open ARCtrl.ROCrate - -let mandatory_properties() = - - let lp = LabProcess("lab_process_id_1") - - lp.SetValue("name","name") - lp.SetValue("agent","name") - lp.SetValue("object", Sample.mandatory_properties()) - lp.SetValue("result","name") - - - lp - -let all_properties() = - - let lp = LabProcess("lab_process_id_2", "additionalType") - - lp \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Person.fs b/tests/TestingUtils/TestObjects.ROCrate/Person.fs deleted file mode 100644 index eb6f2d25..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/Person.fs +++ /dev/null @@ -1,31 +0,0 @@ -module TestObjects.ROCrate.Person - -open ARCtrl.ROCrate -open DynamicObj - -let mandatory_properties() = - - let s = Person("person_id_1") - - s.SetValue("givenName","givenName") - - s - -let all_properties() = - - let s = Person("person_id_2", "additionalType") - - s.SetValue("givenName","givenName") - - s.SetValue("familyName","familyName") - s.SetValue("email","email") - s.SetValue("identifier","identifier") - s.SetValue("affiliation", ROCrateObject("organization_id","schema.org/Organization")) - s.SetValue("jobTitle", ROCrateObject("defined_term_id","schema.org/DefinedTerm")) - s.SetValue("additionalName","additionalName") - s.SetValue("address","address") - s.SetValue("telephone","telephone") - s.SetValue("faxNumber","faxNumber") - s.SetValue("disambiguatingDescription","disambiguatingDescription") - - s \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs b/tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs deleted file mode 100644 index abedb02b..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/PropertyValue.fs +++ /dev/null @@ -1,27 +0,0 @@ -module TestObjects.ROCrate.PropertyValue - -open ARCtrl.ROCrate -open DynamicObj - -let mandatory_properties() = - - let pv = PropertyValue("property_value_id_1") - - pv.SetValue("name","name") - pv.SetValue("value","value") - - pv - -let all_properties() = - - let pv = PropertyValue("property_value_id_2", "additionalType") - - pv.SetValue("name","name") - pv.SetValue("value","value") - - pv.SetValue("propertyID","propertyID") - pv.SetValue("unitCode","unitCode") - pv.SetValue("unitText","unitText") - pv.SetValue("valueReference","valueReference") - - pv \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Sample.fs b/tests/TestingUtils/TestObjects.ROCrate/Sample.fs deleted file mode 100644 index 3345700b..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/Sample.fs +++ /dev/null @@ -1,15 +0,0 @@ -module TestObjects.ROCrate.Sample - -open ARCtrl.ROCrate - -let mandatory_properties() = - - let s = Sample("sample_id_1") - - s - -let all_properties() = - - let s = Sample("sample_id_2", "additionalType") - - s \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs b/tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs deleted file mode 100644 index ca478a0a..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/ScholarlyArtice.fs +++ /dev/null @@ -1,26 +0,0 @@ -module TestObjects.ROCrate.ScholarlyArticle - -open ARCtrl.ROCrate -open DynamicObj - -let mandatory_properties() = - - let s = ScholarlyArticle("scholarly_article_id_1") - - s.SetValue("headline","headline") - s.SetValue("identifier","identifier") - - s - -let all_properties() = - - let s = ScholarlyArticle("scholarly_article_id_2", "additionalType") - - s.SetValue("headline","headline") - s.SetValue("identifier","identifier") - - s.SetValue("author",(TestObjects.ROCrate.Person.all_properties())) - s.SetValue("creativeWorkStatus", ROCrateObject("defined_term_id","schema.org/DefinedTerm")) - s.SetValue("disambiguatingDescription", "disambiguatingDescription") - - s \ No newline at end of file diff --git a/tests/TestingUtils/TestObjects.ROCrate/Study.fs b/tests/TestingUtils/TestObjects.ROCrate/Study.fs deleted file mode 100644 index 9899a6fd..00000000 --- a/tests/TestingUtils/TestObjects.ROCrate/Study.fs +++ /dev/null @@ -1,31 +0,0 @@ -module TestObjects.ROCrate.Study - -open ARCtrl.ROCrate - -let mandatory_properties() = - - let s = Study("study_id_1") - - s.SetValue("identifier", "identifier") - - s - -let all_properties() = - - let s = Study("study_id_2") - - s.SetValue("identifier", "identifier") - - s.SetValue("creator", Person.all_properties()) - s.SetValue("headline", "headline") - s.SetValue("hasPart", ROCrateObject("file_id_1","schema.org/MediaObject")) - s.SetValue("about", LabProcess.all_properties()) - s.SetValue("description", "description") - s.SetValue("dateCreated", Common.testDateTime) - s.SetValue("datePublished", Common.testDate) - s.SetValue("dateModified", Common.testDate) - s.SetValue("citation", ScholarlyArticle.all_properties()) - s.SetValue("comment", "") - s.SetValue("url", "url") - - s \ No newline at end of file diff --git a/tests/TestingUtils/TestingUtils.fsproj b/tests/TestingUtils/TestingUtils.fsproj index b3382527..623113ea 100644 --- a/tests/TestingUtils/TestingUtils.fsproj +++ b/tests/TestingUtils/TestingUtils.fsproj @@ -5,13 +5,7 @@ true - - - - - - - + From 4b4a2fcc3bd32b31ec5aa3b4f1127883f7af83fc Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 28 Aug 2024 16:43:30 +0200 Subject: [PATCH 10/15] temp workaround in tests for https://github.com/CSBiology/DynamicObj/issues/25 --- tests/ROCrate/Common.fs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/ROCrate/Common.fs b/tests/ROCrate/Common.fs index f05bc2e3..3569c4b4 100644 --- a/tests/ROCrate/Common.fs +++ b/tests/ROCrate/Common.fs @@ -17,9 +17,13 @@ module Expect = Expect.equal roc.AdditionalType (Some expectedAdditionalType) "object did not contain correct additionalType" let inline ROCrateObjectHasProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = + #if !FABLE_COMPILER Expect.isTrue (roc.Properties.ContainsKey expectedPropertyName) $"object did not contain the property 'expectedPropertyName'" Expect.equal (roc.TryGetTypedValue<'P>(expectedPropertyName)) (Some expectedPropertyValue) "property value of 'expectedPropertyName' was not correct" - + #endif + #if FABLE_COMPILER + Expect.equal (roc.TryGetValue(expectedPropertyName)) (Some expectedPropertyValue) "property value of 'expectedPropertyName' was not correct" + #endif let inline ROCrateObjectHasExpectedInterfaceMembers (expectedType:string) (expectedId:string) (expectedAdditionalType:string option) (roc:#ROCrateObject) = let interfacerino = roc :> IROCrateObject Expect.equal interfacerino.SchemaType expectedType "object did not contain correct @type via interface access" From f67e78b068350a8e1aecf80fa8b9dd4646fb9ddd Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 2 Sep 2024 13:26:26 +0200 Subject: [PATCH 11/15] Use unblocking version of DynamicObj, introduce runTestProject target --- build.cmd | 1 - build/TestTasks.fs | 29 ++++++++++++++++++- src/ROCrate/ARCtrl.ROCrate.fsproj | 4 +-- tests/ROCrate/Common.fs | 23 ++++++++++----- tests/ROCrate/ISAProfile/Assay.Tests.fs | 20 ++++++------- .../ROCrate/ISAProfile/Investigation.Tests.fs | 26 ++++++++--------- tests/ROCrate/ISAProfile/Study.Tests.fs | 26 ++++++++--------- 7 files changed, 81 insertions(+), 48 deletions(-) diff --git a/build.cmd b/build.cmd index fe247e50..1e9e4ec3 100644 --- a/build.cmd +++ b/build.cmd @@ -2,5 +2,4 @@ set PYTHONIOENCODING=utf-8 dotnet tool restore -cls dotnet run --project ./build/build.fsproj %* \ No newline at end of file diff --git a/build/TestTasks.fs b/build/TestTasks.fs index 19114997..dfcbfd2a 100644 --- a/build/TestTasks.fs +++ b/build/TestTasks.fs @@ -1,4 +1,4 @@ -module TestTasks +module TestTasks open BlackFox.Fake open Fake.DotNet @@ -59,6 +59,33 @@ module RunTests = |> Seq.iter dotnetRun } + let runTestProject = BuildTask.createFn "runTestProject" [clean; build] (fun config -> + let dotnetRun = run dotnet "run" + match config.Context.Arguments with + | projectName::[] -> + let dotnetRun = run dotnet "run" + match List.tryFind (fun (p:string) -> p.EndsWith(projectName)) testProjects with + | Some p -> + // + printfn $"running tests for test project {p}" + dotnetRun p + // + run dotnet $"fable {p} -o {p}/js" "" + //transpile py files from fsharp code + run dotnet $"fable {p} -o {p}/py --lang python" "" + // run pyxpecto in target path to execute tests in python + run python $"{p}/py/main.py" "" + // transpile js files from fsharp code + run dotnet $"fable {p} -o {p}/js" "" + // run mocha in target path to execute tests + // "--timeout 20000" is used, because json schema validation takes a bit of time. + run node $"{p}/js/Main.js" "" + | _ -> + failwithf "Project %s not found" projectName + | _ -> failwith "Please provide a project name to run tests for as the single argument" + ) + + let runTests = BuildTask.create "RunTests" [clean; build; RunTests.runTestsJs; RunTests.runTestsJsNative; RunTests.runTestsPy; RunTests.runTestsPyNative; RunTests.runTestsDotnet] { () } \ No newline at end of file diff --git a/src/ROCrate/ARCtrl.ROCrate.fsproj b/src/ROCrate/ARCtrl.ROCrate.fsproj index 570746a1..b16f34a1 100644 --- a/src/ROCrate/ARCtrl.ROCrate.fsproj +++ b/src/ROCrate/ARCtrl.ROCrate.fsproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -21,7 +21,7 @@ - + Kevin Schneider, nfdi4plants, DataPLANT OSS contributors diff --git a/tests/ROCrate/Common.fs b/tests/ROCrate/Common.fs index 3569c4b4..dd544885 100644 --- a/tests/ROCrate/Common.fs +++ b/tests/ROCrate/Common.fs @@ -1,6 +1,7 @@ module Tests.Common open ARCtrl.ROCrate +open DynamicObj open TestingUtils @@ -16,14 +17,20 @@ module Expect = Expect.isSome roc.AdditionalType "additionalType was None" Expect.equal roc.AdditionalType (Some expectedAdditionalType) "object did not contain correct additionalType" - let inline ROCrateObjectHasProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = - #if !FABLE_COMPILER - Expect.isTrue (roc.Properties.ContainsKey expectedPropertyName) $"object did not contain the property 'expectedPropertyName'" - Expect.equal (roc.TryGetTypedValue<'P>(expectedPropertyName)) (Some expectedPropertyValue) "property value of 'expectedPropertyName' was not correct" - #endif - #if FABLE_COMPILER - Expect.equal (roc.TryGetValue(expectedPropertyName)) (Some expectedPropertyValue) "property value of 'expectedPropertyName' was not correct" - #endif + let inline ROCrateObjectHasDynamicProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = + Expect.isSome (roc.TryGetDynamicPropertyInfo(expectedPropertyName)) $"object did not contain the dynamic property 'expectedPropertyName'" + Expect.equal + (DynObj.tryGetTypedValue<'P> expectedPropertyName roc) + (Some expectedPropertyValue) + "property value of 'expectedPropertyName' was not correct" + + let inline ROCrateObjectHasStaticProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = + Expect.isSome (roc.TryGetStaticPropertyInfo(expectedPropertyName)) $"object did not contain the dynamic property 'expectedPropertyName'" + Expect.equal + (DynObj.tryGetTypedValue<'P> expectedPropertyName roc) + (Some expectedPropertyValue) + "property value of 'expectedPropertyName' was not correct" + let inline ROCrateObjectHasExpectedInterfaceMembers (expectedType:string) (expectedId:string) (expectedAdditionalType:string option) (roc:#ROCrateObject) = let interfacerino = roc :> IROCrateObject Expect.equal interfacerino.SchemaType expectedType "object did not contain correct @type via interface access" diff --git a/tests/ROCrate/ISAProfile/Assay.Tests.fs b/tests/ROCrate/ISAProfile/Assay.Tests.fs index e534e3f9..9232494d 100644 --- a/tests/ROCrate/ISAProfile/Assay.Tests.fs +++ b/tests/ROCrate/ISAProfile/Assay.Tests.fs @@ -28,21 +28,21 @@ let tests_profile_object_is_valid = testList "constructed properties" [ testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "assay_mandatory_properties_id" mandatory_properties testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Assay" mandatory_properties - testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" mandatory_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" mandatory_properties ] testList "all properties" [ testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "assay_all_properties_id" all_properties testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Assay" all_properties - testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" all_properties - testCase "about" <| fun _ -> Expect.ROCrateObjectHasProperty "about" "about" all_properties - testCase "comment" <| fun _ -> Expect.ROCrateObjectHasProperty "comment" "comment" all_properties - testCase "creator" <| fun _ -> Expect.ROCrateObjectHasProperty "creator" "creator" all_properties - testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasProperty "hasPart" "hasPart" all_properties - testCase "measurementMethod" <| fun _ -> Expect.ROCrateObjectHasProperty "measurementMethod" "measurementMethod" all_properties - testCase "measurementTechnique" <| fun _ -> Expect.ROCrateObjectHasProperty "measurementTechnique" "measurementTechnique" all_properties - testCase "url" <| fun _ -> Expect.ROCrateObjectHasProperty "url" "url" all_properties - testCase "variableMeasured" <| fun _ -> Expect.ROCrateObjectHasProperty "variableMeasured" "variableMeasured" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" all_properties + testCase "about" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "about" "about" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "comment" "comment" all_properties + testCase "creator" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "creator" "creator" all_properties + testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "hasPart" "hasPart" all_properties + testCase "measurementMethod" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "measurementMethod" "measurementMethod" all_properties + testCase "measurementTechnique" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "measurementTechnique" "measurementTechnique" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "url" "url" all_properties + testCase "variableMeasured" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "variableMeasured" "variableMeasured" all_properties ] ] diff --git a/tests/ROCrate/ISAProfile/Investigation.Tests.fs b/tests/ROCrate/ISAProfile/Investigation.Tests.fs index 5ddc3dfa..77695263 100644 --- a/tests/ROCrate/ISAProfile/Investigation.Tests.fs +++ b/tests/ROCrate/ISAProfile/Investigation.Tests.fs @@ -31,24 +31,24 @@ let tests_profile_object_is_valid = testList "constructed properties" [ testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "investigation_mandatory_properties_id" mandatory_properties testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Investigation" mandatory_properties - testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" mandatory_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" mandatory_properties ] testList "all properties" [ testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "investigation_all_properties_id" all_properties testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Investigation" all_properties - testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" all_properties - testCase "citation" <| fun _ -> Expect.ROCrateObjectHasProperty "citation" "citation" all_properties - testCase "comment" <| fun _ -> Expect.ROCrateObjectHasProperty "comment" "comment" all_properties - testCase "creator" <| fun _ -> Expect.ROCrateObjectHasProperty "creator" "creator" all_properties - testCase "dateCreated" <| fun _ -> Expect.ROCrateObjectHasProperty "dateCreated" "dateCreated" all_properties - testCase "dateModified" <| fun _ -> Expect.ROCrateObjectHasProperty "dateModified" "dateModified" all_properties - testCase "datePublished" <| fun _ -> Expect.ROCrateObjectHasProperty "datePublished" "datePublished" all_properties - testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasProperty "hasPart" "hasPart" all_properties - testCase "headline" <| fun _ -> Expect.ROCrateObjectHasProperty "headline" "headline" all_properties - testCase "mentions" <| fun _ -> Expect.ROCrateObjectHasProperty "mentions" "mentions" all_properties - testCase "url" <| fun _ -> Expect.ROCrateObjectHasProperty "url" "url" all_properties - testCase "description" <| fun _ -> Expect.ROCrateObjectHasProperty "description" "description" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" all_properties + testCase "citation" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "citation" "citation" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "comment" "comment" all_properties + testCase "creator" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "creator" "creator" all_properties + testCase "dateCreated" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "dateCreated" "dateCreated" all_properties + testCase "dateModified" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "dateModified" "dateModified" all_properties + testCase "datePublished" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "datePublished" "datePublished" all_properties + testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "hasPart" "hasPart" all_properties + testCase "headline" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "headline" "headline" all_properties + testCase "mentions" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "mentions" "mentions" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "url" "url" all_properties + testCase "description" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "description" "description" all_properties ] ] diff --git a/tests/ROCrate/ISAProfile/Study.Tests.fs b/tests/ROCrate/ISAProfile/Study.Tests.fs index 20f6a041..43bb46f3 100644 --- a/tests/ROCrate/ISAProfile/Study.Tests.fs +++ b/tests/ROCrate/ISAProfile/Study.Tests.fs @@ -31,24 +31,24 @@ let tests_profile_object_is_valid = testList "constructed properties" [ testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "study_mandatory_properties_id" mandatory_properties testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" mandatory_properties testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Study" mandatory_properties - testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" mandatory_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" mandatory_properties ] testList "all properties" [ testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "study_all_properties_id" all_properties testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Dataset" all_properties testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "Study" all_properties - testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasProperty "identifier" "identifier" all_properties - testCase "about" <| fun _ -> Expect.ROCrateObjectHasProperty "about" "about" all_properties - testCase "citation" <| fun _ -> Expect.ROCrateObjectHasProperty "citation" "citation" all_properties - testCase "comment" <| fun _ -> Expect.ROCrateObjectHasProperty "comment" "comment" all_properties - testCase "creator" <| fun _ -> Expect.ROCrateObjectHasProperty "creator" "creator" all_properties - testCase "dateCreated" <| fun _ -> Expect.ROCrateObjectHasProperty "dateCreated" "dateCreated" all_properties - testCase "dateModified" <| fun _ -> Expect.ROCrateObjectHasProperty "dateModified" "dateModified" all_properties - testCase "datePublished" <| fun _ -> Expect.ROCrateObjectHasProperty "datePublished" "datePublished" all_properties - testCase "description" <| fun _ -> Expect.ROCrateObjectHasProperty "description" "description" all_properties - testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasProperty "hasPart" "hasPart" all_properties - testCase "headline" <| fun _ -> Expect.ROCrateObjectHasProperty "headline" "headline" all_properties - testCase "url" <| fun _ -> Expect.ROCrateObjectHasProperty "url" "url" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" all_properties + testCase "about" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "about" "about" all_properties + testCase "citation" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "citation" "citation" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "comment" "comment" all_properties + testCase "creator" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "creator" "creator" all_properties + testCase "dateCreated" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "dateCreated" "dateCreated" all_properties + testCase "dateModified" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "dateModified" "dateModified" all_properties + testCase "datePublished" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "datePublished" "datePublished" all_properties + testCase "description" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "description" "description" all_properties + testCase "hasPart" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "hasPart" "hasPart" all_properties + testCase "headline" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "headline" "headline" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "url" "url" all_properties ] ] From 9d526b82df1d7ac04283cbe23c9832f1d5818771 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 2 Sep 2024 13:53:05 +0200 Subject: [PATCH 12/15] add LabProcess tests, fix schematype of ROCrateObject base constructor --- src/ROCrate/ROCrateObject.fs | 2 +- tests/ROCrate/ISAProfile/LabProcess.tests.fs | 53 ++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/ROCrate/ROCrateObject.fs b/src/ROCrate/ROCrateObject.fs index 5f9c57de..a27bb8c7 100644 --- a/src/ROCrate/ROCrateObject.fs +++ b/src/ROCrate/ROCrateObject.fs @@ -13,7 +13,7 @@ type IROCrateObject = type ROCrateObject(id:string, schemaType: string, ?additionalType) = inherit DynamicObj() - let mutable _schemaType = "schema.org/Dataset" + let mutable _schemaType = schemaType let mutable _additionalType = additionalType member this.Id diff --git a/tests/ROCrate/ISAProfile/LabProcess.tests.fs b/tests/ROCrate/ISAProfile/LabProcess.tests.fs index 5053165b..68d03bc2 100644 --- a/tests/ROCrate/ISAProfile/LabProcess.tests.fs +++ b/tests/ROCrate/ISAProfile/LabProcess.tests.fs @@ -3,18 +3,63 @@ module Tests.LabProcess open ARCtrl.ROCrate open TestingUtils +open Common -let tests_profile_object_is_valid = testList "profile object is valid" [] +let mandatory_properties = LabProcess( + id = "labprocess_mandatory_properties_id", + name = "name", + agent = "agent", + object = "object", + result = "result" +) -let tests_static_methods = testList "static methods" [] +let all_properties = LabProcess( + id = "labprocess_all_properties_id", + name = "name", + agent = "agent", + object = "object", + result = "result", + additionalType = "additionalType", + executesLabProtocol = "executesLabProtocol", + parameterValue = "parameterValue", + endTime = "endTime", + disambiguatingDescription = "disambiguatingDescription" +) -let tests_interface_members = testList "interface members" [] +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "labprocess_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "bioschemas.org/LabProcess" mandatory_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" mandatory_properties + testCase "agent" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "agent" "agent" mandatory_properties + testCase "object" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "object" "object" mandatory_properties + testCase "result" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "result" "result" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "labprocess_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "bioschemas.org/LabProcess" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + testCase "agent" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "agent" "agent" all_properties + testCase "object" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "object" "object" all_properties + testCase "result" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "result" "result" all_properties + testCase "executesLabProtocol" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "executesLabProtocol" "executesLabProtocol" all_properties + testCase "parameterValue" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "parameterValue" "parameterValue" all_properties + testCase "endTime" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "endTime" "endTime" all_properties + testCase "disambiguatingDescription" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "disambiguatingDescription" "disambiguatingDescription" all_properties + + ] +] + +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/LabProcess" "labprocess_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/LabProcess" "labprocess_all_properties_id" (Some "additionalType") all_properties +] let tests_dynamic_members = testList "dynamic members" [] let main = testList "LabProcess" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members ] \ No newline at end of file From 4e91e9dcc5b34747a2e4a16f33aee1a227eb08ef Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 3 Sep 2024 10:28:56 +0200 Subject: [PATCH 13/15] finish basic property tests for isa profile types --- tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj | 1 + tests/ROCrate/ISAProfile/Assay.Tests.fs | 13 +++- tests/ROCrate/ISAProfile/Data.Tests.fs | 58 +++++++++++++--- tests/ROCrate/ISAProfile/Dataset.Tests.fs | 13 +++- .../ROCrate/ISAProfile/Investigation.Tests.fs | 13 +++- tests/ROCrate/ISAProfile/LabProcess.tests.fs | 13 +++- tests/ROCrate/ISAProfile/LabProtocol.Tests.fs | 59 ++++++++++++++-- tests/ROCrate/ISAProfile/Person.Tests.fs | 67 +++++++++++++++++-- .../ROCrate/ISAProfile/PropertyValue.Tests.fs | 60 +++++++++++++++-- tests/ROCrate/ISAProfile/Sample.tests.fs | 51 ++++++++++++-- .../ISAProfile/ScholarlyArticle.Tests.fs | 59 ++++++++++++++-- tests/ROCrate/ISAProfile/Study.Tests.fs | 13 +++- tests/ROCrate/Main.fs | 1 + tests/ROCrate/ROCrateObject.Tests.fs | 45 +++++++++++++ 14 files changed, 422 insertions(+), 44 deletions(-) create mode 100644 tests/ROCrate/ROCrateObject.Tests.fs diff --git a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj index c8771272..7d2bcc81 100644 --- a/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj +++ b/tests/ROCrate/ARCtrl.ROCrate.Tests.fsproj @@ -7,6 +7,7 @@ + diff --git a/tests/ROCrate/ISAProfile/Assay.Tests.fs b/tests/ROCrate/ISAProfile/Assay.Tests.fs index 9232494d..d32fafd8 100644 --- a/tests/ROCrate/ISAProfile/Assay.Tests.fs +++ b/tests/ROCrate/ISAProfile/Assay.Tests.fs @@ -1,6 +1,7 @@ module Tests.Assay open ARCtrl.ROCrate +open DynamicObj open TestingUtils open Common @@ -51,7 +52,17 @@ let tests_interface_members = testList "interface members" [ testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "assay_all_properties_id" (Some "Assay") all_properties ] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Assay" [ tests_profile_object_is_valid diff --git a/tests/ROCrate/ISAProfile/Data.Tests.fs b/tests/ROCrate/ISAProfile/Data.Tests.fs index 67935a70..79d12cdb 100644 --- a/tests/ROCrate/ISAProfile/Data.Tests.fs +++ b/tests/ROCrate/ISAProfile/Data.Tests.fs @@ -1,21 +1,61 @@ module Tests.Data open ARCtrl.ROCrate +open DynamicObj open TestingUtils +open Common + +let mandatory_properties = Data( + id = "data_mandatory_properties_id", + name = "name" +) + +let all_properties = Data( + id = "data_all_properties_id", + name = "name", + additionalType = "additionalType", + comment = "comment", + encodingFormat = "encodingFormat", + disambiguatingDescription = "disambiguatingDescription" +) + +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "data_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/MediaObject" mandatory_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "data_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/MediaObject" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "comment" "comment" all_properties + testCase "encodingFormat" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "encodingFormat" "encodingFormat" all_properties + testCase "disambiguatingDescription" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "disambiguatingDescription" "disambiguatingDescription" all_properties + ] +] -let tests_profile_object_is_valid = testList "profile object is valid" [] - -let tests_static_methods = testList "static methods" [] - -let tests_interface_members = testList "interface members" [] +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/MediaObject" "data_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/MediaObject" "data_all_properties_id" (Some "additionalType") all_properties +] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Data" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members -] - +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Dataset.Tests.fs b/tests/ROCrate/ISAProfile/Dataset.Tests.fs index b0292166..a6619d0a 100644 --- a/tests/ROCrate/ISAProfile/Dataset.Tests.fs +++ b/tests/ROCrate/ISAProfile/Dataset.Tests.fs @@ -1,6 +1,7 @@ module Tests.Dataset open ARCtrl.ROCrate +open DynamicObj open TestingUtils open Common @@ -25,7 +26,17 @@ let tests_interface_members = testList "interface members" [ testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "dataset_all_properties_id" (Some "additionalType") all_properties ] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Dataset" [ tests_profile_object_is_valid diff --git a/tests/ROCrate/ISAProfile/Investigation.Tests.fs b/tests/ROCrate/ISAProfile/Investigation.Tests.fs index 77695263..1e0d15de 100644 --- a/tests/ROCrate/ISAProfile/Investigation.Tests.fs +++ b/tests/ROCrate/ISAProfile/Investigation.Tests.fs @@ -1,6 +1,7 @@ module Tests.Investigation open ARCtrl.ROCrate +open DynamicObj open TestingUtils open Common @@ -57,7 +58,17 @@ let tests_interface_members = testList "interface members" [ testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "investigation_all_properties_id" (Some "Investigation") all_properties ] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Investigation" [ tests_profile_object_is_valid diff --git a/tests/ROCrate/ISAProfile/LabProcess.tests.fs b/tests/ROCrate/ISAProfile/LabProcess.tests.fs index 68d03bc2..a713a077 100644 --- a/tests/ROCrate/ISAProfile/LabProcess.tests.fs +++ b/tests/ROCrate/ISAProfile/LabProcess.tests.fs @@ -1,6 +1,7 @@ module Tests.LabProcess open ARCtrl.ROCrate +open DynamicObj open TestingUtils open Common @@ -56,7 +57,17 @@ let tests_interface_members = testList "interface members" [ testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/LabProcess" "labprocess_all_properties_id" (Some "additionalType") all_properties ] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "LabProcess" [ tests_profile_object_is_valid diff --git a/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs b/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs index af6106a3..3e88ea43 100644 --- a/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs +++ b/tests/ROCrate/ISAProfile/LabProtocol.Tests.fs @@ -1,20 +1,69 @@ module Tests.LabProtocol open ARCtrl.ROCrate +open DynamicObj open TestingUtils +open Common -let tests_profile_object_is_valid = testList "profile object is valid" [] +let mandatory_properties = LabProtocol( + id = "labprotocol_mandatory_properties_id" +) -let tests_static_methods = testList "static methods" [] +let all_properties = LabProtocol( + id = "labprotocol_all_properties_id", + additionalType = "additionalType", + name = "name", + intendedUse = "intendedUse", + description = "description", + url = "url", + comment = "comment", + version = "version", + labEquipment = "labEquipment", + reagent = "reagent", + computationalTool = "computationalTool" +) -let tests_interface_members = testList "interface members" [] +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "labprotocol_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "bioschemas.org/LabProtocol" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "labprotocol_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "bioschemas.org/LabProtocol" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + testCase "intendedUse" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "intendedUse" "intendedUse" all_properties + testCase "description" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "description" "description" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "url" "url" all_properties + testCase "comment" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "comment" "comment" all_properties + testCase "version" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "version" "version" all_properties + testCase "labEquipment" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "labEquipment" "labEquipment" all_properties + testCase "reagent" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "reagent" "reagent" all_properties + testCase "computationalTool" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "computationalTool" "computationalTool" all_properties + ] +] -let tests_dynamic_members = testList "dynamic members" [] +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/LabProtocol" "labprotocol_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/LabProtocol" "labprotocol_all_properties_id" (Some "additionalType") all_properties +] + +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "LabProtocol" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members ] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Person.Tests.fs b/tests/ROCrate/ISAProfile/Person.Tests.fs index 7d0bce7e..cf72916c 100644 --- a/tests/ROCrate/ISAProfile/Person.Tests.fs +++ b/tests/ROCrate/ISAProfile/Person.Tests.fs @@ -1,20 +1,75 @@ module Tests.Person open ARCtrl.ROCrate +open DynamicObj open TestingUtils +open Common -let tests_profile_object_is_valid = testList "profile object is valid" [] +let mandatory_properties = Person( + id = "person_mandatory_properties_id", + givenName = "givenName" +) -let tests_static_methods = testList "static methods" [] +let all_properties = Person( + id = "person_all_properties_id", + givenName = "givenName", + additionalType = "additionalType", + familyName = "familyName", + email = "email", + identifier = "identifier", + affiliation = "affiliation", + jobTitle = "jobTitle", + additionalName = "additionalName", + address = "address", + telephone = "telephone", + faxNumber = "faxNumber", + disambiguatingDescription = "disambiguatingDescription" +) -let tests_interface_members = testList "interface members" [] +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "person_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Person" mandatory_properties + testCase "givenName" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "givenName" "givenName" all_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "person_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/Person" mandatory_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "givenName" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "givenName" "givenName" all_properties + testCase "familyName" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "familyName" "familyName" all_properties + testCase "email" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "email" "email" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" all_properties + testCase "affiliation" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "affiliation" "affiliation" all_properties + testCase "jobTitle" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "jobTitle" "jobTitle" all_properties + testCase "additionalName" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "additionalName" "additionalName" all_properties + testCase "address" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "address" "address" all_properties + testCase "telephone" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "telephone" "telephone" all_properties + testCase "faxNumber" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "faxNumber" "faxNumber" all_properties + testCase "disambiguatingDescription" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "disambiguatingDescription" "disambiguatingDescription" all_properties + ] +] + +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Person" "person_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Person" "person_all_properties_id" (Some "additionalType") all_properties +] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Person" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members -] +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs b/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs index 00db974b..6ca0eebe 100644 --- a/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs +++ b/tests/ROCrate/ISAProfile/PropertyValue.Tests.fs @@ -1,21 +1,67 @@ module Tests.PropertyValue open ARCtrl.ROCrate +open DynamicObj open TestingUtils +open Common -let tests_profile_object_is_valid = testList "profile object is valid" [] +let mandatory_properties = PropertyValue( + id = "propertyvalue_mandatory_properties_id", + name = "name", + value = "value" +) -let tests_static_methods = testList "static methods" [] +let all_properties = PropertyValue( + id = "propertyvalue_all_properties_id", + name = "name", + value = "value", + propertyID = "propertyID", + unitCode = "unitCode", + unitText = "unitText", + valueReference = "valueReference", + additionalType = "additionalType" +) -let tests_interface_members = testList "interface members" [] +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "propertyvalue_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/PropertyValue" mandatory_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + testCase "value" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "value" "value" all_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "propertyvalue_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/PropertyValue" mandatory_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + testCase "value" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "value" "value" all_properties + testCase "propertyID" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "propertyID" "propertyID" all_properties + testCase "unitCode" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "unitCode" "unitCode" all_properties + testCase "unitText" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "unitText" "unitText" all_properties + testCase "valueReference" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "valueReference" "valueReference" all_properties + ] +] + +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/PropertyValue" "propertyvalue_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/PropertyValue" "propertyvalue_all_properties_id" (Some "additionalType") all_properties +] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "PropertyValue" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members -] - +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Sample.tests.fs b/tests/ROCrate/ISAProfile/Sample.tests.fs index be83c15b..bcc5b025 100644 --- a/tests/ROCrate/ISAProfile/Sample.tests.fs +++ b/tests/ROCrate/ISAProfile/Sample.tests.fs @@ -1,20 +1,59 @@ module Tests.Sample open ARCtrl.ROCrate +open DynamicObj open TestingUtils +open Common -let tests_profile_object_is_valid = testList "profile object is valid" [] +let mandatory_properties = Sample( + id = "sample_mandatory_properties_id", + name = "name" +) -let tests_static_methods = testList "static methods" [] +let all_properties = Sample( + id = "sample_all_properties_id", + name = "name", + additionalType = "additionalType", + additionalProperty = "additionalProperty", + derivesFrom = "derivesFrom" +) -let tests_interface_members = testList "interface members" [] +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "sample_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "bioschemas.org/Sample" mandatory_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "sample_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "bioschemas.org/Sample" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "name" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "name" "name" all_properties + testCase "additionalProperty" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "additionalProperty" "additionalProperty" all_properties + testCase "derivesFrom" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "derivesFrom" "derivesFrom" all_properties + ] +] + +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/Sample" "sample_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "bioschemas.org/Sample" "sample_all_properties_id" (Some "additionalType") all_properties +] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Sample" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members -] +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs b/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs index 014cdd00..ba498f3d 100644 --- a/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs +++ b/tests/ROCrate/ISAProfile/ScholarlyArticle.Tests.fs @@ -1,20 +1,67 @@ module Tests.ScholarlyArticle open ARCtrl.ROCrate +open DynamicObj open TestingUtils +open Common -let tests_profile_object_is_valid = testList "profile object is valid" [] +let mandatory_properties = ScholarlyArticle( + id = "scholarlyarticle_mandatory_properties_id", + headline = "headline", + identifier = "identifier" +) -let tests_static_methods = testList "static methods" [] +let all_properties = ScholarlyArticle( + id = "scholarlyarticle_all_properties_id", + headline = "headline", + identifier = "identifier", + additionalType = "additionalType", + author = "author", + url = "url", + creativeWorkStatus = "creativeWorkStatus", + disambiguatingDescription = "disambiguatingDescription" +) -let tests_interface_members = testList "interface members" [] +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "scholarlyarticle_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/ScholarlyArticle" mandatory_properties + testCase "headline" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "headline" "headline" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" all_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "scholarlyarticle_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "schema.org/ScholarlyArticle" mandatory_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + testCase "headline" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "headline" "headline" all_properties + testCase "identifier" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "identifier" "identifier" all_properties + testCase "author" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "author" "author" all_properties + testCase "url" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "url" "url" all_properties + testCase "creativeWorkStatus" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "creativeWorkStatus" "creativeWorkStatus" all_properties + testCase "disambiguatingDescription" <| fun _ -> Expect.ROCrateObjectHasDynamicProperty "disambiguatingDescription" "disambiguatingDescription" all_properties + ] +] + +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/ScholarlyArticle" "scholarlyarticle_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/ScholarlyArticle" "scholarlyarticle_all_properties_id" (Some "additionalType") all_properties +] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "ScholarlyArticle" [ tests_profile_object_is_valid - tests_static_methods tests_interface_members tests_dynamic_members -] +] \ No newline at end of file diff --git a/tests/ROCrate/ISAProfile/Study.Tests.fs b/tests/ROCrate/ISAProfile/Study.Tests.fs index 43bb46f3..05151e08 100644 --- a/tests/ROCrate/ISAProfile/Study.Tests.fs +++ b/tests/ROCrate/ISAProfile/Study.Tests.fs @@ -1,6 +1,7 @@ module Tests.Study open ARCtrl.ROCrate +open DynamicObj open TestingUtils open Common @@ -57,7 +58,17 @@ let tests_interface_members = testList "interface members" [ testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "schema.org/Dataset" "study_all_properties_id" (Some "Study") all_properties ] -let tests_dynamic_members = testList "dynamic members" [] +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) let main = testList "Study" [ tests_profile_object_is_valid diff --git a/tests/ROCrate/Main.fs b/tests/ROCrate/Main.fs index 7cc29817..ef0393c2 100644 --- a/tests/ROCrate/Main.fs +++ b/tests/ROCrate/Main.fs @@ -3,6 +3,7 @@ module ROCrate.Tests open Fable.Pyxpecto let all = testSequenced <| testList "ROCrate" [ + Tests.ROCrateObject.main Tests.Dataset.main Tests.Investigation.main Tests.Study.main diff --git a/tests/ROCrate/ROCrateObject.Tests.fs b/tests/ROCrate/ROCrateObject.Tests.fs new file mode 100644 index 00000000..6d2b0e5f --- /dev/null +++ b/tests/ROCrate/ROCrateObject.Tests.fs @@ -0,0 +1,45 @@ +module Tests.ROCrateObject + +open ARCtrl.ROCrate +open DynamicObj + +open TestingUtils +open Common + +let mandatory_properties = ROCrateObject("rocrateobject_mandatory_properties_id", "someType") +let all_properties = ROCrateObject("rocrateobject_all_properties_id", "someType", additionalType = "additionalType") + +let tests_profile_object_is_valid = testList "constructed properties" [ + testList "mandatory properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "rocrateobject_mandatory_properties_id" mandatory_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "someType" mandatory_properties + ] + testList "all properties" [ + testCase "Id" <| fun _ -> Expect.ROCrateObjectHasId "rocrateobject_all_properties_id" all_properties + testCase "SchemaType" <| fun _ -> Expect.ROCrateObjectHasType "someType" all_properties + testCase "AdditionalType" <| fun _ -> Expect.ROCrateObjectHasAdditionalType "additionalType" all_properties + ] +] + +let tests_interface_members = testList "interface members" [ + testCase "mandatoryProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "someType" "rocrateobject_mandatory_properties_id" None mandatory_properties + testCase "allProperties" <| fun _ -> Expect.ROCrateObjectHasExpectedInterfaceMembers "someType" "rocrateobject_all_properties_id" (Some "additionalType") all_properties +] + +let tests_dynamic_members = testSequenced ( + testList "dynamic members" [ + testCase "property not present before setting" <| fun _ -> Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be set" + testCase "Set dynamic property" <| fun _ -> + mandatory_properties.SetValue("yes",42) + Expect.ROCrateObjectHasDynamicProperty "yes" 42 mandatory_properties + testCase "Remove dynamic property" <| fun _ -> + mandatory_properties.Remove("yes") + Expect.isNone (DynObj.tryGetTypedValue "yes" mandatory_properties) "dynamic property 'yes' was set although it was expected not to be removed" + ] +) + +let main = testList "ROCrateObject" [ + tests_profile_object_is_valid + tests_interface_members + tests_dynamic_members +] \ No newline at end of file From 192812d43569270845883ca116de9931dea6ba62 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 3 Sep 2024 10:31:22 +0200 Subject: [PATCH 14/15] fix error messages of ROCrate testing utils --- tests/ROCrate/Common.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ROCrate/Common.fs b/tests/ROCrate/Common.fs index dd544885..862477e1 100644 --- a/tests/ROCrate/Common.fs +++ b/tests/ROCrate/Common.fs @@ -18,18 +18,18 @@ module Expect = Expect.equal roc.AdditionalType (Some expectedAdditionalType) "object did not contain correct additionalType" let inline ROCrateObjectHasDynamicProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = - Expect.isSome (roc.TryGetDynamicPropertyInfo(expectedPropertyName)) $"object did not contain the dynamic property 'expectedPropertyName'" + Expect.isSome (roc.TryGetDynamicPropertyInfo(expectedPropertyName)) $"object did not contain the dynamic property '{expectedPropertyName}'" Expect.equal (DynObj.tryGetTypedValue<'P> expectedPropertyName roc) (Some expectedPropertyValue) - "property value of 'expectedPropertyName' was not correct" + $"property value of '{expectedPropertyName}' was not correct" let inline ROCrateObjectHasStaticProperty (expectedPropertyName:string) (expectedPropertyValue:'P) (roc:#ROCrateObject) = - Expect.isSome (roc.TryGetStaticPropertyInfo(expectedPropertyName)) $"object did not contain the dynamic property 'expectedPropertyName'" + Expect.isSome (roc.TryGetStaticPropertyInfo(expectedPropertyName)) $"object did not contain the dynamic property '{expectedPropertyName}'" Expect.equal (DynObj.tryGetTypedValue<'P> expectedPropertyName roc) (Some expectedPropertyValue) - "property value of 'expectedPropertyName' was not correct" + $"property value of '{expectedPropertyName}' was not correct" let inline ROCrateObjectHasExpectedInterfaceMembers (expectedType:string) (expectedId:string) (expectedAdditionalType:string option) (roc:#ROCrateObject) = let interfacerino = roc :> IROCrateObject From c71b8a301fbdf95531a9ba0d33f8e6d0d238adc9 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 5 Sep 2024 08:19:23 +0200 Subject: [PATCH 15/15] correct interface implementation on ROCrateObject, remove interface implementation from Dataset --- src/ROCrate/ISAProfile/Dataset.fs | 6 ------ src/ROCrate/ISAProfile/Investigation.fs | 10 ++-------- src/ROCrate/ROCrateObject.fs | 15 +++++++++++---- tests/TestingUtils/TestingUtils.fsproj | 2 +- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/ROCrate/ISAProfile/Dataset.fs b/src/ROCrate/ISAProfile/Dataset.fs index fd85b239..8fb712ca 100644 --- a/src/ROCrate/ISAProfile/Dataset.fs +++ b/src/ROCrate/ISAProfile/Dataset.fs @@ -7,9 +7,3 @@ open Fable.Core [] type Dataset (id: string, ?additionalType: string) = inherit ROCrateObject(id = id, schemaType = "schema.org/Dataset", ?additionalType = additionalType) - - //interface implementations - interface IROCrateObject with - member this.Id with get () = this.Id - member this.SchemaType with get (): string = this.SchemaType - member this.AdditionalType with get (): string option = this.AdditionalType \ No newline at end of file diff --git a/src/ROCrate/ISAProfile/Investigation.fs b/src/ROCrate/ISAProfile/Investigation.fs index 31213679..2498807c 100644 --- a/src/ROCrate/ISAProfile/Investigation.fs +++ b/src/ROCrate/ISAProfile/Investigation.fs @@ -7,10 +7,7 @@ open Fable.Core [] type Investigation( id, - // Properties from Thing identifier, - // optional - // Properties from CreativeWork ?citation, ?comment, ?creator, @@ -21,12 +18,12 @@ type Investigation( ?headline, ?mentions, ?url, - // Properties from Thing ?description ) as this = inherit Dataset(id, "Investigation") do - // Properties from CreativeWork + DynObj.setValue this (nameof identifier) identifier + DynObj.setValueOpt this (nameof citation) citation DynObj.setValueOpt this (nameof comment) comment DynObj.setValueOpt this (nameof creator) creator @@ -37,7 +34,4 @@ type Investigation( DynObj.setValueOpt this (nameof headline) headline DynObj.setValueOpt this (nameof mentions) mentions DynObj.setValueOpt this (nameof url) url - - // Properties from Thing DynObj.setValueOpt this (nameof description) description - DynObj.setValue this (nameof identifier) identifier diff --git a/src/ROCrate/ROCrateObject.fs b/src/ROCrate/ROCrateObject.fs index a27bb8c7..30b30108 100644 --- a/src/ROCrate/ROCrateObject.fs +++ b/src/ROCrate/ROCrateObject.fs @@ -4,9 +4,9 @@ open DynamicObj /// Base interface implemented by all explicitly known objects in our ROCrate profiles. type IROCrateObject = - abstract member SchemaType : string + abstract member SchemaType : string with get, set abstract member Id: string - abstract member AdditionalType: string option + abstract member AdditionalType: string option with get, set /// Base class for all explicitly known objects in our ROCrate profiles to inherit from. /// Basically a DynamicObj that implements the IROPCrateObject interface. @@ -28,6 +28,13 @@ type ROCrateObject(id:string, schemaType: string, ?additionalType) = and set(value) = _additionalType <- value interface IROCrateObject with - member this.SchemaType = schemaType + + member this.SchemaType + with get() = _schemaType + and set(value) = _schemaType <- value + member this.Id = id - member this.AdditionalType = additionalType \ No newline at end of file + + member this.AdditionalType + with get() = _additionalType + and set(value) = _additionalType <- value \ No newline at end of file diff --git a/tests/TestingUtils/TestingUtils.fsproj b/tests/TestingUtils/TestingUtils.fsproj index 623113ea..955e0f06 100644 --- a/tests/TestingUtils/TestingUtils.fsproj +++ b/tests/TestingUtils/TestingUtils.fsproj @@ -5,7 +5,7 @@ true - +