123 lines
5.0 KiB
C#
123 lines
5.0 KiB
C#
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("manager", "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("UserOptions/" + UserId.ToString(), await Util.GetTokenAsync("manager", "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("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
|
|
/*
|
|
"{\"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("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
|
|
|
//CHECK DELETE USER REMOVED USEROPTIONS
|
|
R = await Util.GetAsync("UserOptions/" + UserId.ToString(), await Util.GetTokenAsync("manager", "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("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
|