4648
This commit is contained in:
526
User/UserCrud.cs
526
User/UserCrud.cs
@@ -1,263 +1,263 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a User
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("First Test User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
|
||||
D1.userType = 3;//non scheduleable
|
||||
|
||||
//Required by form custom rules
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R1 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R1);
|
||||
long d1Id = R1.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
dynamic D2 = new JObject();
|
||||
D2.name = Util.Uniquify("Second Test User");
|
||||
//Required by form custom rules
|
||||
D2.notes = "notes";
|
||||
D2.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D2.active = true;
|
||||
D2.login = Util.Uniquify("LOGIN");
|
||||
D2.password = Util.Uniquify("PASSWORD");
|
||||
D2.roles = 0;//norole
|
||||
|
||||
D2.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R2 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R2);
|
||||
long d2Id = R2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse R3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R3);
|
||||
R3.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
D2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
||||
D2.concurrency = R2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
D2.id=d2Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User" , await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UserWithActivityShouldNotBeDeleteable()
|
||||
{
|
||||
ApiResponse a = await Util.DeleteAsync("User/1", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
a.ObjectResponse["error"]["details"][0]["message"].Value<string>().Should().Contain("LT:ErrorDBForeignKeyViolation");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("User/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("User/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic D = new JObject();
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
D.notes = "notes";
|
||||
D.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D.active = true;
|
||||
D.login = Util.Uniquify("LOGIN");
|
||||
D.password = Util.Uniquify("PASSWORD");
|
||||
D.roles = 0;//norole
|
||||
|
||||
D.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long D1Id = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
D.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
D.id=D1Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutPasswordShouldWork()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("PutPasswordShouldWork");
|
||||
|
||||
d.active = true;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
|
||||
d.userType = 3;//non scheduleable
|
||||
//Required by form custom rules
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long UserId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//Test can login
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = d.password;
|
||||
DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//GET user (login changed concurrency token above)
|
||||
a = await Util.GetAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
d = a.ObjectResponse["data"];
|
||||
|
||||
|
||||
//PUT
|
||||
var NewPassword = "NEW_PASSWORD";
|
||||
d.password = NewPassword;
|
||||
d.login=DCreds.login;
|
||||
a = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Test can login with new creds
|
||||
//dynamic DCreds = new JObject();
|
||||
DCreds.password = NewPassword;
|
||||
// DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void NonUniqueLoginShouldFail()
|
||||
{
|
||||
var UniqueLogin = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
//CREATE FIRST USER
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
|
||||
|
||||
//Attempt create second with same login
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("2NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Login", "2206");
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2200\",\"details\":[{\"target\":\"Login\",\"error\":\"2206\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a User
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("First Test User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
|
||||
D1.userType = 3;//non scheduleable
|
||||
|
||||
//Required by form custom rules
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R1 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R1);
|
||||
long d1Id = R1.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
dynamic D2 = new JObject();
|
||||
D2.name = Util.Uniquify("Second Test User");
|
||||
//Required by form custom rules
|
||||
D2.notes = "notes";
|
||||
D2.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D2.active = true;
|
||||
D2.login = Util.Uniquify("LOGIN");
|
||||
D2.password = Util.Uniquify("PASSWORD");
|
||||
D2.roles = 0;//norole
|
||||
|
||||
D2.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R2 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R2);
|
||||
long d2Id = R2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse R3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R3);
|
||||
R3.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
D2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
||||
D2.concurrency = R2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
D2.id=d2Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User" , await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task UserWithActivityShouldNotBeDeleteable()
|
||||
{
|
||||
ApiResponse a = await Util.DeleteAsync("User/1", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
a.ObjectResponse["error"]["details"][0]["message"].Value<string>().Should().Contain("LT:ErrorDBForeignKeyViolation");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("User/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("User/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic D = new JObject();
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
D.notes = "notes";
|
||||
D.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D.active = true;
|
||||
D.login = Util.Uniquify("LOGIN");
|
||||
D.password = Util.Uniquify("PASSWORD");
|
||||
D.roles = 0;//norole
|
||||
|
||||
D.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long D1Id = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
D.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
D.id=D1Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PutPasswordShouldWork()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("PutPasswordShouldWork");
|
||||
|
||||
d.active = true;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
|
||||
d.userType = 3;//non scheduleable
|
||||
//Required by form custom rules
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long UserId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//Test can login
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = d.password;
|
||||
DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//GET user (login changed concurrency token above)
|
||||
a = await Util.GetAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
d = a.ObjectResponse["data"];
|
||||
|
||||
|
||||
//PUT
|
||||
var NewPassword = "NEW_PASSWORD";
|
||||
d.password = NewPassword;
|
||||
d.login=DCreds.login;
|
||||
a = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Test can login with new creds
|
||||
//dynamic DCreds = new JObject();
|
||||
DCreds.password = NewPassword;
|
||||
// DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task NonUniqueLoginShouldFail()
|
||||
{
|
||||
var UniqueLogin = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
//CREATE FIRST USER
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
|
||||
|
||||
//Attempt create second with same login
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("2NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Login", "2206");
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2200\",\"details\":[{\"target\":\"Login\",\"error\":\"2206\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserInactive
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Inactive user should not be able to login
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void InactiveUserCantLogin()
|
||||
{
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = DCreds.login = "TEST_INACTIVE";
|
||||
ApiResponse a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateErrorCodeResponse(a,2003, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserInactive
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Inactive user should not be able to login
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InactiveUserCantLogin()
|
||||
{
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = DCreds.login = "TEST_INACTIVE";
|
||||
ApiResponse a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateErrorCodeResponse(a,2003, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserOptions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a UserOptions object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
|
||||
//CREATE a user
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("Test UserOptions User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
D1.userType = 3;//non scheduleable
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long UserId = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//Now there should be a user options available for this user
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
|
||||
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.translationId = 1;
|
||||
D2.emailAddress = "testuseroptions@helloayanova.com";
|
||||
D2.languageOverride = "de-DE";
|
||||
D2.timeZoneOverride = "Europe/Berlin";
|
||||
D2.currencyName = "EUR";
|
||||
D2.hour12 = false;
|
||||
D2.uiColor = "#ffaaff";
|
||||
D2.concurrency = concurrency;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
/*
|
||||
"{\"data\":{\"id\":44,\"concurrency\":7144348,\"emailAddress\":null,\"uiColor\":0,\"languageOverride\":null,\"timeZoneOverride\":null,\"currencyName\":\"USD\",\"hour12\":true,\"userId\":44}}"
|
||||
*/
|
||||
R.ObjectResponse["data"]["emailAddress"].Value<string>().Should().Be(D2.emailAddress.ToString());
|
||||
R.ObjectResponse["data"]["languageOverride"].Value<string>().Should().Be(D2.languageOverride.ToString());
|
||||
R.ObjectResponse["data"]["timeZoneOverride"].Value<string>().Should().Be(D2.timeZoneOverride.ToString());
|
||||
R.ObjectResponse["data"]["currencyName"].Value<string>().Should().Be(D2.currencyName.ToString());
|
||||
R.ObjectResponse["data"]["hour12"].Value<bool>().Should().Be((bool)D2.hour12);
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be(D2.uiColor.ToString());
|
||||
R.ObjectResponse["data"]["translationId"].Value<long>().Should().Be((long)D2.translationId);
|
||||
concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//DELETE USER
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//CHECK DELETE USER REMOVED USEROPTIONS
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("user-option/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("user-option/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserOptions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a UserOptions object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
|
||||
//CREATE a user
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("Test UserOptions User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
D1.userType = 3;//non scheduleable
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long UserId = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//Now there should be a user options available for this user
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
|
||||
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.translationId = 1;
|
||||
D2.emailAddress = "testuseroptions@helloayanova.com";
|
||||
D2.languageOverride = "de-DE";
|
||||
D2.timeZoneOverride = "Europe/Berlin";
|
||||
D2.currencyName = "EUR";
|
||||
D2.hour12 = false;
|
||||
D2.uiColor = "#ffaaff";
|
||||
D2.concurrency = concurrency;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
/*
|
||||
"{\"data\":{\"id\":44,\"concurrency\":7144348,\"emailAddress\":null,\"uiColor\":0,\"languageOverride\":null,\"timeZoneOverride\":null,\"currencyName\":\"USD\",\"hour12\":true,\"userId\":44}}"
|
||||
*/
|
||||
R.ObjectResponse["data"]["emailAddress"].Value<string>().Should().Be(D2.emailAddress.ToString());
|
||||
R.ObjectResponse["data"]["languageOverride"].Value<string>().Should().Be(D2.languageOverride.ToString());
|
||||
R.ObjectResponse["data"]["timeZoneOverride"].Value<string>().Should().Be(D2.timeZoneOverride.ToString());
|
||||
R.ObjectResponse["data"]["currencyName"].Value<string>().Should().Be(D2.currencyName.ToString());
|
||||
R.ObjectResponse["data"]["hour12"].Value<bool>().Should().Be((bool)D2.hour12);
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be(D2.uiColor.ToString());
|
||||
R.ObjectResponse["data"]["translationId"].Value<long>().Should().Be((long)D2.translationId);
|
||||
concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//DELETE USER
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//CHECK DELETE USER REMOVED USEROPTIONS
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("user-option/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("user-option/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
Reference in New Issue
Block a user