diff --git a/Medidata.RWS.NET/Core/Requests/Datasets/VersionDatasetRequest.cs b/Medidata.RWS.NET/Core/Requests/Datasets/VersionDatasetRequest.cs new file mode 100644 index 0000000..7a9098b --- /dev/null +++ b/Medidata.RWS.NET/Core/Requests/Datasets/VersionDatasetRequest.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Medidata.RWS.Core.Requests; + +namespace Medidata.RWS.Core.Requests.Datasets +{ + public class VersionDatasetRequest : OdmDatasetBase + { + public VersionDatasetRequest( + + string project_name, + string environment_name, + string version_oid, + string dataset_type = "regular", + string formOid = default(string), + string versionitem = default(string), + string rawsuffix = default(string), + string codelistsuffix = default(string), + string decodesuffix = default(string), + string stdsuffix = default(string), + string start = default(string)) : base(dataset_type, versionitem, rawsuffix, codelistsuffix, decodesuffix, stdsuffix, start) + { + + ProjectName = project_name; + EnvironmentName = environment_name; + VersionOid = version_oid; + FormOid = formOid; + Verify(); + } + + public string VersionOid { get; set; } + + public string FormOid { get; set; } + + public string EnvironmentName { get; set; } + + public string ProjectName { get; set; } + + /// + /// Get the Study and Environment names in a format RWS expects. + /// If no environment name is provided, it is left out of the return string. + /// + /// + private string StudyNameAndEnvironment() + { + return string.IsNullOrWhiteSpace(EnvironmentName) ? $"{ProjectName}" : $"{ProjectName}({EnvironmentName})"; + } + + + /// + /// The URL path of the resource being requested. + /// + /// + public override string UrlPath() + { + + var queryParams = new List { "studies", StudyNameAndEnvironment(), "versions", VersionOid, "datasets", dataset_type }; + + if (!string.IsNullOrEmpty(FormOid)) queryParams.Add(FormOid); + + return RequestHelpers.MakeUrl("/", QueryString(), queryParams.ToArray()); + + } + } +} diff --git a/Medidata.RWS.NET/Medidata.RWS.NET.csproj b/Medidata.RWS.NET/Medidata.RWS.NET.csproj index b23cb5d..303db7e 100644 --- a/Medidata.RWS.NET/Medidata.RWS.NET.csproj +++ b/Medidata.RWS.NET/Medidata.RWS.NET.csproj @@ -64,6 +64,7 @@ + diff --git a/Medidata.RWS.NET/docs/core_resources.rst b/Medidata.RWS.NET/docs/core_resources.rst index a9c4da2..c82a7d4 100644 --- a/Medidata.RWS.NET/docs/core_resources.rst +++ b/Medidata.RWS.NET/docs/core_resources.rst @@ -113,7 +113,8 @@ or, to filter the data by form: .. code-block:: c# - using Medidata.RWS.Core.Requests.Implementations; + using Medidata.RWS.Core.Requests + using Medidata.RWS.Core.Requests.Datasets; //Create a connection var connection = new RwsConnection("innovate", "username", "password"); // authentication required @@ -122,7 +123,7 @@ or, to filter the data by form: var response = connection.SendRequest(new StudyDatasetRequest("Mediflex", "Prod", dataset_type: "regular")) as RWSResponse; //Write the XML response to the console (see XML below) - Console.Write(response.xmlString); + Console.Write(response.RawXMLString()); .. code-block:: xml @@ -184,16 +185,17 @@ or, to filter the data by form: .. code-block:: c# - using Medidata.RWS.Core.Requests.Implementations; + using Medidata.RWS.Core.Requests + using Medidata.RWS.Core.Requests.Datasets; - //Create a connection - var connection = new RwsConnection("innovate", "username", "password"); // authentication required + //Create a connection + var connection = new RwsConnection("innovate", "username", "password"); // authentication required - //Send the request / get a response - var response = connection.SendRequest(new SubjectDatasetRequest("Mediflex", "Prod", subject_key: "1", dataset_type: "regular")) as RWSResponse; + //Send the request / get a response + var response = connection.SendRequest(new SubjectDatasetRequest("Mediflex", "Prod", subject_key: "1", dataset_type: "regular")) as RWSResponse; - //Write the XML response to the console (see XML below) - Console.Write(response.xmlString); + //Write the XML response to the console (see XML below) + Console.Write(response.RawXMLString()); .. code-block:: xml @@ -256,4 +258,62 @@ This is the equivalent of calling: or, to filter the data by form: ``https://{subdomain}.mdsol.com/studies/{project}({environment})/versions/{ version_id }/datasets/{ regular|raw }/{ formoid }?{options}`` -*TBA* \ No newline at end of file + +.. code-block:: c# + + using Medidata.RWS.Core.Requests + using Medidata.RWS.Core.Requests.Datasets; + + //Create a connection + var connection = new RwsConnection("innovate", "username", "password"); // authentication required + + //Send the request / get a response + var response = connection.SendRequest(new VersionDatasetRequest(project_name: "Mediflex", environment_name: "Dev", version_oid: "999")) as RWSResponse; + + //Write the XML response to the console (see XML below) + Console.Write(response.RawXMLString()); + +*Note the **MetaDataVersionOID** value in the XML response.* + +.. code-block:: xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + \ No newline at end of file diff --git a/Medidata.RWS.Tests/Core/Requests/Datasets/VersionDatasetRequestTests.cs b/Medidata.RWS.Tests/Core/Requests/Datasets/VersionDatasetRequestTests.cs new file mode 100644 index 0000000..3bb2664 --- /dev/null +++ b/Medidata.RWS.Tests/Core/Requests/Datasets/VersionDatasetRequestTests.cs @@ -0,0 +1,66 @@ +using System; +using Medidata.RWS.Core.Requests.Datasets; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Medidata.RWS.Tests.Core.Requests.Datasets +{ + [TestClass] + public class VersionDatasetRequestTests + { + [TestMethod] + public void VersionDatasetRequest_default_version_path_is_correct() + { + var request = new VersionDatasetRequest(project_name: "Mediflex", environment_name: "Dev", version_oid: "001"); + + Assert.AreEqual("Mediflex", request.ProjectName); + + Assert.AreEqual("Dev", request.EnvironmentName); + + Assert.AreEqual("001", request.VersionOid); + + Assert.AreEqual("studies/Mediflex(Dev)/versions/001/datasets/regular", request.UrlPath()); + + } + + [TestMethod] + public void VersionDatasetRequest_raw_version_path_is_correct() + { + var request = new VersionDatasetRequest(project_name: "Mediflex", environment_name: "Dev", version_oid: "001", dataset_type:"raw"); + + Assert.AreEqual("Mediflex", request.ProjectName); + + Assert.AreEqual("Dev", request.EnvironmentName); + + Assert.AreEqual("001", request.VersionOid); + + Assert.AreEqual("studies/Mediflex(Dev)/versions/001/datasets/raw", request.UrlPath()); + + } + + [TestMethod] + public void VersionDatasetRequest_raw_version_path_with_form_is_correct() + { + var request = new VersionDatasetRequest(project_name: "Mediflex", environment_name: "Dev", version_oid: "001", dataset_type: "raw", formOid: "DM"); + + Assert.AreEqual("Mediflex", request.ProjectName); + + Assert.AreEqual("Dev", request.EnvironmentName); + + Assert.AreEqual("001", request.VersionOid); + + Assert.AreEqual("studies/Mediflex(Dev)/versions/001/datasets/raw/DM", request.UrlPath()); + + } + + [TestMethod] + [ExpectedException(typeof(NotSupportedException))] + public void VersionDatasetRequest_throws_with_improper_parameters() + { + + var req = new VersionDatasetRequest("TESTPROJECT", "DEV", "1001", dataset_type: "newfie"); + + } + + + } +} diff --git a/Medidata.RWS.Tests/Medidata.RWS.Tests.csproj b/Medidata.RWS.Tests/Medidata.RWS.Tests.csproj index 9fbe148..ef0a5ad 100644 --- a/Medidata.RWS.Tests/Medidata.RWS.Tests.csproj +++ b/Medidata.RWS.Tests/Medidata.RWS.Tests.csproj @@ -73,6 +73,7 @@ + @@ -102,9 +103,6 @@ - - Always - diff --git a/Medidata.RWS.Tests/Read_Before_Running_Tests.txt b/Medidata.RWS.Tests/Read_Before_Running_Tests.txt index c357dc8..9d937a1 100644 --- a/Medidata.RWS.Tests/Read_Before_Running_Tests.txt +++ b/Medidata.RWS.Tests/Read_Before_Running_Tests.txt @@ -1,12 +1,12 @@ -In order for tests to run successfully, the Medidata.RWS assembly must not be installed in the GAC. +In order for tests to run successfully, the Medidata.RWS.NET assembly must not be installed in the GAC. To remove it from the GAC: -gacutil /uf Medidata.RWS +gacutil /uf Medidata.RWS.NET After test suite is run, it can be added back: -gacutil /if Medidata.RWS.dll +gacutil /if Medidata.RWS.NET.dll ## .env file Ensure you have a .env file in your test project root.