-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from tranpl/net-core-1.x
implemented apis
- Loading branch information
Showing
11 changed files
with
759 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Redcap.Models | ||
{ | ||
public class Record | ||
{ | ||
public KeyValuePair<string, string> Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using Newtonsoft.Json; | ||
using Redcap; | ||
using Redcap.Models; | ||
using NUnit.Framework; | ||
|
||
namespace RedcapApiTests | ||
{ | ||
[TestFixture] | ||
public class ApiMethodTests | ||
{ | ||
private string _apiKey = "3D57A7FA57C8A43F6C8803A84BB3957B"; | ||
private string _apiEndpoint = "http://localhost/redcap/api/"; | ||
[TestCase] | ||
public void CanExportAsync_SingleRecord_ShouldContain_1() | ||
{ | ||
// Arrange | ||
var apiKey = _apiKey; | ||
var apiEndpoint = _apiEndpoint; | ||
|
||
// Act | ||
var redcap_api = new RedcapApi(apiKey, apiEndpoint); | ||
var result = redcap_api.GetRecordAsync("1", InputFormat.json, RedcapDataType.flat, ReturnFormat.json, null, null, null, null).Result; | ||
var data = JsonConvert.DeserializeObject(result).ToString(); | ||
|
||
// Assert | ||
StringAssert.Contains("1", data); | ||
} | ||
[TestCase] | ||
public void CanExportAsync_AllEvents_ShouldContain_event_name() | ||
{ | ||
// Arrange | ||
var apiKey = _apiKey; | ||
var apiEndpoint = _apiEndpoint; | ||
|
||
// Act | ||
var redcap_api = new RedcapApi(apiKey, apiEndpoint); | ||
var result = redcap_api.ExportEventsAsync(InputFormat.json, ReturnFormat.json).Result; | ||
var data = JsonConvert.DeserializeObject(result).ToString(); | ||
|
||
// Assert | ||
StringAssert.Contains("event_name", data); | ||
|
||
} | ||
[TestCase] | ||
public void CanGetRecordsAsync_AllRecords_ShouldContain_record_id() | ||
{ | ||
// Arrange | ||
var apiKey = _apiKey; | ||
var apiEndpoint = _apiEndpoint; | ||
|
||
// Act | ||
var redcap_api = new RedcapApi(apiKey, apiEndpoint); | ||
var result = redcap_api.GetRecordsAsync(InputFormat.json, ReturnFormat.json, RedcapDataType.flat).Result; | ||
var data = JsonConvert.DeserializeObject(result).ToString(); | ||
|
||
// Assert | ||
StringAssert.Contains("record_id", data); | ||
|
||
} | ||
[TestCase] | ||
public void CanGetRedcapVersion_VersionNumber_Shouldontain_Number() | ||
{ | ||
// Arrange | ||
// Assume current redcap version is 7.4.9 | ||
var currentRedcapVersion = "7.4.9"; | ||
var apiKey = _apiKey; | ||
var apiEndpoint = _apiEndpoint; | ||
|
||
// Act | ||
var redcap_api = new RedcapApi(apiKey, apiEndpoint); | ||
var result = redcap_api.GetRedcapVersionAsync(InputFormat.json, RedcapDataType.flat).Result; | ||
var data = result; | ||
|
||
// Assert | ||
Assert.AreEqual(currentRedcapVersion, data); | ||
|
||
} | ||
[TestCase] | ||
public void CanSaveRecord_SingleRecord_ShouldReturn_Ids() | ||
{ | ||
// Arrange | ||
var apiKey = _apiKey; | ||
var apiEndpoint = _apiEndpoint; | ||
|
||
var record = new | ||
{ | ||
record_id = "1", | ||
redcap_event_name = "event_1_arm_1", | ||
first_name = "John", | ||
last_name = "Doe" | ||
}; | ||
// Act | ||
var redcap_api = new RedcapApi(apiKey, apiEndpoint); | ||
var result = redcap_api.SaveRecordsAsync(record, ReturnContent.ids, OverwriteBehavior.overwrite, InputFormat.json, RedcapDataType.flat, ReturnFormat.json).Result; | ||
var data = JsonConvert.DeserializeObject(result).ToString(); | ||
|
||
// Assert | ||
StringAssert.Contains("1", data); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0-beta3" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="1.2.0-beta3" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | ||
<PackageReference Include="NUnit" Version="3.8.1" /> | ||
<PackageReference Include="NUnit.Runners" Version="3.7.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" /> | ||
<PackageReference Include="Serilog" Version="2.5.1-dev-00873" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Redcap"> | ||
<HintPath>..\RedcapApi\bin\Release\netcoreapp1.1\Redcap.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |