Skip to content

Commit

Permalink
Merge pull request #23 from tranpl/net-core-1.x
Browse files Browse the repository at this point in the history
implemented apis
  • Loading branch information
cctrbic authored Sep 13, 2017
2 parents cc38b51 + 2a5535e commit 35659f0
Show file tree
Hide file tree
Showing 11 changed files with 759 additions and 245 deletions.
8 changes: 7 additions & 1 deletion RedcapApi.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.10
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Redcap", "RedcapApi\Redcap.csproj", "{E34E88C8-D30F-4924-8108-8E84D14C2E9A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedcapApiDemo", "RedcapApiDemo\RedcapApiDemo.csproj", "{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedcapApiTests", "RedcapApiTests\RedcapApiTests.csproj", "{F7B44B5F-7559-4507-AC25-2B2D08C1E078}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}.Release|Any CPU.Build.0 = Release|Any CPU
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
733 changes: 536 additions & 197 deletions RedcapApi/Api/Redcap.cs

Large diffs are not rendered by default.

75 changes: 38 additions & 37 deletions RedcapApi/Interfaces/IRedcap.cs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions RedcapApi/Models/Record.cs
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; }
}
}
2 changes: 1 addition & 1 deletion RedcapApi/Models/RedcapDataType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Redcap.Models
{
/// <summary>
/// The format which is provided when requesting a import through Redcap API
/// The data format which the Redcap API endpoint should receive.
/// RedcapDataType, 0 = flat
/// RedcapDataType, 1 = eav
/// RedcapDataType, 2 = nonlogitudinal
Expand Down
2 changes: 1 addition & 1 deletion RedcapApi/Models/RedcapFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// RedcapFormat, 1 = CSV
/// RedcapFormat, 2 = XML
/// </summary>
public enum RedcapFormat
public enum InputFormat
{
json = 0,
csv = 1,
Expand Down
6 changes: 3 additions & 3 deletions RedcapApi/Redcap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<Description>This library allows external applications to connect to REDCap remotely and is used to programmatically retrieve or modify data or settings within REDCap, e.g Import/Export records into Redcap</Description>
<Product>Redcap Api Library</Product>
<PackageId>RedcapAPI</PackageId>
<Version>0.2.6-alpha-release</Version>
<AssemblyVersion>0.2.6.0</AssemblyVersion>
<Version>0.2.8-alpha</Version>
<AssemblyVersion>0.2.8.0</AssemblyVersion>
<PackageTags>redcap</PackageTags>
<PackageReleaseNotes>alpha release</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ApplicationIcon />
<OutputType>WinExe</OutputType>
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>

Expand Down
36 changes: 32 additions & 4 deletions RedcapApiDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Redcap;
using Redcap.Models;
Expand All @@ -14,9 +13,38 @@ static void Main(string[] args)

var redcap_api = new RedcapApi("3D57A7FA57C8A43F6C8803A84BB3957B", "http://localhost/redcap/api/");

var result = redcap_api.GetRecordAsync("1",RedcapFormat.json, RedcapDataType.flat, ReturnFormat.json, null, null, null, null).Result;
var data = JsonConvert.DeserializeObject(result);
Console.WriteLine(data);
Console.WriteLine("Calling GetRecordAsync() . . .");
var GetRecordAsync = redcap_api.GetRecordAsync("1", InputFormat.json, RedcapDataType.flat, ReturnFormat.json, null, null, null, null).Result;
var GetRecordAsyncData = JsonConvert.DeserializeObject(GetRecordAsync);
Console.WriteLine($"GetRecordAsync Result: {GetRecordAsyncData}");

Console.WriteLine("Calling ExportEventsAsync() . . .");
var exportEvents = redcap_api.ExportEventsAsync(InputFormat.json, ReturnFormat.json).Result;
var exportEventsAsync = JsonConvert.DeserializeObject(exportEvents);
Console.WriteLine($"ExportEventsAsync Result: {exportEventsAsync}");

Console.WriteLine("Calling GetRecordsAsync() . . .");
var GetRecordsAsync = redcap_api.GetRecordsAsync(InputFormat.json, ReturnFormat.json, RedcapDataType.flat).Result;
var GetRecordsAsyncData = JsonConvert.DeserializeObject(GetRecordsAsync);
Console.WriteLine($"GetRecordsAsync Result: {GetRecordsAsyncData}");

Console.WriteLine("Calling GetRedcapVersionAsync() . . .");
var GetRedcapVersionAsync = redcap_api.GetRedcapVersionAsync(InputFormat.json, RedcapDataType.flat).Result;
Console.WriteLine($"GetRedcapVersionAsync Result: {GetRedcapVersionAsync}");


var saveRecordsAsyncObject = new {
record_id = "1",
redcap_event_name = "event_1_arm_1",
first_name = "John",
last_name = "Doe"
};

Console.WriteLine("Calling SaveRecordsAsync() . . .");
var SaveRecordsAsync = redcap_api.SaveRecordsAsync(saveRecordsAsyncObject, ReturnContent.ids,OverwriteBehavior.overwrite, InputFormat.json, RedcapDataType.flat, ReturnFormat.json).Result;
var SaveRecordsAsyncData = JsonConvert.DeserializeObject(SaveRecordsAsync);
Console.WriteLine($"SaveRecordsAsync Result: {SaveRecordsAsyncData}");

Console.ReadLine();

}
Expand Down
2 changes: 1 addition & 1 deletion RedcapApiDemo/RedcapApiDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<Reference Include="Redcap">
<HintPath>..\RedcapApi\bin\Debug\netcoreapp1.1\Redcap.dll</HintPath>
<HintPath>..\RedcapApi\bin\Release\netcoreapp1.1\Redcap.dll</HintPath>
</Reference>
</ItemGroup>

Expand Down
103 changes: 103 additions & 0 deletions RedcapApiTests/ApiMethodTests.cs
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);

}

}
}
26 changes: 26 additions & 0 deletions RedcapApiTests/RedcapApiTests.csproj
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>

0 comments on commit 35659f0

Please sign in to comment.