Files
raven-test-integration/User/UserOptions.cs
2020-03-18 15:45:40 +00:00

124 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.translationId=1;
D1.userType = 3;//non scheduleable
//Required by form custom rules
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<int>().Should().Be(0);
uint concurrencyToken = R.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
//UPDATE
//PUT
dynamic D2 = new JObject();
D2.EmailAddress = "testuseroptions@helloayanova.com";
D2.LanguageOverride = "de-DE";
D2.TimeZoneOverride = "Europe/Berlin";
D2.CurrencyName = "EUR";
D2.Hour12 = false;
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
/*
"{\"data\":{\"id\":44,\"concurrencyToken\":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<int>().Should().Be((int)D2.UiColor);
concurrencyToken = R.ObjectResponse["data"]["concurrencyToken"].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