|
|
|
|
@@ -8,51 +8,47 @@ namespace raven_integration
|
|
|
|
|
|
|
|
|
|
public class UserCrud
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test all CRUD routes for a User
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async void CRUD()
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
{
|
|
|
|
|
"id": 0,
|
|
|
|
|
"name": "string",
|
|
|
|
|
"dollarAmount": 0,
|
|
|
|
|
"active": true,
|
|
|
|
|
"roles": 0
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//CREATE
|
|
|
|
|
dynamic w1 = new JObject();
|
|
|
|
|
w1.name = Util.Uniquify("First Test User");
|
|
|
|
|
w1.dollarAmount = 1.11m;
|
|
|
|
|
w1.active = true;
|
|
|
|
|
w1.roles = 0;
|
|
|
|
|
dynamic d1 = new JObject();
|
|
|
|
|
d1.name = Util.Uniquify("First Test User");
|
|
|
|
|
d1.ownerId = 1L;
|
|
|
|
|
d1.active=true;
|
|
|
|
|
d1.login=Util.Uniquify("LOGIN");
|
|
|
|
|
d1.password=Util.Uniquify("PASSWORD");
|
|
|
|
|
d1.roles=0;//norole
|
|
|
|
|
d1.localeId=1;//random locale
|
|
|
|
|
d1.userType=3;//non scheduleable
|
|
|
|
|
|
|
|
|
|
ApiResponse r1 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), w1.ToString());
|
|
|
|
|
ApiResponse r1 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d1.ToString());
|
|
|
|
|
Util.ValidateDataReturnResponseOk(r1);
|
|
|
|
|
long w1Id = r1.ObjectResponse["result"]["id"].Value<long>();
|
|
|
|
|
long d1Id = r1.ObjectResponse["result"]["id"].Value<long>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dynamic w2 = new JObject();
|
|
|
|
|
w2.name = Util.Uniquify("Second Test User");
|
|
|
|
|
w2.dollarAmount = 2.22m;
|
|
|
|
|
w2.active = true;
|
|
|
|
|
w2.roles = 0;
|
|
|
|
|
dynamic d2 = new JObject();
|
|
|
|
|
d2.name = Util.Uniquify("Second Test User");
|
|
|
|
|
d2.dollarAmount = 2.22m;
|
|
|
|
|
d2.active = true;
|
|
|
|
|
d2.roles = 0;
|
|
|
|
|
|
|
|
|
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d2.ToString());
|
|
|
|
|
Util.ValidateDataReturnResponseOk(r2);
|
|
|
|
|
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
|
|
|
|
long d2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//RETRIEVE
|
|
|
|
|
|
|
|
|
|
//Get one
|
|
|
|
|
ApiResponse r3 = await Util.GetAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
ApiResponse r3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateDataReturnResponseOk(r3);
|
|
|
|
|
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
|
|
|
|
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(d2.name.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -60,36 +56,36 @@ namespace raven_integration
|
|
|
|
|
//PUT
|
|
|
|
|
|
|
|
|
|
//update w2id
|
|
|
|
|
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
|
|
|
|
w2.OwnerId = 1;
|
|
|
|
|
w2.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
|
|
|
|
ApiResponse PUTTestResponse = await Util.PutAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
d2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
|
|
|
|
d2.OwnerId = 1;
|
|
|
|
|
d2.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
|
|
|
|
ApiResponse PUTTestResponse = await Util.PutAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), d2.ToString());
|
|
|
|
|
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
|
|
|
|
|
|
|
|
|
//check PUT worked
|
|
|
|
|
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
|
|
|
|
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
|
|
|
|
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(d2.name.ToString());
|
|
|
|
|
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
|
|
|
|
|
|
|
|
|
//PATCH
|
|
|
|
|
var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST User");
|
|
|
|
|
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
|
|
|
|
ApiResponse PATCHTestResponse = await Util.PatchAsync("User/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
|
|
|
|
ApiResponse PATCHTestResponse = await Util.PatchAsync("User/" + d2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
|
|
|
|
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
|
|
|
|
|
|
|
|
|
//check PATCH worked
|
|
|
|
|
ApiResponse checkPATCHWorked = await Util.GetAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
ApiResponse checkPATCHWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateNoErrorInResponse(checkPATCHWorked);
|
|
|
|
|
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName);
|
|
|
|
|
|
|
|
|
|
//DELETE
|
|
|
|
|
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -101,7 +97,7 @@ namespace raven_integration
|
|
|
|
|
{
|
|
|
|
|
//Get non existant
|
|
|
|
|
//Should return status code 404, api error code 2010
|
|
|
|
|
ApiResponse a = await Util.GetAsync("User/999999", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
ApiResponse a = await Util.GetAsync("User/999999", await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateResponseNotFound(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -113,36 +109,11 @@ namespace raven_integration
|
|
|
|
|
{
|
|
|
|
|
//Get non existant
|
|
|
|
|
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
|
|
|
|
ApiResponse a = await Util.GetAsync("User/2q2", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
ApiResponse a = await Util.GetAsync("User/2q2", await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateBadModelStateResponse(a, "id");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test server exception
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async void ServerExceptionShouldErrorPropertly()
|
|
|
|
|
{
|
|
|
|
|
//Get non existant
|
|
|
|
|
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
|
|
|
|
ApiResponse a = await Util.GetAsync("User/exception", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateServerExceptionResponse(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test server alt exception
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async void ServerAltExceptionShouldErrorPropertly()
|
|
|
|
|
{
|
|
|
|
|
//Get non existant
|
|
|
|
|
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
|
|
|
|
ApiResponse a = await Util.GetAsync("User/altexception", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
|
|
|
Util.ValidateServerExceptionResponse(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -162,7 +133,7 @@ namespace raven_integration
|
|
|
|
|
w2.active = true;
|
|
|
|
|
w2.roles = 0;
|
|
|
|
|
|
|
|
|
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
Util.ValidateDataReturnResponseOk(r2);
|
|
|
|
|
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
|
|
|
|
uint OriginalConcurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
|
|
|
|
@@ -175,7 +146,7 @@ namespace raven_integration
|
|
|
|
|
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
|
|
|
|
w2.OwnerId = 1;
|
|
|
|
|
w2.concurrencyToken = OriginalConcurrencyToken - 1;//bad token
|
|
|
|
|
ApiResponse PUTTestResponse = await Util.PutAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
ApiResponse PUTTestResponse = await Util.PutAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
Util.ValidateConcurrencyError(PUTTestResponse);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -199,7 +170,7 @@ namespace raven_integration
|
|
|
|
|
w2.active = true;
|
|
|
|
|
w2.roles = 0;
|
|
|
|
|
|
|
|
|
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
|
|
|
|
Util.ValidateDataReturnResponseOk(r2);
|
|
|
|
|
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
|
|
|
|
uint OriginalConcurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
|
|
|
|
@@ -208,7 +179,7 @@ namespace raven_integration
|
|
|
|
|
//PATCH
|
|
|
|
|
var newName = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATED VIA PATCH");
|
|
|
|
|
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
|
|
|
|
ApiResponse PATCHTestResponse = await Util.PatchAsync("User/" + w2Id.ToString() + "/" + (OriginalConcurrencyToken - 1).ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
|
|
|
|
ApiResponse PATCHTestResponse = await Util.PatchAsync("User/" + w2Id.ToString() + "/" + (OriginalConcurrencyToken - 1).ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
|
|
|
|
Util.ValidateConcurrencyError(PATCHTestResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|