Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ValidicCSharp/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ public string ExecuteWebCommand(string command, HttpMethod method, object payloa
try
{
if (method == HttpMethod.GET)
{
json = client.DownloadString(address);
if (method == HttpMethod.POST && payload != null)
}
else if (method == HttpMethod.POST && payload != null)
{
json = client.UploadString(address, JsonConvert.SerializeObject(payload));
}
else if (method == HttpMethod.DELETE)
{
json = client.UploadString(address, HttpMethod.DELETE.ToString(), string.Empty);
}
}
catch (WebException ex)
{
Expand Down
4 changes: 1 addition & 3 deletions ValidicCSharp/Model/AddUserResponse.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace ValidicCSharp.Model
{
public class AddUserResponse
public class AddUserResponse : BaseResponse
{
public int code { get; set; }
public string message { get; set; }
public User user { get; set; }
}
}
10 changes: 10 additions & 0 deletions ValidicCSharp/Model/BaseResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ValidicCSharp.Model
{
using System.Net;

public class BaseResponse
{
public int code { get; set; }
public string message { get; set; }
}
}
8 changes: 7 additions & 1 deletion ValidicCSharp/Request/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ public static Command GetLatest(this Command command)
return command;
}

public static string GetStringAndStripRandom(this Command command)
public static Command DeleteUser(this Command command, string userId)
{
command.Method = HttpMethod.DELETE;
return command.FromUser(userId);
}

public static string GetStringAndStripRandom(this Command command)
{
var text = command.ToString();
var split = text.Split('?');
Expand Down
1 change: 1 addition & 0 deletions ValidicCSharp/ValidicCSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="Model\AddUserResponse.cs" />
<Compile Include="Model\AddUserRequest.cs" />
<Compile Include="Model\Application.cs" />
<Compile Include="Model\BaseResponse.cs" />
<Compile Include="Model\Credentials.cs" />
<Compile Include="Model\Measurement.cs" />
<Compile Include="Model\OrganizationAuthenticationCredentials.cs" />
Expand Down
12 changes: 11 additions & 1 deletion ValidicCSharpTests/CustomerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ public AddUserResponse AddUser(string uid, Profile profile = null)
var response = json.Objectify<AddUserResponse>();
return response;
}
}


public BaseResponse DeleteUser(string validicId)
{
var client = new Client() { AccessToken = Credentials.AccessToken };
var command = new Command().DeleteUser(validicId).FromOrganization(Credentials.OrganizationId);
var json = client.PerformCommand(command);
var response = json.Objectify<BaseResponse>();
return response;
}
}
}
20 changes: 19 additions & 1 deletion ValidicCSharpTests/ModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ModelTests : BaseTests
{
public static CustomerModel Acme = new CustomerModel
{
Credentials = new OrganizationAuthenticationCredentials{ OrganizationId = "51aca5a06dedda916400002b", AccessToken = "ENTERPRISE_KEY"},
Credentials = new OrganizationAuthenticationCredentials { OrganizationId = "51aca5a06dedda916400002b", AccessToken = "ENTERPRISE_KEY" },
Organization = new Organization{Name = "ACME Corp"},
Profile = new Profile { Uid = "52ffcb4bf1f70eefba000004", Gender = GenderType.M}
};
Expand Down Expand Up @@ -72,6 +72,7 @@ public void CanAddUser()
Assert.IsTrue(response.user._id != null);
Assert.IsTrue(response.code == (int)StatusCode.Created);
}

[Test]
public void AddUserWithSameId()
{
Expand All @@ -94,6 +95,23 @@ public void CanAddUserWithProfile()
Assert.IsTrue(response.user.profile.Gender == GenderType.M);
}

[Test]
public void CanAddAndDeleteUser()
{
var response = Customer.AddUser(MakeRandom().ToString());
Assert.IsTrue(response.user._id != null);
Assert.AreEqual((int)StatusCode.Created, response.code);
var deleteResponse = Customer.DeleteUser(response.user._id);
Assert.AreEqual((int)StatusCode.Ok, (int)deleteResponse.code);
}

[Test]
public void DeleteNonExistantUser()
{
var deleteResponse = Customer.DeleteUser(MakeRandom().ToString());
Assert.AreEqual((int)StatusCode.NotFound, (int)deleteResponse.code);
}


[Test]
public void DiabetesModelPopulatesCorrectly()
Expand Down