This commit is contained in:
131
test/raven-integration/User/UserOptionsRu.cs
Normal file
131
test/raven-integration/User/UserOptionsRu.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserOptionsRu
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a UserOptions object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void RU()
|
||||
{
|
||||
|
||||
//CREATE a user
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("Test UserOptions 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 R = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long UserId = R.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//Now there should be a user options available for this user
|
||||
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
|
||||
//Get it
|
||||
R = await Util.GetAsync("UserOptions/" + UserId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["result"]["uiColor"].Value<int>().Should().Be(0);
|
||||
uint concurrencyToken = R.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.emailaddress = "testuseroptions@helloayanova.com";
|
||||
D2.TimeZoneOffset = -7.5M;//Decimal value
|
||||
D2.UiColor = -2097216;//Int value (no suffix for int literals)
|
||||
D2.concurrencyToken = concurrencyToken;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("UserOptions/" + UserId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("UserOptions/" + UserId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["result"]["emailAddress"].Value<string>().Should().Be(D2.emailaddress.ToString());
|
||||
R.ObjectResponse["result"]["timeZoneOffset"].Value<decimal>().Should().Be((decimal)D2.TimeZoneOffset);
|
||||
R.ObjectResponse["result"]["uiColor"].Value<int>().Should().Be((int)D2.UiColor);
|
||||
concurrencyToken = R.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
// //update w2id
|
||||
// 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/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
// Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
// 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/" + d2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
||||
// Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
||||
|
||||
// //check PATCH worked
|
||||
// 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/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
// Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <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("UserOptions/999999", await Util.GetTokenAsync("manager", "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("UserOptions/2q2", await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user