using System; using Xunit; using Newtonsoft.Json.Linq; using FluentAssertions; using System.Collections.Generic; using System.Threading.Tasks; using System.Collections.Concurrent; namespace raven_integration { public class Translation { /* ImportTranslation(ct, ResourceFolderPath, "en"); - id 1 ImportTranslation(ct, ResourceFolderPath, "es"); - id 2 ImportTranslation(ct, ResourceFolderPath, "fr"); - id 3 ImportTranslation(ct, ResourceFolderPath, "de"); - id 4 */ [Fact] public async void TranslationListWorks() { //Get all ApiResponse a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("CustomerLimited"));//lowest level test user because there are no limits on this route except to be authenticated Util.ValidateDataReturnResponseOk(a); Util.ValidateHTTPStatusCode(a, 200); //there should be at least 4 of them as there are 4 stock translations ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(3); } [Fact] public async void GetFullTranslationWorks() { //Get all ApiResponse a = await Util.GetAsync("translation/1", await Util.GetTokenAsync("CustomerLimited"));//lowest level test user because there are no limits on this route except to be authenticated Util.ValidateDataReturnResponseOk(a); Util.ValidateHTTPStatusCode(a, 200); //there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one ((JArray)a.ObjectResponse["data"]["translationItems"]).Count.Should().BeGreaterThan(0); } [Fact] public async void GetSubsetWorks() { List keys = new List(); keys.AddRange(new string[] { "AddressType", "CustomerName", "RateName", "WorkOrder" }); dynamic d = new JObject(); d = JToken.FromObject(keys); ApiResponse a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString()); Util.ValidateDataReturnResponseOk(a); Util.ValidateHTTPStatusCode(a, 200); //there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one ((JArray)a.ObjectResponse["data"]).Count.Should().Be(4); } [Fact] public async void DuplicateUpdateAndDeleteWorks() { //DUPLICATE dynamic d = new JObject(); d.id = 1; d.name = Util.Uniquify("INTEGRATION-TEST-LOCALE"); ApiResponse a = await Util.PostAsync("translation/Duplicate", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); Util.ValidateDataReturnResponseOk(a); Util.ValidateHTTPStatusCode(a, 201); //verify the object returned is as expected a.ObjectResponse["data"]["name"].Value().Should().Be(d.name.ToString()); a.ObjectResponse["data"]["stock"].Value().Should().Be(false); a.ObjectResponse["data"]["id"].Value().Should().BeGreaterThan(4); a.ObjectResponse["data"]["concurrency"].Value().Should().BeGreaterThan(0); ((JArray)a.ObjectResponse["data"]["translationItems"]).Count.Should().BeGreaterThan(0); long NewId = a.ObjectResponse["data"]["id"].Value(); //UPDATE //Update translation name dynamic d2 = new JObject(); d2.id = NewId; d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALE NAME UPDATE"); d2.concurrency = a.ObjectResponse["data"]["concurrency"].Value(); ApiResponse PUTTestResponse = await Util.PutAsync("translation/UpdateTranslationName", await Util.GetTokenAsync("BizAdminFull"), d2.ToString()); Util.ValidateHTTPStatusCode(PUTTestResponse, 200); ApiResponse checkPUTWorked = await Util.GetAsync("translation/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull")); Util.ValidateNoErrorInResponse(checkPUTWorked); checkPUTWorked.ObjectResponse["data"]["name"].Value().Should().Be(d2.newText.ToString()); //uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value(); //Update translation key var FirstTranslationKey = ((JArray)a.ObjectResponse["data"]["translationItems"])[0]; long UpdatedTranslationKeyId = FirstTranslationKey["id"].Value(); d2.id = UpdatedTranslationKeyId; d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALEITEM DISPLAY UPDATE"); d2.concurrency = FirstTranslationKey["concurrency"].Value(); string UpdatedTranslationKey = FirstTranslationKey["key"].Value(); PUTTestResponse = await Util.PutAsync("translation/UpdateTranslationItemDisplayText", await Util.GetTokenAsync("BizAdminFull"), d2.ToString()); Util.ValidateHTTPStatusCode(PUTTestResponse, 200); //create user that is set to new translation so can use getSubset var Login = Util.Uniquify("LOGIN"); var Password = Util.Uniquify("PASSWORD"); dynamic DUSER = new JObject(); DUSER.name = Util.Uniquify("TranslationUpdateSubsetTestUser"); DUSER.active = true; DUSER.login = Login; DUSER.password = Password; DUSER.roles = 0;//norole (any role can get a subset of translation keys) // DUSER.translationId = NewId; DUSER.userType = 3;//non scheduleable //Required by form custom rules DUSER.notes = "notes"; DUSER.customFields = Util.UserRequiredCustomFieldsJsonString(); a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), DUSER.ToString()); Util.ValidateDataReturnResponseOk(a); long DUSERID = a.ObjectResponse["data"]["id"].Value(); //RETRIEVE companion USEROPTIONS object ApiResponse R = await Util.GetAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); Util.ValidateDataReturnResponseOk(R); //ensure the default value is set R.ObjectResponse["data"]["uiColor"].Value().Should().Be("#000000"); uint concurrency = R.ObjectResponse["data"]["concurrency"].Value(); //UPDATE //PUT dynamic D2 = new JObject(); D2.translationId = NewId; D2.concurrency = concurrency; PUTTestResponse = await Util.PutAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString()); Util.ValidateHTTPStatusCode(PUTTestResponse, 200); //VALIDATE R = await Util.GetAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); Util.ValidateDataReturnResponseOk(R); List keys = new List(); keys.AddRange(new string[] { UpdatedTranslationKey }); dynamic d3 = new JObject(); d3 = JToken.FromObject(keys); checkPUTWorked = await Util.PostAsync("translation/subset", await Util.GetTokenAsync(Login, Password), d3.ToString()); Util.ValidateDataReturnResponseOk(checkPUTWorked); Util.ValidateHTTPStatusCode(checkPUTWorked, 200); ((JArray)checkPUTWorked.ObjectResponse["data"]).Count.Should().Be(1); var FirstTranslationKeyUpdated = ((JArray)checkPUTWorked.ObjectResponse["data"])[0]; FirstTranslationKeyUpdated["value"].Value().Should().Be(d2.newText.ToString()); //DELETE TEMPORARY USER SO CAN DELETE LOCALE a = await Util.DeleteAsync("User/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); Util.ValidateHTTPStatusCode(a, 204); //DELETE TEMP LOCALE a = await Util.DeleteAsync("translation/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull")); Util.ValidateHTTPStatusCode(a, 204); } //================================================== }//eoc }//eons