This commit is contained in:
2026-02-24 07:05:56 -08:00
parent 76109ad265
commit 13b3aed088
34 changed files with 9807 additions and 9804 deletions

View File

@@ -1,20 +1,20 @@
using System.Net.Http; using System.Net.Http;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace raven_integration namespace raven_integration
{ {
public class ApiResponse public class ApiResponse
{ {
public HttpResponseMessage HttpResponse { get; set; } public HttpResponseMessage HttpResponse { get; set; }
public JObject ObjectResponse { get; set; } public JObject ObjectResponse { get; set; }
public string CompactResponse public string CompactResponse
{ {
get get
{ {
return ObjectResponse.ToString(Newtonsoft.Json.Formatting.None); return ObjectResponse.ToString(Newtonsoft.Json.Formatting.None);
} }
} }
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,31 +1,31 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class ApiRoute public class ApiRoute
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerApiRootPageShouldFetch() public async Task ServerApiRootPageShouldFetch()
{ {
ApiTextResponse t = await Util.GetNonApiPageAsync("/api/v8/"); ApiTextResponse t = await Util.GetNonApiPageAsync("/api/v8/");
Util.ValidateHTTPStatusCode(t, 200); Util.ValidateHTTPStatusCode(t, 200);
t.TextResponse.Should().Contain("<title>AyaNova server</title>"); t.TextResponse.Should().Contain("<title>AyaNova server</title>");
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,13 +1,13 @@
using System.Net.Http; using System.Net.Http;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace raven_integration namespace raven_integration
{ {
public class ApiTextResponse public class ApiTextResponse
{ {
public HttpResponseMessage HttpResponse {get;set;} public HttpResponseMessage HttpResponse {get;set;}
public string TextResponse {get;set;} public string TextResponse {get;set;}
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,204 +1,204 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.IO; using System.IO;
namespace raven_integration namespace raven_integration
{ {
//https://stackoverflow.com/questions/17725882/testing-asp-net-web-api-multipart-form-data-file-upload //https://stackoverflow.com/questions/17725882/testing-asp-net-web-api-multipart-form-data-file-upload
public class AttachmentTest public class AttachmentTest
{ {
/// <summary> /// <summary>
/// test attach CRUD /// test attach CRUD
/// </summary> /// </summary>
[Fact] [Fact]
public async void AttachmentUploadDownloadDeleteShouldWork() public async Task AttachmentUploadDownloadDeleteShouldWork()
{ {
//Make a user just for this test so can deal with dl token properly //Make a user just for this test so can deal with dl token properly
var UniqueName = Util.Uniquify("AttachmentUploadDownloadDeleteShouldWork"); var UniqueName = Util.Uniquify("AttachmentUploadDownloadDeleteShouldWork");
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = UniqueName; d.name = UniqueName;
d.active = true; d.active = true;
d.login = UniqueName; d.login = UniqueName;
d.password = UniqueName; d.password = UniqueName;
d.roles = 2;//bizadminfull needs widget rights d.roles = 2;//bizadminfull needs widget rights
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
//Required by form custom rules //Required by form custom rules
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long TestUserId=a.ObjectResponse["data"]["id"].Value<long>(); long TestUserId=a.ObjectResponse["data"]["id"].Value<long>();
d = new JObject(); d = new JObject();
d.login = UniqueName; d.login = UniqueName;
d.password = UniqueName; d.password = UniqueName;
a = await Util.PostAsync("auth", null, d.ToString()); a = await Util.PostAsync("auth", null, d.ToString());
string downloadToken = a.ObjectResponse["data"]["dlt"].Value<string>(); string downloadToken = a.ObjectResponse["data"]["dlt"].Value<string>();
////////////////////////////////////////// //////////////////////////////////////////
//// Upload the files //// Upload the files
MultipartFormDataContent formDataContent = new MultipartFormDataContent(); MultipartFormDataContent formDataContent = new MultipartFormDataContent();
//Form data like the bizobject type and id //Form data like the bizobject type and id
formDataContent.Add(new StringContent("3"), name: "AttachToObjectType"); formDataContent.Add(new StringContent("3"), name: "AttachToObjectType");
formDataContent.Add(new StringContent(TestUserId.ToString()), name: "AttachToObjectId"); formDataContent.Add(new StringContent(TestUserId.ToString()), name: "AttachToObjectId");
formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes"); formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes");
formDataContent.Add(new StringContent("[{\"name\":\"test.zip\",\"lastModified\":1582822079618},{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData"); formDataContent.Add(new StringContent("[{\"name\":\"test.zip\",\"lastModified\":1582822079618},{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData");
//fileData in JSON stringify format which contains the actual last modified dates etc //fileData in JSON stringify format which contains the actual last modified dates etc
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]" //"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
//or if testing non-existant this is probably safe: long.MaxValue //or if testing non-existant this is probably safe: long.MaxValue
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png")); StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png"); file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
file1.Headers.ContentDisposition.FileName = "test.png"; file1.Headers.ContentDisposition.FileName = "test.png";
formDataContent.Add(file1); formDataContent.Add(file1);
StreamContent file2 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.zip")); StreamContent file2 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.zip"));
file2.Headers.ContentType = new MediaTypeHeaderValue("application/zip"); file2.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
file2.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); file2.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
file2.Headers.ContentDisposition.FileName = "test.zip"; file2.Headers.ContentDisposition.FileName = "test.zip";
formDataContent.Add(file2); formDataContent.Add(file2);
//create via inventory full test user as attachments use the role of the object attaching to //create via inventory full test user as attachments use the role of the object attaching to
a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long lTestPngAttachmentId = a.ObjectResponse["data"][0]["id"].Value<long>(); long lTestPngAttachmentId = a.ObjectResponse["data"][0]["id"].Value<long>();
long lTestZipAttachmentId = a.ObjectResponse["data"][1]["id"].Value<long>(); long lTestZipAttachmentId = a.ObjectResponse["data"][1]["id"].Value<long>();
//saw negative values on a db issue that I corrected (I think) //saw negative values on a db issue that I corrected (I think)
//Keeping these in case it arises again, if it does, see log, it's a db error with async issue of some kind //Keeping these in case it arises again, if it does, see log, it's a db error with async issue of some kind
lTestPngAttachmentId.Should().BePositive(); lTestPngAttachmentId.Should().BePositive();
lTestZipAttachmentId.Should().BePositive(); lTestZipAttachmentId.Should().BePositive();
////////////////////////////////////////// //////////////////////////////////////////
//// DOWNLOAD: Get the file attachment //// DOWNLOAD: Get the file attachment
//now get the file https://rockfish.ayanova.com/api/rfcaseblob/download/248?t=9O2eDAAlZ0Wknj19SBK2iA //now get the file https://rockfish.ayanova.com/api/rfcaseblob/download/248?t=9O2eDAAlZ0Wknj19SBK2iA
var dlresponse = await Util.DownloadFileAsync("attachment/Download/" + lTestZipAttachmentId.ToString() + "?t=" + downloadToken, null); var dlresponse = await Util.DownloadFileAsync("attachment/Download/" + lTestZipAttachmentId.ToString() + "?t=" + downloadToken, null);
//ensure it's the zip file we expected //ensure it's the zip file we expected
dlresponse.Content.Headers.ContentDisposition.FileName.Should().Be("test.zip"); dlresponse.Content.Headers.ContentDisposition.FileName.Should().Be("test.zip");
dlresponse.Content.Headers.ContentLength.Should().BeGreaterThan(2000); dlresponse.Content.Headers.ContentLength.Should().BeGreaterThan(2000);
////////////////////////////////////////// //////////////////////////////////////////
//// DELETE: Delete the file attachments //// DELETE: Delete the file attachments
a = await Util.DeleteAsync("attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
/// <summary> /// <summary>
/// test no rights /// test no rights
/// </summary> /// </summary>
[Fact] [Fact]
public async void NoRightsTest() public async Task NoRightsTest()
{ {
MultipartFormDataContent formDataContent = new MultipartFormDataContent(); MultipartFormDataContent formDataContent = new MultipartFormDataContent();
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType"); formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId"); formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes"); formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes");
formDataContent.Add(new StringContent("[{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData"); formDataContent.Add(new StringContent("[{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData");
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png")); StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png"); file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
file1.Headers.ContentDisposition.FileName = "test.png"; file1.Headers.ContentDisposition.FileName = "test.png";
formDataContent.Add(file1); formDataContent.Add(file1);
//ERROR CONDITION: BizAdminLimited user should not be able to attach a file to a widget //ERROR CONDITION: BizAdminLimited user should not be able to attach a file to a widget
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("BizAdminLimited")); ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("BizAdminLimited"));
//2004 unauthorized //2004 unauthorized
Util.ValidateErrorCodeResponse(a, 2004, 403); Util.ValidateErrorCodeResponse(a, 2004, 403);
} }
/// <summary> /// <summary>
/// test not attachable /// test not attachable
/// </summary> /// </summary>
[Fact] [Fact]
public async void UnattachableTest() public async Task UnattachableTest()
{ {
MultipartFormDataContent formDataContent = new MultipartFormDataContent(); MultipartFormDataContent formDataContent = new MultipartFormDataContent();
//Form data bizobject type and id //Form data bizobject type and id
//HERE IS THE ERROR CONDITION: LICENSE TYPE OBJECT WHICH IS UNATTACHABLE //HERE IS THE ERROR CONDITION: LICENSE TYPE OBJECT WHICH IS UNATTACHABLE
formDataContent.Add(new StringContent("5"), name: "AttachToObjectType"); formDataContent.Add(new StringContent("5"), name: "AttachToObjectType");
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId"); formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png")); StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png"); file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
file1.Headers.ContentDisposition.FileName = "test.png"; file1.Headers.ContentDisposition.FileName = "test.png";
formDataContent.Add(file1); formDataContent.Add(file1);
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull")); ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
//2203 unattachable object //2203 unattachable object
Util.ValidateErrorCodeResponse(a, 2203, 400); Util.ValidateErrorCodeResponse(a, 2203, 400);
} }
/// <summary> /// <summary>
/// test bad object values /// test bad object values
/// </summary> /// </summary>
[Fact] [Fact]
public async void BadObject() public async Task BadObject()
{ {
MultipartFormDataContent formDataContent = new MultipartFormDataContent(); MultipartFormDataContent formDataContent = new MultipartFormDataContent();
//Form data like the bizobject type and id //Form data like the bizobject type and id
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType"); formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
//HERE IS THE ERROR CONDITION, A NON EXISTENT ID VALUE FOR THE WIDGET //HERE IS THE ERROR CONDITION, A NON EXISTENT ID VALUE FOR THE WIDGET
formDataContent.Add(new StringContent(long.MaxValue.ToString()), name: "AttachToObjectId");//non-existent widget formDataContent.Add(new StringContent(long.MaxValue.ToString()), name: "AttachToObjectId");//non-existent widget
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png")); StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png"); file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
file1.Headers.ContentDisposition.FileName = "test.png"; file1.Headers.ContentDisposition.FileName = "test.png";
formDataContent.Add(file1); formDataContent.Add(file1);
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull")); ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
//2203 invalid attachment object //2203 invalid attachment object
Util.ValidateErrorCodeResponse(a, 2203, 400); Util.ValidateErrorCodeResponse(a, 2203, 400);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,137 +1,137 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class auth public class Auth
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BadLoginShouldNotWork() public async Task BadLoginShouldNotWork()
{ {
//Expect status code 401 and result: //Expect status code 401 and result:
// {{ // {{
// "error": { // "error": {
// "code": "2003", // "code": "2003",
// "message": "Authentication failed" // "message": "Authentication failed"
// } // }
// }} // }}
dynamic d = new JObject(); dynamic d = new JObject();
d.login = "BOGUS"; d.login = "BOGUS";
d.password = "ACCOUNT"; d.password = "ACCOUNT";
ApiResponse a = await Util.PostAsync("auth", null, d.ToString()); ApiResponse a = await Util.PostAsync("auth", null, d.ToString());
Util.ValidateErrorCodeResponse(a, 2003, 401); Util.ValidateErrorCodeResponse(a, 2003, 401);
} }
//NOTE: These tests are for Debug builds, they should still pass in a release build because none of the creds will work and it checks for 401 only //NOTE: These tests are for Debug builds, they should still pass in a release build because none of the creds will work and it checks for 401 only
//but a true test of these JWT tokens is only in server debug mode //but a true test of these JWT tokens is only in server debug mode
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void JWTExpiredTokenShouldFail() public async Task JWTExpiredTokenShouldFail()
{ {
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "EXPIRED"));//lowest level test user because there are no limits on this route except to be authenticated a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "EXPIRED"));//lowest level test user because there are no limits on this route except to be authenticated
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void JWTWrongIssuerShouldFail() public async Task JWTWrongIssuerShouldFail()
{ {
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_ISSUER"));//lowest level test user because there are no limits on this route except to be authenticated a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_ISSUER"));//lowest level test user because there are no limits on this route except to be authenticated
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void JWTNoAlgorithmShouldFail() public async Task JWTNoAlgorithmShouldFail()
{ {
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "NO_ALGORITHM")); a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "NO_ALGORITHM"));
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void JWTBadSecretShouldFail() public async Task JWTBadSecretShouldFail()
{ {
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_SECRET")); a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_SECRET"));
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void JWTTruncatedSignatureShouldFail() public async Task JWTTruncatedSignatureShouldFail()
{ {
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRUNCATED_SIGNATURE")); a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRUNCATED_SIGNATURE"));
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void JWTTransposedSignatureShouldFail() public async Task JWTTransposedSignatureShouldFail()
{ {
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRANSPOSE_SIGNATURE")); a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRANSPOSE_SIGNATURE"));
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,30 +1,30 @@
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class DataListRights public class DataListRights
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void InsufficentRightsShouldNotRetrieve() public async Task InsufficentRightsShouldNotRetrieve()
{ {
//Get without rights //Get without rights
/* /*
"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}" "{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
*/ */
//ApiResponse a = await Util.GetAsync("data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=3", await Util.GetTokenAsync("CustomerLimited")); //ApiResponse a = await Util.GetAsync("data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=3", await Util.GetTokenAsync("CustomerLimited"));
ApiResponse a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("CustomerLimited"), Util.BuildDataListRequestEx()); ApiResponse a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("CustomerLimited"), Util.BuildDataListRequestEx());
Util.ValidateErrorCodeResponse(a, 2004, 403); Util.ValidateErrorCodeResponse(a, 2004, 403);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,413 +1,413 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class DataListSorting public class DataListSorting
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void DefaultSortByIdWorks() public async Task DefaultSortByIdWorks()
{ {
var WidgetNameStart = Util.Uniquify("DefaultSortByIdWorks"); var WidgetNameStart = Util.Uniquify("DefaultSortByIdWorks");
//CREATE 3 TEST WIDGETS TO TEST ORDER //CREATE 3 TEST WIDGETS TO TEST ORDER
long FirstInOrderWidgetId = 0; long FirstInOrderWidgetId = 0;
long SecondInOrderWidgetId = 0; long SecondInOrderWidgetId = 0;
long ThirdInOrderWidgetId = 0; long ThirdInOrderWidgetId = 0;
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.usertype = 1; w.usertype = 1;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
//CREATE FILTER //CREATE FILTER
dynamic dListView = new JArray(); dynamic dListView = new JArray();
//name starts with filter to constrict to widgets that this test block created only //name starts with filter to constrict to widgets that this test block created only
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart)); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
//NOW FETCH WIDGET LIST WITH FILTER //NOW FETCH WIDGET LIST WITH FILTER
// a = await Util.GetAsync($"data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=999&DataFilterId={DataFilterId.ToString()}", await Util.GetTokenAsync("superuser", "l3tm3in")); // a = await Util.GetAsync($"data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=999&DataFilterId={DataFilterId.ToString()}", await Util.GetTokenAsync("superuser", "l3tm3in"));
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//assert contains exactly 3 records //assert contains exactly 3 records
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
//assert the order returned //assert the order returned
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId); a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId); a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId); a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void SortByFieldAscendingWorks() public async Task SortByFieldAscendingWorks()
{ {
var WidgetNameStart = Util.Uniquify("SortByFieldAscendingWorks"); var WidgetNameStart = Util.Uniquify("SortByFieldAscendingWorks");
//CREATE 3 TEST WIDGETS TO TEST ORDER //CREATE 3 TEST WIDGETS TO TEST ORDER
long FirstInOrderWidgetId = 0; long FirstInOrderWidgetId = 0;
long SecondInOrderWidgetId = 0; long SecondInOrderWidgetId = 0;
long ThirdInOrderWidgetId = 0; long ThirdInOrderWidgetId = 0;
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.startDate = DateTime.Now; w.startDate = DateTime.Now;
w.endDate = DateTime.Now.AddHours(1); w.endDate = DateTime.Now.AddHours(1);
w.usertype = 1; w.usertype = 1;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.startDate = DateTime.Now.AddHours(1); w.startDate = DateTime.Now.AddHours(1);
w.endDate = DateTime.Now.AddHours(2); w.endDate = DateTime.Now.AddHours(2);
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.startDate = DateTime.Now.AddHours(2); w.startDate = DateTime.Now.AddHours(2);
w.endDate = DateTime.Now.AddHours(3); w.endDate = DateTime.Now.AddHours(3);
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
//CREATE FILTER //CREATE FILTER
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY //FILTER IN BY NAME FOR TESTING THIS RUN ONLY
dynamic dListView = new JArray(); dynamic dListView = new JArray();
//name starts with filter to constrict to widgets that this test block created only //name starts with filter to constrict to widgets that this test block created only
//SORT ORDER ################### //SORT ORDER ###################
// dynamic dsortarray = new JArray(); // dynamic dsortarray = new JArray();
// dynamic dsort = new JObject(); // dynamic dsort = new JObject();
// dsort.fld = "widgetstartdate"; // dsort.fld = "widgetstartdate";
// dsort.dir = "+"; // dsort.dir = "+";
// dsortarray.Add(dsort); // dsortarray.Add(dsort);
//both conditions filter and sort here //both conditions filter and sort here
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart, "+")); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart, "+"));
//NOW FETCH WIDGET LIST WITH FILTER //NOW FETCH WIDGET LIST WITH FILTER
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//assert contains exactly 3 records //assert contains exactly 3 records
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
//assert the order returned //assert the order returned
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId); a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId); a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId); a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void SortByFieldDescendingWorks() public async Task SortByFieldDescendingWorks()
{ {
var WidgetNameStart = Util.Uniquify("SortByFieldDescendingWorks"); var WidgetNameStart = Util.Uniquify("SortByFieldDescendingWorks");
//CREATE 3 TEST WIDGETS TO TEST ORDER //CREATE 3 TEST WIDGETS TO TEST ORDER
long FirstInOrderWidgetId = 0; long FirstInOrderWidgetId = 0;
long SecondInOrderWidgetId = 0; long SecondInOrderWidgetId = 0;
long ThirdInOrderWidgetId = 0; long ThirdInOrderWidgetId = 0;
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.count = 999; w.count = 999;
w.usertype = 1; w.usertype = 1;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.count = 665; w.count = 665;
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.count = 333; w.count = 333;
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
//CREATE FILTER //CREATE FILTER
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY //FILTER IN BY NAME FOR TESTING THIS RUN ONLY
dynamic dListView = new JArray(); dynamic dListView = new JArray();
//name starts with filter to constrict to widgets that this test block created only //name starts with filter to constrict to widgets that this test block created only
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart)); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
//SORT ORDER ################### //SORT ORDER ###################
// dynamic dsortarray = new JArray(); // dynamic dsortarray = new JArray();
// dynamic dsort = new JObject(); // dynamic dsort = new JObject();
// dsort.fld = "widgetcount"; // dsort.fld = "widgetcount";
// dsort.dir = "-"; // dsort.dir = "-";
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-")); dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-"));
//NOW FETCH WIDGET LIST WITH FILTER //NOW FETCH WIDGET LIST WITH FILTER
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//assert contains exactly 3 records //assert contains exactly 3 records
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
//assert the order returned //assert the order returned
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId); a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId); a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId); a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void SortByMultipleFieldsWorks() public async Task SortByMultipleFieldsWorks()
{ {
/* /*
Created order: Created order:
dollaramount, count dollaramount, count
2,1 2,1
1,2 1,2
2,2 2,2
1,1 1,1
sorted order: sorted order:
dollar asc, count desc dollar asc, count desc
1,2 1,2
1,1 1,1
2,2 2,2
2,1 2,1
*/ */
var WidgetNameStart = Util.Uniquify("SortByMultipleFieldsWorks"); var WidgetNameStart = Util.Uniquify("SortByMultipleFieldsWorks");
//CREATE 4 TEST WIDGETS TO TEST ORDER //CREATE 4 TEST WIDGETS TO TEST ORDER
long FirstInOrderWidgetId = 0; long FirstInOrderWidgetId = 0;
long SecondInOrderWidgetId = 0; long SecondInOrderWidgetId = 0;
long ThirdInOrderWidgetId = 0; long ThirdInOrderWidgetId = 0;
long FourthInOrderWidgetId = 0; long FourthInOrderWidgetId = 0;
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.dollaramount = 2.22; w.dollaramount = 2.22;
w.count = 1; w.count = 1;
w.usertype = 1; w.usertype = 1;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
FourthInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); FourthInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.dollaramount = 1.11; w.dollaramount = 1.11;
w.count = 2; w.count = 2;
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.dollaramount = 1.11; w.dollaramount = 1.11;
w.count = 1; w.count = 1;
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
w = new JObject(); w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.dollaramount = 2.22; w.dollaramount = 2.22;
w.count = 2; w.count = 2;
w.usertype = 1; w.usertype = 1;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
//CREATE FILTER //CREATE FILTER
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY //FILTER IN BY NAME FOR TESTING THIS RUN ONLY
dynamic dListView = new JArray(); dynamic dListView = new JArray();
//name starts with filter to constrict to widgets that this test block created only //name starts with filter to constrict to widgets that this test block created only
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart)); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
//SORT ORDER ################### //SORT ORDER ###################
// dynamic dsortarray = new JArray(); // dynamic dsortarray = new JArray();
//First column //First column
// dynamic dsort1 = new JObject(); // dynamic dsort1 = new JObject();
// dsort1.fld = "widgetdollaramount"; // dsort1.fld = "widgetdollaramount";
// dsort1.dir = "+"; // dsort1.dir = "+";
// dsortarray.Add(dsort1); // dsortarray.Add(dsort1);
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetdollaramount", "+")); dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetdollaramount", "+"));
//Second column //Second column
// dynamic dsort2 = new JObject(); // dynamic dsort2 = new JObject();
// dsort2.fld = "widgetcount"; // dsort2.fld = "widgetcount";
// dsort2.dir = "-"; // dsort2.dir = "-";
// dsortarray.Add(dsort2); // dsortarray.Add(dsort2);
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-")); dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-"));
//NOW FETCH WIDGET LIST WITH FILTER //NOW FETCH WIDGET LIST WITH FILTER
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//assert contains exactly 3 records //assert contains exactly 3 records
((JArray)a.ObjectResponse["data"]).Count.Should().Be(4); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(4);
//assert the order returned //assert the order returned
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId); a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId); a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId); a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
a.ObjectResponse["data"][3][0]["i"].Value<long>().Should().Be(FourthInOrderWidgetId); a.ObjectResponse["data"][3][0]["i"].Value<long>().Should().Be(FourthInOrderWidgetId);
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("widget/" + FourthInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("widget/" + FourthInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
//======================================================================== //========================================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,202 +1,202 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class DataListFilterCrud public class DataListFilterCrud
{ {
/// <summary> /// <summary>
/// Test all CRUD routes /// Test all CRUD routes
/// </summary> /// </summary>
[Fact] [Fact]
public async void CRUD() public async Task CRUD()
{ {
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("Test DataListView"); d.name = Util.Uniquify("Test DataListView");
d["public"] = true; d["public"] = true;
d.listKey="TestWidgetDataList"; d.listKey="TestWidgetDataList";
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}] //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
dynamic dListView = new JArray(); dynamic dListView = new JArray();
// dynamic df = new JObject(); // dynamic df = new JObject();
// df.fld = "widgetname"; // df.fld = "widgetname";
// df.op = "%-"; // df.op = "%-";
// df.value = "Generic";//lots of seed widgets start with Generic // df.value = "Generic";//lots of seed widgets start with Generic
// dListView.Add(df); // dListView.Add(df);
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json // d.filter = dListView.ToString();//it expects it to be a json string, not actual json
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic")); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic"));
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None); d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long Id = a.ObjectResponse["data"]["id"].Value<long>(); long Id = a.ObjectResponse["data"]["id"].Value<long>();
//RETRIEVE //RETRIEVE
//Get one //Get one
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView"); a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView");
//Get as alternate user should work for public filter //Get as alternate user should work for public filter
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited")); a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView"); a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView");
//UPDATE //UPDATE
//PUT, make private //PUT, make private
d["public"] = false; d["public"] = false;
d.name = Util.Uniquify("Put - Test DataListView (privatized)"); d.name = Util.Uniquify("Put - Test DataListView (privatized)");
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>(); d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
a = await Util.PutAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString()); a = await Util.PutAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString());
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//check PUT worked //check PUT worked
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateNoErrorInResponse(a); Util.ValidateNoErrorInResponse(a);
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString()); a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
//FETCH DISALLOWED //FETCH DISALLOWED
//Get as alternate user should fail for private filter //Get as alternate user should fail for private filter
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited")); a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
Util.ValidateResponseNotFound(a); Util.ValidateResponseNotFound(a);
// //DELETE // //DELETE
ApiResponse DELETETestResponse = await Util.DeleteAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull")); ApiResponse DELETETestResponse = await Util.DeleteAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204); Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void InvalidListKeyShouldFail() public async Task InvalidListKeyShouldFail()
{ {
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("Test DataListView"); d.name = Util.Uniquify("Test DataListView");
d["public"] = true; d["public"] = true;
d.listKey = "nonexistant"; d.listKey = "nonexistant";
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}] //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
// dynamic dfilter = new JArray(); // dynamic dfilter = new JArray();
// dynamic df = new JObject(); // dynamic df = new JObject();
// df.fld = "name"; // df.fld = "name";
// df.op = "%-"; // df.op = "%-";
// df.value = "Generic";//lots of seed widgets start with Generic // df.value = "Generic";//lots of seed widgets start with Generic
// dfilter.Add(df); // dfilter.Add(df);
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json // d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); // ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
dynamic dListView = new JArray(); dynamic dListView = new JArray();
// dynamic df = new JObject(); // dynamic df = new JObject();
// df.fld = "widgetname"; // df.fld = "widgetname";
// df.op = "%-"; // df.op = "%-";
// df.value = "Generic";//lots of seed widgets start with Generic // df.value = "Generic";//lots of seed widgets start with Generic
// dListView.Add(df); // dListView.Add(df);
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json // d.filter = dListView.ToString();//it expects it to be a json string, not actual json
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic")); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic"));
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None); d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "ListKey", "2203"); Util.ShouldContainValidationError(a, "ListKey", "2203");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void InvalidFieldNameShouldFail() public async Task InvalidFieldNameShouldFail()
{ {
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("Test DataListView"); d.name = Util.Uniquify("Test DataListView");
d["public"] = true; d["public"] = true;
d.listKey="TestWidgetDataList"; d.listKey="TestWidgetDataList";
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}] //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
// dynamic dfilter = new JArray(); // dynamic dfilter = new JArray();
// dynamic df = new JObject(); // dynamic df = new JObject();
// df.fld = "doesntexist"; // df.fld = "doesntexist";
// df.op = "%-"; // df.op = "%-";
// df.value = "Generic";//lots of seed widgets start with Generic // df.value = "Generic";//lots of seed widgets start with Generic
// dfilter.Add(df); // dfilter.Add(df);
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json // d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); // ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
dynamic dListView = new JArray(); dynamic dListView = new JArray();
// dynamic df = new JObject(); // dynamic df = new JObject();
// df.fld = "widgetname"; // df.fld = "widgetname";
// df.op = "%-"; // df.op = "%-";
// df.value = "Generic";//lots of seed widgets start with Generic // df.value = "Generic";//lots of seed widgets start with Generic
// dListView.Add(df); // dListView.Add(df);
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json // d.filter = dListView.ToString();//it expects it to be a json string, not actual json
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("doesntexist", Util.OpStartsWith, "Generic")); dListView.Add(Util.BuildSimpleFilterDataListViewColumn("doesntexist", Util.OpStartsWith, "Generic"));
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None); d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "ListView", "2203"); Util.ShouldContainValidationError(a, "ListView", "2203");
} }
//REMOVED THIS VALIDATION TEST AS SWITCH TO DATALISTVIEW NO LONGER VALIDATES FILTER ANYWAY //REMOVED THIS VALIDATION TEST AS SWITCH TO DATALISTVIEW NO LONGER VALIDATES FILTER ANYWAY
//ONLY COLUMN NAMES AND LIST NAME //ONLY COLUMN NAMES AND LIST NAME
// /// <summary> // /// <summary>
// /// // ///
// /// </summary> // /// </summary>
// [Fact] // [Fact]
// public async void InvalidOperatorShouldFail() // public async Task InvalidOperatorShouldFail()
// { // {
// //CREATE // //CREATE
// dynamic d = new JObject(); // dynamic d = new JObject();
// d.name = Util.Uniquify("Test DataListView"); // d.name = Util.Uniquify("Test DataListView");
// d["public"] = true; // d["public"] = true;
// d.listKey="TestWidgetDataList"; // d.listKey="TestWidgetDataList";
// //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}] // //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
// dynamic dfilter = new JArray(); // dynamic dfilter = new JArray();
// dynamic df = new JObject(); // dynamic df = new JObject();
// df.fld = "name"; // df.fld = "name";
// df.op = "wtf"; // df.op = "wtf";
// df.value = "Generic";//lots of seed widgets start with Generic // df.value = "Generic";//lots of seed widgets start with Generic
// dfilter.Add(df); // dfilter.Add(df);
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json // d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); // ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
// Util.ValidateErrorCodeResponse(a, 2200, 400); // Util.ValidateErrorCodeResponse(a, 2200, 400);
// Util.ShouldContainValidationError(a, "Filter", "2203"); // Util.ShouldContainValidationError(a, "Filter", "2203");
// } // }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,31 +1,31 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class Docs public class Docs
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void UserManualShouldFetch() public async Task UserManualShouldFetch()
{ {
ApiTextResponse t = await Util.GetNonApiPageAsync("docs/"); ApiTextResponse t = await Util.GetNonApiPageAsync("docs/");
Util.ValidateHTTPStatusCode(t, 200); Util.ValidateHTTPStatusCode(t, 200);
t.TextResponse.Should().Contain("<title>AyaNova manual</title>"); t.TextResponse.Should().Contain("<title>AyaNova manual</title>");
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,45 +1,45 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class EnumListOps public class EnumListOps
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetListOfEnumListsAndGetAllEnumListsWorks() public async Task GetListOfEnumListsAndGetAllEnumListsWorks()
{ {
ApiResponse a = await Util.GetAsync("enum-list/listkeys", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("enum-list/listkeys", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(2); ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(2);
//iterate all the list names and fetch each one in turn and see that it fetches ok and has at least 2 list items in it //iterate all the list names and fetch each one in turn and see that it fetches ok and has at least 2 list items in it
foreach (JObject jListName in a.ObjectResponse["data"]) foreach (JObject jListName in a.ObjectResponse["data"])
{ {
ApiResponse b = await Util.GetAsync($"enum-list/list/{jListName["key"].Value<string>()}", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse b = await Util.GetAsync($"enum-list/list/{jListName["key"].Value<string>()}", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(b); Util.ValidateDataReturnResponseOk(b);
Util.ValidateHTTPStatusCode(b, 200); Util.ValidateHTTPStatusCode(b, 200);
((JArray)b.ObjectResponse["data"]).Count.Should().BeGreaterThan(1); ((JArray)b.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);
} }
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,221 +1,221 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class EventLog public class EventLog
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void ObjectLogWorks() public async Task ObjectLogWorks()
{ {
//CRUD a widget and confirm it logs properly //CRUD a widget and confirm it logs properly
//http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1 //http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1
//http://localhost:7575/api/v8.0/event-log/objectlog?AyType=2&AyId=242 //http://localhost:7575/api/v8.0/event-log/objectlog?AyType=2&AyId=242
//http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24 //http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify("EventLog Test WIDGET"); w.name = Util.Uniquify("EventLog Test WIDGET");
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.created = DateTime.Now.ToString(); w.created = DateTime.Now.ToString();
w.dollarAmount = 2.22m; w.dollarAmount = 2.22m;
w.active = true; w.active = true;
w.usertype = 1; w.usertype = 1;
//*** CREATED //*** CREATED
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString()); ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
Util.ValidateDataReturnResponseOk(r2); Util.ValidateDataReturnResponseOk(r2);
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>(); long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
ApiResponse EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); ApiResponse EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(EventLogResponse, 200); Util.ValidateHTTPStatusCode(EventLogResponse, 200);
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);//only one event so far ((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);//only one event so far
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull(); EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(1);//AyEvent 1 = created EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(1);//AyEvent 1 = created
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty(); EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty();
//Get current user doing modifications ID //Get current user doing modifications ID
long CurrentUserId = EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Value<long>(); long CurrentUserId = EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Value<long>();
//*** RETRIEVED //*** RETRIEVED
//Get one //Get one
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull")); ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateDataReturnResponseOk(r3); Util.ValidateDataReturnResponseOk(r3);
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString()); r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString());
w = r3.ObjectResponse["data"]; w = r3.ObjectResponse["data"];
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(EventLogResponse, 200); Util.ValidateHTTPStatusCode(EventLogResponse, 200);
//confirm event count, type and sort order (descending by date most recent first) //confirm event count, type and sort order (descending by date most recent first)
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(2); ((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(2);
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull(); EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(2);//AyEvent 2 = retrieved EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(2);//AyEvent 2 = retrieved
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty(); EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty();
//*** MODIFIED //*** MODIFIED
//PUT //PUT
//update w2id //update w2id
w.name = Util.Uniquify("UPDATED VIA PUT EVENTLOG TEST WIDGET"); w.name = Util.Uniquify("UPDATED VIA PUT EVENTLOG TEST WIDGET");
w.UserId = 1; w.UserId = 1;
w.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>(); w.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200); Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//*** RETRIEVED //*** RETRIEVED
//check PUT worked //check PUT worked
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull")); ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateNoErrorInResponse(checkPUTWorked); Util.ValidateNoErrorInResponse(checkPUTWorked);
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString()); checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString());
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>(); uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(EventLogResponse, 200); Util.ValidateHTTPStatusCode(EventLogResponse, 200);
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(4); ((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(4);
//put op is the second item in the list, top item is the recent fetch //put op is the second item in the list, top item is the recent fetch
EventLogResponse.ObjectResponse["data"]["events"][1]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now EventLogResponse.ObjectResponse["data"]["events"][1]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
EventLogResponse.ObjectResponse["data"]["events"][1]["userId"].Should().NotBeNull(); EventLogResponse.ObjectResponse["data"]["events"][1]["userId"].Should().NotBeNull();
EventLogResponse.ObjectResponse["data"]["events"][1]["event"].Value<int>().Should().Be(3);//AyEvent 3 = Modified EventLogResponse.ObjectResponse["data"]["events"][1]["event"].Value<int>().Should().Be(3);//AyEvent 3 = Modified
EventLogResponse.ObjectResponse["data"]["events"][1]["textra"].Should().BeNullOrEmpty(); EventLogResponse.ObjectResponse["data"]["events"][1]["textra"].Should().BeNullOrEmpty();
//Check user log for basic accessibility userlog?UserId=7 //Check user log for basic accessibility userlog?UserId=7
EventLogResponse = await Util.GetAsync($"event-log/userlog?UserId={CurrentUserId}", await Util.GetTokenAsync("BizAdminFull")); EventLogResponse = await Util.GetAsync($"event-log/userlog?UserId={CurrentUserId}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(EventLogResponse, 200); Util.ValidateHTTPStatusCode(EventLogResponse, 200);
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().BeGreaterOrEqualTo(4);//just one run of the above will be 4 events plus any others from other tests ((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().BeGreaterOrEqualTo(4);//just one run of the above will be 4 events plus any others from other tests
//Not sure of any easy way to assert the User log is correct other than the count as other tests running concurrently could easily skew this //Not sure of any easy way to assert the User log is correct other than the count as other tests running concurrently could easily skew this
//DELETE //DELETE
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull")); ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204); Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
//All events should be cleared up on deletion with the sole exception of the deleted event //All events should be cleared up on deletion with the sole exception of the deleted event
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull")); EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(EventLogResponse, 200); Util.ValidateHTTPStatusCode(EventLogResponse, 200);
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1); ((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull(); EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(0);//AyEvent 0 = deleted EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(0);//AyEvent 0 = deleted
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Value<string>().Should().Be(w.name.ToString()); EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Value<string>().Should().Be(w.name.ToString());
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void UserLogWorks() public async Task UserLogWorks()
{ {
//get admin log, sb lots of shit //get admin log, sb lots of shit
ApiResponse a = await Util.GetAsync($"event-log/userlog?UserId=1&Offset=0&Limit=999", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync($"event-log/userlog?UserId=1&Offset=0&Limit=999", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().BeGreaterThan(90); ((JArray)a.ObjectResponse["data"]["events"]).Count.Should().BeGreaterThan(90);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void EventLogLimitOffSetWorks() public async Task EventLogLimitOffSetWorks()
{ {
var UniqueName = Util.Uniquify("EventLogLimitOffSetWorks"); var UniqueName = Util.Uniquify("EventLogLimitOffSetWorks");
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = UniqueName; d.name = UniqueName;
d.active = true; d.active = true;
d.login = UniqueName; d.login = UniqueName;
d.password = UniqueName; d.password = UniqueName;
d.roles = 2;//bizadminfull needs widget rights d.roles = 2;//bizadminfull needs widget rights
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
//Required by form custom rules //Required by form custom rules
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long UserId = a.ObjectResponse["data"]["id"].Value<long>(); long UserId = a.ObjectResponse["data"]["id"].Value<long>();
//Loop and make 10 widgets //Loop and make 10 widgets
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
d = new JObject(); d = new JObject();
d.name = Util.Uniquify("EventLogLimitOffSetWorks"); d.name = Util.Uniquify("EventLogLimitOffSetWorks");
d.customFields = Util.WidgetRequiredCustomFieldsJsonString(); d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
d.notes = "note here"; d.notes = "note here";
a = await Util.PostAsync("widget", await Util.GetTokenAsync(UniqueName, UniqueName), d.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync(UniqueName, UniqueName), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
} }
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=9", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=9", await Util.GetTokenAsync("BizAdminFull"));
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(9); ((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(9);
//capture events, then compare to paged ones //capture events, then compare to paged ones
var eventList = ((JArray)a.ObjectResponse["data"]["events"]); var eventList = ((JArray)a.ObjectResponse["data"]["events"]);
List<string> allEvents = new List<string>(9); List<string> allEvents = new List<string>(9);
foreach (JObject o in eventList) foreach (JObject o in eventList)
{ {
allEvents.Add(o["date"].Value<string>() + o["objectType"].Value<string>() allEvents.Add(o["date"].Value<string>() + o["objectType"].Value<string>()
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>() + o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
); );
} }
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=3", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3); ((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
var pageEventList = ((JArray)a.ObjectResponse["data"]["events"]); var pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
foreach (JObject o in pageEventList) foreach (JObject o in pageEventList)
{ {
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>() allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>() + o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
); );
} }
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=1&Limit=3", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=1&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3); ((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
pageEventList = ((JArray)a.ObjectResponse["data"]["events"]); pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
foreach (JObject o in pageEventList) foreach (JObject o in pageEventList)
{ {
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>() allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>() + o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
); );
} }
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=2&Limit=3", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=2&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3); ((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
pageEventList = ((JArray)a.ObjectResponse["data"]["events"]); pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
foreach (JObject o in pageEventList) foreach (JObject o in pageEventList)
{ {
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>() allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>() + o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
); );
} }
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,241 +1,241 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class FormCustom public class FormCustom
{ {
public enum AyaUiFieldDataType : int public enum AyaUiFieldDataType : int
{ {
NoType = 0, NoType = 0,
DateTime = 1, DateTime = 1,
Date = 2, Date = 2,
Time = 3, Time = 3,
Text = 4, Text = 4,
Integer = 5, Integer = 5,
Bool = 6, Bool = 6,
Decimal = 7, Decimal = 7,
Currency = 8, Currency = 8,
Tags = 9, Tags = 9,
Enum = 10, Enum = 10,
EmailAddress = 11 EmailAddress = 11
} }
/// <summary> /// <summary>
/// Test create or update /// Test create or update
/// </summary> /// </summary>
[Fact] [Fact]
public async void FormCustomUpdate() public async Task FormCustomUpdate()
{ {
//This is a special case, you can PUT a formcustom, but you can't delete one and you can't create one //This is a special case, you can PUT a formcustom, but you can't delete one and you can't create one
/* /*
*/ */
dynamic d = new JObject(); dynamic d = new JObject();
d.formkey = "User"; d.formkey = "User";
dynamic dtemplate = new JArray(); dynamic dtemplate = new JArray();
dynamic dt = new JObject(); dynamic dt = new JObject();
dt.fld = "UserCustom1"; dt.fld = "UserCustom1";
dt.hide = false; dt.hide = false;
dt.required = true; dt.required = true;
dt.type = AyaUiFieldDataType.Text; dt.type = AyaUiFieldDataType.Text;
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "Notes"; dt.fld = "Notes";
dt.required = true; dt.required = true;
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "UserCustom2"; dt.fld = "UserCustom2";
dt.hide = true; dt.hide = true;
dt.required = false; dt.required = false;
dt.type = AyaUiFieldDataType.Bool; dt.type = AyaUiFieldDataType.Bool;
dtemplate.Add(dt); dtemplate.Add(dt);
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
//RETRIEVE //RETRIEVE
//Get the current one (server will create if non-existent) //Get the current one (server will create if non-existent)
ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"));
//Update //Update
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>(); d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//check the concurrency token cache scheme //check the concurrency token cache scheme
uint token = a.ObjectResponse["data"]["concurrency"].Value<uint>(); uint token = a.ObjectResponse["data"]["concurrency"].Value<uint>();
//This should return a 304 not modified //This should return a 304 not modified
a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(a, 304); Util.ValidateHTTPStatusCode(a, 304);
//and this should return the whole object //and this should return the whole object
token--;//make the token not match token--;//make the token not match
//This should return a 200 and the whole object //This should return a 200 and the whole object
a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
} }
/// <summary> /// <summary>
/// Ensure validation works in FormCustombiz /// Ensure validation works in FormCustombiz
/// </summary> /// </summary>
[Fact] [Fact]
public async void ValidatesProperly() public async Task ValidatesProperly()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.formkey = "User"; d.formkey = "User";
dynamic dtemplate = new JArray(); dynamic dtemplate = new JArray();
dynamic dt = new JObject(); dynamic dt = new JObject();
dt.fld = string.Empty;//expected ApiErrorCode.VALIDATION_REQUIRED Missing key 2 errors 2201 and 2203 dt.fld = string.Empty;//expected ApiErrorCode.VALIDATION_REQUIRED Missing key 2 errors 2201 and 2203
dt.hide = false; dt.hide = false;
dt.required = true; dt.required = true;
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "ThisFieldKeyDoesNotExist";//expected ApiErrorCode.VALIDATION_INVALID_VALUE Bad key dt.fld = "ThisFieldKeyDoesNotExist";//expected ApiErrorCode.VALIDATION_INVALID_VALUE Bad key
dt.required = true; dt.required = true;
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "Name";//expect ApiErrorCode.VALIDATION_INVALID_VALUE required field not hideable dt.fld = "Name";//expect ApiErrorCode.VALIDATION_INVALID_VALUE required field not hideable
dt.hide = true; dt.hide = true;
dt.required = true; dt.required = true;
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "UserCustom1";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field dt.fld = "UserCustom1";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
dt.hide = false; dt.hide = false;
dt.required = false; dt.required = false;
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "EmployeeNumber";//expect ApiErrorCode.VALIDATION_INVALID_VALUE not custom field but type specified anyway dt.fld = "EmployeeNumber";//expect ApiErrorCode.VALIDATION_INVALID_VALUE not custom field but type specified anyway
dt.hide = true; dt.hide = true;
dt.required = false; dt.required = false;
dt.type = AyaUiFieldDataType.EmailAddress;//type specified (doesn't matter what type) dt.type = AyaUiFieldDataType.EmailAddress;//type specified (doesn't matter what type)
dtemplate.Add(dt); dtemplate.Add(dt);
dt = new JObject(); dt = new JObject();
dt.fld = "UserCustom2";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field dt.fld = "UserCustom2";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
dt.hide = false; dt.hide = false;
dt.required = false; dt.required = false;
dtemplate.Add(dt); dtemplate.Add(dt);
dt.type = 999;//not a valid type dt.type = 999;//not a valid type
dt = new JObject(); dt = new JObject();
dt.fld = "Notes";//expect ApiErrorCode.VALIDATION_REQUIRED required property is always required (no idea why, just designed that way and that's the rule) dt.fld = "Notes";//expect ApiErrorCode.VALIDATION_REQUIRED required property is always required (no idea why, just designed that way and that's the rule)
dt.hide = true; dt.hide = true;
// dt.required = false; Deliberately not set // dt.required = false; Deliberately not set
dtemplate.Add(dt); dtemplate.Add(dt);
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
//RETRIEVE //RETRIEVE
//Get the current one (server will create if non-existent) //Get the current one (server will create if non-existent)
ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"));
//Update //Update
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>(); d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
Util.ValidateHTTPStatusCode(a, 400); Util.ValidateHTTPStatusCode(a, 400);
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 0, \"fld\" property exists but is empty, a value is required"); Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 0, \"fld\" property exists but is empty, a value is required");
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 0, fld property value \"\" is not a valid form field value for formKey specified"); Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 0, fld property value \"\" is not a valid form field value for formKey specified");
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 1, fld property value \"ThisFieldKeyDoesNotExist\" is not a valid form field value for formKey specified"); Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 1, fld property value \"ThisFieldKeyDoesNotExist\" is not a valid form field value for formKey specified");
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 2 (\"Name\"), \"hide\" property value of \"True\" is not valid, this field is core and cannot be hidden"); Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 2 (\"Name\"), \"hide\" property value of \"True\" is not valid, this field is core and cannot be hidden");
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 3 (\"UserCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified"); Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 3 (\"UserCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified");
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 4 (\"EmployeeNumber\"), \"type\" property value is not valid, only Custom fields can have types specified"); Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 4 (\"EmployeeNumber\"), \"type\" property value is not valid, only Custom fields can have types specified");
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 5 (\"UserCustom2\"), \"type\" property value of \"999\" is not a valid custom field type"); Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 5 (\"UserCustom2\"), \"type\" property value of \"999\" is not a valid custom field type");
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 6, object is missing \"required\" property. All items must contain this property."); Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 6, object is missing \"required\" property. All items must contain this property.");
/* /*
"{\"error\":{\"code\":\"2200\",\"details\":[ "{\"error\":{\"code\":\"2200\",\"details\":[
{\"message\":\"Template array item 0, \\\"fld\\\" property exists but is empty, a value is required\",\"target\":\"Template\",\"error\":\"2201\"}, {\"message\":\"Template array item 0, \\\"fld\\\" property exists but is empty, a value is required\",\"target\":\"Template\",\"error\":\"2201\"},
{\"message\":\"Template array item 0, fld property value \\\"\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"}, {\"message\":\"Template array item 0, fld property value \\\"\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"},
{\"message\":\"Template array item 1, fld property value \\\"ThisFieldKeyDoesNotExist\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"}, {\"message\":\"Template array item 1, fld property value \\\"ThisFieldKeyDoesNotExist\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"},
{\"message\":\"Template array item 2 (\\\"Name\\\"), \\\"hide\\\" property value of \\\"True\\\" is not valid, this field is core and cannot be hidden\",\"target\":\"Template\",\"error\":\"2203\"}, {\"message\":\"Template array item 2 (\\\"Name\\\"), \\\"hide\\\" property value of \\\"True\\\" is not valid, this field is core and cannot be hidden\",\"target\":\"Template\",\"error\":\"2203\"},
{\"message\":\"Template array item 3 (\\\"UserCustom1\\\"), \\\"type\\\" property value is MISSING for custom filed, Custom fields MUST have types specified\",\"target\":\"Template\",\"error\":\"2203\"}, {\"message\":\"Template array item 3 (\\\"UserCustom1\\\"), \\\"type\\\" property value is MISSING for custom filed, Custom fields MUST have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
{\"message\":\"Template array item 4 (\\\"EmployeeNumber\\\"), \\\"type\\\" property value is not valid, only Custom fields can have types specified\",\"target\":\"Template\",\"error\":\"2203\"}, {\"message\":\"Template array item 4 (\\\"EmployeeNumber\\\"), \\\"type\\\" property value is not valid, only Custom fields can have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
{\"message\":\"Template array item 5 (\\\"UserCustom2\\\"), \\\"type\\\" property value of \\\"999\\\" is not a valid custom field type\",\"target\":\"Template\",\"error\":\"2203\"}, {\"message\":\"Template array item 5 (\\\"UserCustom2\\\"), \\\"type\\\" property value of \\\"999\\\" is not a valid custom field type\",\"target\":\"Template\",\"error\":\"2203\"},
{\"message\":\"Template array item 6, object is missing \\\"required\\\" property. All items must contain this property. \",\"target\":\"Template\",\"error\":\"2201\"} {\"message\":\"Template array item 6, object is missing \\\"required\\\" property. All items must contain this property. \",\"target\":\"Template\",\"error\":\"2201\"}
],\"message\":\"Object did not pass validation\"}}" ],\"message\":\"Object did not pass validation\"}}"
*/ */
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void InvalidObjectFieldsFormKeyShouldFail() public async Task InvalidObjectFieldsFormKeyShouldFail()
{ {
ApiResponse a = await Util.GetAsync("form-field-definition/nonexistent", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("form-field-definition/nonexistent", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateErrorCodeResponse(a, 2010, 404); Util.ValidateErrorCodeResponse(a, 2010, 404);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void ObjectFieldsWorks() public async Task ObjectFieldsWorks()
{ {
ApiResponse a = await Util.GetAsync("form-field-definition/Widget", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("form-field-definition/Widget", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(25); ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(25);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void AvailableCustomizableFormKeysWorks() public async Task AvailableCustomizableFormKeysWorks()
{ {
ApiResponse a = await Util.GetAsync("form-custom/availablecustomizableformkeys", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("form-custom/availablecustomizableformkeys", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);//is 2 as of writing (widget,user) ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);//is 2 as of writing (widget,user)
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void AvailableCustomTypesWorks() public async Task AvailableCustomTypesWorks()
{ {
ApiResponse a = await Util.GetAsync("form-custom/availablecustomtypes", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("form-custom/availablecustomtypes", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(4); ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(4);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,29 +1,29 @@
using Xunit; using Xunit;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class GlobalAll public class GlobalAll
{ {
/// <summary> /// <summary>
/// Test Global routes /// Test Global routes
/// </summary> /// </summary>
[Fact] [Fact]
public async void GlobalOps() public async Task GlobalOps()
{ {
//excercise the fetch and update routes but no actual changes because making a change of any kind to global will likely break other tests //excercise the fetch and update routes but no actual changes because making a change of any kind to global will likely break other tests
//and we just need to see the routes are active really //and we just need to see the routes are active really
ApiResponse a = await Util.GetAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
a.ObjectResponse["data"]["searchCaseSensitiveOnly"].Should().NotBeNull(); a.ObjectResponse["data"]["searchCaseSensitiveOnly"].Should().NotBeNull();
var g = a.ObjectResponse["data"]; var g = a.ObjectResponse["data"];
a = await Util.PutAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"), g.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PutAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"), g.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,28 +1,28 @@
using Xunit; using Xunit;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class LogFiles public class LogFiles
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void MostRecentLogShouldFetch() public async Task MostRecentLogShouldFetch()
{ {
ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("OpsAdminFull")); ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("OpsAdminFull"));
Util.ValidateHTTPStatusCode(t, 200); Util.ValidateHTTPStatusCode(t, 200);
string[] ExpectedLogItems = {"|INFO|","|ERROR|","|FATAL|", "|WARN|"};//assumes any log will have at least one of these items in it string[] ExpectedLogItems = {"|INFO|","|ERROR|","|FATAL|", "|WARN|"};//assumes any log will have at least one of these items in it
t.TextResponse.Should().ContainAny(ExpectedLogItems); t.TextResponse.Should().ContainAny(ExpectedLogItems);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,63 +1,63 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class Metrics public class Metrics
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void MetricsShouldFetch() public async Task MetricsShouldFetch()
{ {
// DateTime tsEnd = DateTime.Now.ToOffsetAdjustedUniversalTime();//{2020-05-29 3:30:21 PM} // DateTime tsEnd = DateTime.Now.ToOffsetAdjustedUniversalTime();//{2020-05-29 3:30:21 PM}
// DateTime tsStart = DateTime.Now.AddHours(-6).ToOffsetAdjustedUniversalTime();//{2020-05-29 9:30:21 AM} // DateTime tsStart = DateTime.Now.AddHours(-6).ToOffsetAdjustedUniversalTime();//{2020-05-29 9:30:21 AM}
// DateTime tsEnd = DateTime.UtcNow;//{2020-05-29 3:32:54 PM} // DateTime tsEnd = DateTime.UtcNow;//{2020-05-29 3:32:54 PM}
// DateTime tsStart = DateTime.UtcNow.AddHours(-6); //{2020-05-29 9:32:54 AM} // DateTime tsStart = DateTime.UtcNow.AddHours(-6); //{2020-05-29 9:32:54 AM}
//weirdly, this is the only way to get the correct date range //weirdly, this is the only way to get the correct date range
//just as the html client does but from here //just as the html client does but from here
//in both cases the server shows parameters as local time to the server //in both cases the server shows parameters as local time to the server
//and in the route I have to adjust them back to universal time before sending them to the db query //and in the route I have to adjust them back to universal time before sending them to the db query
//as the db data is in utc and the db server doesn't know what timezone it is //as the db data is in utc and the db server doesn't know what timezone it is
DateTime tsEnd = DateTime.Now;//{2020-05-29 8:36:48 AM} DateTime tsEnd = DateTime.Now;//{2020-05-29 8:36:48 AM}
DateTime tsStart = DateTime.Now.AddHours(-6); //{2020-05-29 2:36:48 AM} DateTime tsStart = DateTime.Now.AddHours(-6); //{2020-05-29 2:36:48 AM}
//http://localhost:7575/api/v8.0/server-metric/mm?maxRecords=200&tsStart=2020-05-29T09:23:18.114Z&tsEnd=2020-05-29T15:23:19.114Z //http://localhost:7575/api/v8.0/server-metric/mm?maxRecords=200&tsStart=2020-05-29T09:23:18.114Z&tsEnd=2020-05-29T15:23:19.114Z
//from client at server route {2020-05-29 2:29:25 AM} {2020-05-29 8:29:26 AM} //from client at server route {2020-05-29 2:29:25 AM} {2020-05-29 8:29:26 AM}
ApiResponse a = await Util.GetAsync($"server-metric/memcpu?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull")); ApiResponse a = await Util.GetAsync($"server-metric/memcpu?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see
a = await Util.GetAsync($"server-metric/storage?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull")); a = await Util.GetAsync($"server-metric/storage?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,466 +1,466 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class PickListAllTests public class PickListAllTests
{ {
//NOTE: in order not to interfere in each other will use Widget picklist to test with standard unmodified picklist template //NOTE: in order not to interfere in each other will use Widget picklist to test with standard unmodified picklist template
//and will use User pick-list to test the template functionality //and will use User pick-list to test the template functionality
/// <summary> /// <summary>
/// Test all Template editing related routes /// Test all Template editing related routes
/// </summary> /// </summary>
[Fact] [Fact]
public async void UserPickListTemplatesOps() public async Task UserPickListTemplatesOps()
{ {
//NOTE: Due to there being only one possible template per type, this test will need to test ALL potential tests in one function //NOTE: Due to there being only one possible template per type, this test will need to test ALL potential tests in one function
//and only for the User picklist in order to not step over other potential tests running in parallel //and only for the User picklist in order to not step over other potential tests running in parallel
//REPLACE USER TEMPLATE //REPLACE USER TEMPLATE
dynamic d = new JObject(); dynamic d = new JObject();
d.Id = 3;//User type d.Id = 3;//User type
//custom template, only one field employee number //custom template, only one field employee number
dynamic dTemplateArray = new JArray(); dynamic dTemplateArray = new JArray();
dynamic df = new JObject(); dynamic df = new JObject();
df.fld = "useremployeenumber"; df.fld = "useremployeenumber";
dTemplateArray.Add(df); dTemplateArray.Add(df);
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None); d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
//replace the User template at the server //replace the User template at the server
ApiResponse a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); ApiResponse a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
//RETRIEVE //RETRIEVE
//Get one //Get one
a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//assert contains ONE record ONLY and it's the one we set //assert contains ONE record ONLY and it's the one we set
var templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>()); var templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
templateArray.Count.Should().Be(1); templateArray.Count.Should().Be(1);
templateArray[0]["fld"].Value<string>().Should().Be("useremployeenumber"); templateArray[0]["fld"].Value<string>().Should().Be("useremployeenumber");
//CONFIRM THE CUSTOM PICKLIST TEMPLATE WORKS PROPERLY //CONFIRM THE CUSTOM PICKLIST TEMPLATE WORKS PROPERLY
//MAKE THE TEST USERS //MAKE THE TEST USERS
//First make a unique string for this iteration of this test only //First make a unique string for this iteration of this test only
var UniquePhrase = Util.Uniquify("pick").Replace(" ", ""); var UniquePhrase = Util.Uniquify("pick").Replace(" ", "");
d = new JObject(); d = new JObject();
d.name = Util.Uniquify("UserPickListTemplatesOps") + UniquePhrase; d.name = Util.Uniquify("UserPickListTemplatesOps") + UniquePhrase;
d.active = true; d.active = true;
d.login = Util.Uniquify("LOGIN"); d.login = Util.Uniquify("LOGIN");
d.password = Util.Uniquify("PASSWORD"); d.password = Util.Uniquify("PASSWORD");
d.roles = 0;//norole d.roles = 0;//norole
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
//Required by form custom rules //Required by form custom rules
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long InNameId = a.ObjectResponse["data"]["id"].Value<long>(); long InNameId = a.ObjectResponse["data"]["id"].Value<long>();
d = new JObject(); d = new JObject();
d.name = Util.Uniquify("UserPickListTemplatesOps"); d.name = Util.Uniquify("UserPickListTemplatesOps");
d.employeeNumber = UniquePhrase; d.employeeNumber = UniquePhrase;
d.login = Util.Uniquify("LOGIN"); d.login = Util.Uniquify("LOGIN");
d.password = Util.Uniquify("PASSWORD"); d.password = Util.Uniquify("PASSWORD");
d.roles = 0;//norole d.roles = 0;//norole
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
d.active = true; d.active = true;
//Required by form custom rules //Required by form custom rules
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long InEmployeeNumberId = a.ObjectResponse["data"]["id"].Value<long>(); long InEmployeeNumberId = a.ObjectResponse["data"]["id"].Value<long>();
//GET PICKLIST FOR unique phrase query sb only employee number due to custom template //GET PICKLIST FOR unique phrase query sb only employee number due to custom template
a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
var pickList = ((JArray)a.ObjectResponse["data"]); var pickList = ((JArray)a.ObjectResponse["data"]);
pickList.Count.Should().Be(1); pickList.Count.Should().Be(1);
pickList[0]["id"].Value<long>().Should().Be(InEmployeeNumberId); pickList[0]["id"].Value<long>().Should().Be(InEmployeeNumberId);
//custom template, only one field user name //custom template, only one field user name
d = new JObject(); d = new JObject();
d.Id = 3;//User type d.Id = 3;//User type
dTemplateArray = new JArray(); dTemplateArray = new JArray();
df = new JObject(); df = new JObject();
df.fld = "username"; df.fld = "username";
dTemplateArray.Add(df); dTemplateArray.Add(df);
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None); d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
//replace the User template at the server //replace the User template at the server
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
//GET PICKLIST FOR unique phrase query sb only user name field due to custom template //GET PICKLIST FOR unique phrase query sb only user name field due to custom template
a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
//"select auser.id as plId, auser.active as plActive, concat_ws(' ', auser.name) as plname from auser where auser.active = true and ((auser.name like '%pick1584556347748%')) order by auser.name limit 100" //"select auser.id as plId, auser.active as plActive, concat_ws(' ', auser.name) as plname from auser where auser.active = true and ((auser.name like '%pick1584556347748%')) order by auser.name limit 100"
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
pickList = ((JArray)a.ObjectResponse["data"]); pickList = ((JArray)a.ObjectResponse["data"]);
pickList.Count.Should().Be(1); pickList.Count.Should().Be(1);
pickList[0]["id"].Value<long>().Should().Be(InNameId); pickList[0]["id"].Value<long>().Should().Be(InNameId);
//DELETE TEST USERS NO LONGER NEEDED //DELETE TEST USERS NO LONGER NEEDED
a = await Util.DeleteAsync("User/" + InNameId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("User/" + InNameId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
a = await Util.DeleteAsync("User/" + InEmployeeNumberId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.DeleteAsync("User/" + InEmployeeNumberId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
// RESET TEMPLATE TO DEFAULT // RESET TEMPLATE TO DEFAULT
a = await Util.DeleteAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull")); a = await Util.DeleteAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
//RETRIEVE (Confirm it's back to default) //RETRIEVE (Confirm it's back to default)
//Get one //Get one
a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//assert contains default template record ONLY and it's the one we set //assert contains default template record ONLY and it's the one we set
templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>()); templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
templateArray.Count.Should().Be(3); templateArray.Count.Should().Be(3);
templateArray[0]["fld"].Value<string>().Should().Be("username"); templateArray[0]["fld"].Value<string>().Should().Be("username");
//Now test error conditions.... //Now test error conditions....
//BAD FIELD NAME VALIDATION ERROR //BAD FIELD NAME VALIDATION ERROR
d = new JObject(); d = new JObject();
d.Id = 3;//User type d.Id = 3;//User type
//template, simple test, nothing fancy //template, simple test, nothing fancy
dTemplateArray = new JArray(); dTemplateArray = new JArray();
df = new JObject(); df = new JObject();
df.fld = "DOES_NOT_EXIST";//<-- ERROR BAD FIELD NAME df.fld = "DOES_NOT_EXIST";//<-- ERROR BAD FIELD NAME
dTemplateArray.Add(df); dTemplateArray.Add(df);
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None); d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}" //"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Template", "2203"); Util.ShouldContainValidationError(a, "Template", "2203");
//BAD AYATYPE ERROR //BAD AYATYPE ERROR
d = new JObject(); d = new JObject();
d.Id = 0;//<==ERROR NO_TYPE, INVALID d.Id = 0;//<==ERROR NO_TYPE, INVALID
//template, simple test, nothing fancy //template, simple test, nothing fancy
dTemplateArray = new JArray(); dTemplateArray = new JArray();
df = new JObject(); df = new JObject();
df.fld = "useremployeenumber"; df.fld = "useremployeenumber";
dTemplateArray.Add(df); dTemplateArray.Add(df);
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None); d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
//replace the User template at the server //replace the User template at the server
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}" //"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "ayaType", "2203"); Util.ShouldContainValidationError(a, "ayaType", "2203");
//RIGHTS ISSUE, //RIGHTS ISSUE,
//currently only bizadminfull can change a picklist template //currently only bizadminfull can change a picklist template
d = new JObject(); d = new JObject();
d.Id = 3;//User d.Id = 3;//User
//template, simple test, nothing fancy //template, simple test, nothing fancy
dTemplateArray = new JArray(); dTemplateArray = new JArray();
df = new JObject(); df = new JObject();
df.fld = "useremployeenumber"; df.fld = "useremployeenumber";
dTemplateArray.Add(df); dTemplateArray.Add(df);
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None); d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
//ERROR NO RIGHTS USER //ERROR NO RIGHTS USER
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("CustomerLimited"), d.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("CustomerLimited"), d.ToString(Newtonsoft.Json.Formatting.None));
//"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}" //"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
Util.ValidateErrorCodeResponse(a, 2004, 403); Util.ValidateErrorCodeResponse(a, 2004, 403);
//EMPTY TEMPLATE VALIDATION ERROR //EMPTY TEMPLATE VALIDATION ERROR
d = new JObject(); d = new JObject();
d.Id = 3;//User d.Id = 3;//User
d.Template = "";//<-- ERROR no template d.Template = "";//<-- ERROR no template
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Template", "2201"); Util.ShouldContainValidationError(a, "Template", "2201");
//MALFORMED TEMPLATE JSON ERROR //MALFORMED TEMPLATE JSON ERROR
d = new JObject(); d = new JObject();
d.Id = 3;//User type d.Id = 3;//User type
dTemplateArray = new JArray(); dTemplateArray = new JArray();
df = new JObject(); df = new JObject();
df.fld = "useremployeenumber"; df.fld = "useremployeenumber";
dTemplateArray.Add(df); dTemplateArray.Add(df);
string sTemplate = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None); string sTemplate = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
d.Template = sTemplate.Substring(2);//<-- ERROR missing first two characters of json template array d.Template = sTemplate.Substring(2);//<-- ERROR missing first two characters of json template array
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None)); a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template is not valid JSON string: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path '', line 1, position 5.\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}" //"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template is not valid JSON string: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path '', line 1, position 5.\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Template", "2203"); Util.ShouldContainValidationError(a, "Template", "2203");
} }
/// <summary> /// <summary>
/// test get templates list /// test get templates list
/// </summary> /// </summary>
[Fact] [Fact]
public async void PickListTemplateList() public async Task PickListTemplateList()
{ {
//RETRIEVE //RETRIEVE
ApiResponse a = await Util.GetAsync("pick-list/template/list", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("pick-list/template/list", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//assert contains at least two records (as we only have two at time of writing this test) //assert contains at least two records (as we only have two at time of writing this test)
var templateList = ((JArray)a.ObjectResponse["data"]); var templateList = ((JArray)a.ObjectResponse["data"]);
templateList.Count.Should().BeGreaterThan(1); templateList.Count.Should().BeGreaterThan(1);
templateList[0]["id"].Value<long>().Should().Be(2);//first one should be a widget templateList[0]["id"].Value<long>().Should().Be(2);//first one should be a widget
} }
/// <summary> /// <summary>
/// test get picklist fields list for widget template /// test get picklist fields list for widget template
/// </summary> /// </summary>
[Fact] [Fact]
public async void WidgetPickListTemplateFieldList() public async Task WidgetPickListTemplateFieldList()
{ {
//RETRIEVE WIDGET PICKLIST FIELDS //RETRIEVE WIDGET PICKLIST FIELDS
ApiResponse a = await Util.GetAsync("pick-list/template/ListFields/2", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("pick-list/template/ListFields/2", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//assert contains at least two records (as we only have two at time of writing this test) //assert contains at least two records (as we only have two at time of writing this test)
var templateList = ((JArray)a.ObjectResponse["data"]); var templateList = ((JArray)a.ObjectResponse["data"]);
templateList.Count.Should().BeGreaterThan(4); templateList.Count.Should().BeGreaterThan(4);
templateList[0]["fieldKey"].Value<string>().Should().Be("widgetactive");//first one should be a widgetactive field templateList[0]["fieldKey"].Value<string>().Should().Be("widgetactive");//first one should be a widgetactive field
} }
/// <summary> /// <summary>
/// test get picklist for widget without query /// test get picklist for widget without query
/// </summary> /// </summary>
[Fact] [Fact]
public async void FetchWidgetPickListNoQuery() public async Task FetchWidgetPickListNoQuery()
{ {
//RETRIEVE WIDGET PICKLIST no filter //RETRIEVE WIDGET PICKLIST no filter
ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=2", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=2", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//assert contains 100 records (current picklist maximum count) //assert contains 100 records (current picklist maximum count)
var pickList = ((JArray)a.ObjectResponse["data"]); var pickList = ((JArray)a.ObjectResponse["data"]);
pickList.Count.Should().Be(100); pickList.Count.Should().Be(100);
} }
/// <summary> /// <summary>
/// test get picklist for single predefined value only /// test get picklist for single predefined value only
/// </summary> /// </summary>
[Fact] [Fact]
public async void FetchWidgetPickListPreDefined() public async Task FetchWidgetPickListPreDefined()
{ {
//fetch the SuperUser account which always exists //fetch the SuperUser account which always exists
ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=3&preId=1", await Util.GetTokenAsync("BizAdminFull")); ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=3&preId=1", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//assert contains 1 record //assert contains 1 record
var pickList = ((JArray)a.ObjectResponse["data"]); var pickList = ((JArray)a.ObjectResponse["data"]);
pickList.Count.Should().Be(1); pickList.Count.Should().Be(1);
pickList[0]["id"].Value<long>().Should().Be(1); pickList[0]["id"].Value<long>().Should().Be(1);
} }
/// <summary> /// <summary>
/// test get picklist for widget with basic autocomplete query only /// test get picklist for widget with basic autocomplete query only
/// </summary> /// </summary>
[Fact] [Fact]
public async void FetchWidgetPickListAutoComplete() public async Task FetchWidgetPickListAutoComplete()
{ {
//make key widget //make key widget
var WidgetNameStart = "FetchWidgetPickListAutoComplete_a1b2c3"; var WidgetNameStart = "FetchWidgetPickListAutoComplete_a1b2c3";
long IncludedWidgetId = 0; long IncludedWidgetId = 0;
//CREATE TEST WIDGETS //CREATE TEST WIDGETS
//included widget //included widget
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.active = true; w.active = true;
w.usertype = 1; w.usertype = 1;
w.dollarAmount = 555.55; w.dollarAmount = 555.55;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
//RETRIEVE WIDGET PICKLIST with name filter //RETRIEVE WIDGET PICKLIST with name filter
a = await Util.GetAsync("pick-list/list?ayaType=2&query=a1b2c3", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/list?ayaType=2&query=a1b2c3", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
var pickList = ((JArray)a.ObjectResponse["data"]); var pickList = ((JArray)a.ObjectResponse["data"]);
pickList.Count.Should().BeGreaterThan(0); pickList.Count.Should().BeGreaterThan(0);
pickList[0]["name"].Value<string>().Should().Contain("_a1b2c3"); pickList[0]["name"].Value<string>().Should().Contain("_a1b2c3");
//DELETE WIDGETS //DELETE WIDGETS
a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull")); a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void FetchWidgetPickListTags() public async Task FetchWidgetPickListTags()
{ {
//make key widget //make key widget
var WidgetNameStart = "FetchWidgetPickListTags"; var WidgetNameStart = "FetchWidgetPickListTags";
long IncludedWidgetId = 0; long IncludedWidgetId = 0;
//CREATE TEST WIDGETS //CREATE TEST WIDGETS
//included widget //included widget
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.active = true; w.active = true;
w.usertype = 1; w.usertype = 1;
w.dollarAmount = 555.55; w.dollarAmount = 555.55;
//Tags //Tags
dynamic InclusiveTagsArray = new JArray(); dynamic InclusiveTagsArray = new JArray();
InclusiveTagsArray.Add("plred"); InclusiveTagsArray.Add("plred");
InclusiveTagsArray.Add("plblue"); InclusiveTagsArray.Add("plblue");
w.tags = InclusiveTagsArray; w.tags = InclusiveTagsArray;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>(); IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
//RETRIEVE WIDGET PICKLIST with name filter //RETRIEVE WIDGET PICKLIST with name filter
a = await Util.GetAsync("pick-list/list?ayaType=2&query=..lblu", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/list?ayaType=2&query=..lblu", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
var pickList = ((JArray)a.ObjectResponse["data"]); var pickList = ((JArray)a.ObjectResponse["data"]);
pickList.Count.Should().Be(1); pickList.Count.Should().Be(1);
pickList[0]["id"].Value<long>().Should().Be(IncludedWidgetId); pickList[0]["id"].Value<long>().Should().Be(IncludedWidgetId);
//DELETE WIDGETS //DELETE WIDGETS
a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull")); a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
/// <summary> /// <summary>
/// test get picklist for widget with basic autocomplete query only /// test get picklist for widget with basic autocomplete query only
/// </summary> /// </summary>
[Fact] [Fact]
public async void FetchWidgetPickListInactiveActive() public async Task FetchWidgetPickListInactiveActive()
{ {
//make key widget //make key widget
var WidgetNameStart = "FetchWidgetPickListInactiveActive"; var WidgetNameStart = "FetchWidgetPickListInactiveActive";
List<long> ActiveWidgetIdList = new List<long>(); List<long> ActiveWidgetIdList = new List<long>();
List<long> NotActiveWidgetIdList = new List<long>(); List<long> NotActiveWidgetIdList = new List<long>();
//CREATE 4 TEST WIDGETS //CREATE 4 TEST WIDGETS
//two active and two non active //two active and two non active
//first active widget //first active widget
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.notes = "blah"; w.notes = "blah";
w.active = true; w.active = true;
w.usertype = 1; w.usertype = 1;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>()); ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
//second active widget //second active widget
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>()); ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
//first NON active widget //first NON active widget
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.active = false; w.active = false;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>()); NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
//second NON active widget //second NON active widget
w.name = Util.Uniquify(WidgetNameStart); w.name = Util.Uniquify(WidgetNameStart);
w.active = false; w.active = false;
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>()); NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
//CONFIRM BOTH INACTIVE AND ACTIVE //CONFIRM BOTH INACTIVE AND ACTIVE
a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct&inactive=true", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct&inactive=true", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
var pickList = ((JArray)a.ObjectResponse["data"]); var pickList = ((JArray)a.ObjectResponse["data"]);
//assert contains at least two records //assert contains at least two records
pickList.Count.Should().BeGreaterThan(1); pickList.Count.Should().BeGreaterThan(1);
int nActiveMatches = 0; int nActiveMatches = 0;
int nInactiveMatches = 0; int nInactiveMatches = 0;
foreach (JObject o in pickList) foreach (JObject o in pickList)
{ {
if (ActiveWidgetIdList.Contains(o["id"].Value<long>())) if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
nActiveMatches++; nActiveMatches++;
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>())) if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
nInactiveMatches++; nInactiveMatches++;
} }
nActiveMatches.Should().Be(ActiveWidgetIdList.Count); nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count); nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count);
//CONFIRM ACTIVE ONLY //CONFIRM ACTIVE ONLY
a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct", await Util.GetTokenAsync("BizAdminFull")); a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
pickList = ((JArray)a.ObjectResponse["data"]); pickList = ((JArray)a.ObjectResponse["data"]);
//assert contains at least two records //assert contains at least two records
pickList.Count.Should().BeGreaterThan(1); pickList.Count.Should().BeGreaterThan(1);
nActiveMatches = 0; nActiveMatches = 0;
nInactiveMatches = 0; nInactiveMatches = 0;
foreach (JObject o in pickList) foreach (JObject o in pickList)
{ {
if (ActiveWidgetIdList.Contains(o["id"].Value<long>())) if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
nActiveMatches++; nActiveMatches++;
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>())) if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
nInactiveMatches++; nInactiveMatches++;
} }
nActiveMatches.Should().Be(ActiveWidgetIdList.Count); nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
nInactiveMatches.Should().Be(0); nInactiveMatches.Should().Be(0);
//DELETE WIDGETS //DELETE WIDGETS
foreach (long l in ActiveWidgetIdList) foreach (long l in ActiveWidgetIdList)
{ {
a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
foreach (long l in NotActiveWidgetIdList) foreach (long l in NotActiveWidgetIdList)
{ {
a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(a, 204); Util.ValidateHTTPStatusCode(a, 204);
} }
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,28 +1,28 @@
using Xunit; using Xunit;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class Privacy public class Privacy
{ {
//DEPRECATED, NOT USEFUL //DEPRECATED, NOT USEFUL
// /// <summary> // /// <summary>
// /// // ///
// /// </summary> // /// </summary>
// [Fact] // [Fact]
// public async void LogShouldNotContainPrivateData() // public async Task LogShouldNotContainPrivateData()
// { // {
// ApiResponse a = await Util.GetAsync("AyaType", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT")); // ApiResponse a = await Util.GetAsync("AyaType", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
// ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT")); // ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
// Util.ValidateHTTPStatusCode(t, 200); // Util.ValidateHTTPStatusCode(t, 200);
// t.TextResponse.Should().NotContain("TEST_PRIVACY_USER_ACCOUNT"); // t.TextResponse.Should().NotContain("TEST_PRIVACY_USER_ACCOUNT");
// } // }
// //================================================== // //==================================================
}//eoc }//eoc
}//eons }//eons

File diff suppressed because it is too large Load Diff

View File

@@ -1,59 +1,59 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class ServerJob public class ServerJob
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void TestJobShouldSubmit() public async Task TestJobShouldSubmit()
{ {
ApiResponse a = await Util.PostAsync("job-operations/test-job", await Util.GetTokenAsync("OpsAdminFull")); ApiResponse a = await Util.PostAsync("job-operations/test-job", await Util.GetTokenAsync("OpsAdminFull"));
//Util.ValidateDataReturnResponseOk(a); //Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 202); Util.ValidateHTTPStatusCode(a, 202);
//should return something like this: //should return something like this:
/* /*
{ {
"testJobId": 4 "testJobId": 4
} }
*/ */
String jobId = a.ObjectResponse["jobId"].Value<String>(); String jobId = a.ObjectResponse["jobId"].Value<String>();
//Get a list of operations //Get a list of operations
a = await Util.GetAsync("job-operations", await Util.GetTokenAsync("OpsAdminFull")); a = await Util.GetAsync("job-operations", await Util.GetTokenAsync("OpsAdminFull"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
//there should be at least 1 //there should be at least 1
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterOrEqualTo(1); ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterOrEqualTo(1);
//See if our job is in there //See if our job is in there
bool bFound=false; bool bFound=false;
foreach(JToken t in a.ObjectResponse["data"]) foreach(JToken t in a.ObjectResponse["data"])
{ {
if(t["gId"].Value<String>()==jobId) if(t["gId"].Value<String>()==jobId)
bFound=true; bFound=true;
} }
bFound.Should().BeTrue(); bFound.Should().BeTrue();
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,25 +1,25 @@
using Xunit; using Xunit;
namespace raven_integration namespace raven_integration
{ {
public class ServerStateTest public class ServerStateTest
{ {
/// <summary> /// <summary>
/// Test get state /// Test get state
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerStateShouldReturnOk() public async Task ServerStateShouldReturnOk()
{ {
ApiResponse a = await Util.GetAsync("server-state"); ApiResponse a = await Util.GetAsync("server-state");
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
} }
//NOTE: can't test set because it would break the other tests //NOTE: can't test set because it would break the other tests
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,165 +1,165 @@
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
namespace raven_integration namespace raven_integration
{ {
public class TagOps public class TagOps
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void TagListsWork() public async Task TagListsWork()
{ {
var TestName = "TagListsWork"; var TestName = "TagListsWork";
var WidgetRunNameStart = Util.Uniquify(TestName); var WidgetRunNameStart = Util.Uniquify(TestName);
var TagNameStart = Util.Uniquify("crud-tag-test-") + "-";//ensure this run gets it's own unique tags var TagNameStart = Util.Uniquify("crud-tag-test-") + "-";//ensure this run gets it's own unique tags
TagNameStart = TagNameStart.Replace(" ", ""); TagNameStart = TagNameStart.Replace(" ", "");
List<string> InitialTagsList = new List<string>(); List<string> InitialTagsList = new List<string>();
InitialTagsList.Add(TagNameStart + "red"); InitialTagsList.Add(TagNameStart + "red");
InitialTagsList.Add(TagNameStart + "orange"); InitialTagsList.Add(TagNameStart + "orange");
InitialTagsList.Add(TagNameStart + "yellow"); InitialTagsList.Add(TagNameStart + "yellow");
InitialTagsList.Add(TagNameStart + "green"); InitialTagsList.Add(TagNameStart + "green");
InitialTagsList.Add(TagNameStart + "blue"); InitialTagsList.Add(TagNameStart + "blue");
InitialTagsList.Add(TagNameStart + "indigo"); InitialTagsList.Add(TagNameStart + "indigo");
InitialTagsList.Add(TagNameStart + "violet"); InitialTagsList.Add(TagNameStart + "violet");
List<string> UpdateTagsList = new List<string>(); List<string> UpdateTagsList = new List<string>();
//Newly added tags //Newly added tags
UpdateTagsList.Add(TagNameStart + "crimson"); UpdateTagsList.Add(TagNameStart + "crimson");
UpdateTagsList.Add(TagNameStart + "amber"); UpdateTagsList.Add(TagNameStart + "amber");
UpdateTagsList.Add(TagNameStart + "saffron"); UpdateTagsList.Add(TagNameStart + "saffron");
UpdateTagsList.Add(TagNameStart + "emerald"); UpdateTagsList.Add(TagNameStart + "emerald");
UpdateTagsList.Add(TagNameStart + "azure"); UpdateTagsList.Add(TagNameStart + "azure");
UpdateTagsList.Add(TagNameStart + "cobalt"); UpdateTagsList.Add(TagNameStart + "cobalt");
UpdateTagsList.Add(TagNameStart + "magenta"); UpdateTagsList.Add(TagNameStart + "magenta");
//maintains these tags //maintains these tags
UpdateTagsList.Add(TagNameStart + "red"); UpdateTagsList.Add(TagNameStart + "red");
UpdateTagsList.Add(TagNameStart + "blue"); UpdateTagsList.Add(TagNameStart + "blue");
//Removes these tags by omission //Removes these tags by omission
//orange, yellow, green, indigo, violet //orange, yellow, green, indigo, violet
dynamic w = new JObject(); dynamic w = new JObject();
w.name = Util.Uniquify(WidgetRunNameStart); w.name = Util.Uniquify(WidgetRunNameStart);
w.notes = "blah"; w.notes = "blah";
w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
w.usertype = 1; w.usertype = 1;
//Tags //Tags
dynamic InitialTags = new JArray(); dynamic InitialTags = new JArray();
foreach (string s in InitialTagsList) foreach (string s in InitialTagsList)
{ {
InitialTags.Add(s); InitialTags.Add(s);
} }
w.tags = InitialTags; w.tags = InitialTags;
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long WidgetId = a.ObjectResponse["data"]["id"].Value<long>(); long WidgetId = a.ObjectResponse["data"]["id"].Value<long>();
uint Concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>(); uint Concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
w = a.ObjectResponse["data"]; w = a.ObjectResponse["data"];
//validate the repository LIST ROUTE of tags contains the ones above //validate the repository LIST ROUTE of tags contains the ones above
a = await Util.GetAsync($"tag-list/list?query={TagNameStart}", await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.GetAsync($"tag-list/list?query={TagNameStart}", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
((JArray)a.ObjectResponse["data"]).Count.Should().Be(7); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(7);
//UPDATE Tags //UPDATE Tags
dynamic UpdateTags = new JArray(); dynamic UpdateTags = new JArray();
//Adds these tags //Adds these tags
foreach (string s in UpdateTagsList) foreach (string s in UpdateTagsList)
{ {
UpdateTags.Add(s); UpdateTags.Add(s);
} }
//update Widget and put to server //update Widget and put to server
w.concurrency = Concurrency; w.concurrency = Concurrency;
w.tags = UpdateTags; w.tags = UpdateTags;
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200); Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//Verify the tags collection remaining //Verify the tags collection remaining
a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
((JArray)a.ObjectResponse["data"]).Count.Should().Be(9); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(9);
//Verify the CLOUD LIST AND REF COUNT of tags collection remaining //Verify the CLOUD LIST AND REF COUNT of tags collection remaining
a = await Util.GetAsync($"tag-list/cloudlist?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.GetAsync($"tag-list/cloudlist?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
((JArray)a.ObjectResponse["data"]).Count.Should().Be(9); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(9);
a.ObjectResponse["data"][0]["refCount"].Value<long>().Should().Be(1); a.ObjectResponse["data"][0]["refCount"].Value<long>().Should().Be(1);
//DELETE //DELETE
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + WidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + WidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204); Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
//Verify the tags collection remaining //Verify the tags collection remaining
a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
((JArray)a.ObjectResponse["data"]).Count.Should().Be(0); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(0);
} }
/// <summary> /// <summary>
/// Test bulk tag bad params /// Test bulk tag bad params
/// </summary> /// </summary>
[Fact] [Fact]
public async void BulkBadParamsShouldFail() public async Task BulkBadParamsShouldFail()
{ {
dynamic d = new JArray(); dynamic d = new JArray();
// d.Add(1); // d.Add(1);
// d.Add(2); // d.Add(2);
// d.Add(3); // d.Add(3);
ApiResponse a = await Util.PostAsync("tag-list/bulk-add/33/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); ApiResponse a = await Util.PostAsync("tag-list/bulk-add/33/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
; ;
} }
// /// <summary> // /// <summary>
// /// Test bulk tag // /// Test bulk tag
// /// </summary> // /// </summary>
// [Fact] // [Fact]
// public async void BulkTagDriver() // public async Task BulkTagDriver()
// { // {
// dynamic d = new JArray(); // dynamic d = new JArray();
// d.Add(1); // d.Add(1);
// d.Add(2); // d.Add(2);
// ApiResponse a = await Util.PostAsync("tag-list/bulk-add/2/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); // ApiResponse a = await Util.PostAsync("tag-list/bulk-add/2/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
// //http://localhost:7575/api/v8/tag-list/bulk-add-any/2/bulk-add-this-tag // //http://localhost:7575/api/v8/tag-list/bulk-add-any/2/bulk-add-this-tag
// //http://localhost:7575/api/v8/tag-list/bulk-remove/2/happy%20new%20tag // //http://localhost:7575/api/v8/tag-list/bulk-remove/2/happy%20new%20tag
// //http://localhost:7575/api/v8/tag-list/bulk-remove-any/2/red // //http://localhost:7575/api/v8/tag-list/bulk-remove-any/2/red
// //http://localhost:7575/api/v8/tag-list/bulk-replace/2/bulk-add-this-tag?toTag=bulk-update-this-tag // //http://localhost:7575/api/v8/tag-list/bulk-replace/2/bulk-add-this-tag?toTag=bulk-update-this-tag
// //http://localhost:7575/api/v8/tag-list/bulk-replace-any/2/bulk-update-this-tag?toTag=bulk-replace-this-tag-any // //http://localhost:7575/api/v8/tag-list/bulk-replace-any/2/bulk-update-this-tag?toTag=bulk-replace-this-tag-any
// ; // ;
// } // }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,67 +1,67 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class RequestedLocaleKeys public class RequestedLocaleKeys
{ {
[Fact] [Fact]
public async void RequestedLocaleKeysWorks() public async Task RequestedLocaleKeysWorks()
{ {
//First determine if there is a requested key route because it's debug build dependent //First determine if there is a requested key route because it's debug build dependent
//And doesn't exists if server was not debug built //And doesn't exists if server was not debug built
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("CustomerLimited")); ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("CustomerLimited"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>(); var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
BuildMode.Should().BeOneOf((new string[] { "DEBUG", "RELEASE" })); BuildMode.Should().BeOneOf((new string[] { "DEBUG", "RELEASE" }));
if (BuildMode == "DEBUG") if (BuildMode == "DEBUG")
{ {
//Make a "list" of keys to fetch the values for //Make a "list" of keys to fetch the values for
List<string> keys = new List<string>(); List<string> keys = new List<string>();
keys.AddRange(new string[] { "HelpLicense", "CustomerName" }); keys.AddRange(new string[] { "HelpLicense", "CustomerName" });
dynamic d = new JObject(); dynamic d = new JObject();
d = JToken.FromObject(keys); d = JToken.FromObject(keys);
//Fetch the values to force RAVEN to track at least these two //Fetch the values to force RAVEN to track at least these two
a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString()); a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); 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 //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(2); ((JArray)a.ObjectResponse["data"]).Count.Should().Be(2);
//Now ensure there are at least two keys in the fetched keys array //Now ensure there are at least two keys in the fetched keys array
a = await Util.GetAsync("translation/TranslationKeyCoverage", await Util.GetTokenAsync("CustomerLimited")); a = await Util.GetAsync("translation/TranslationKeyCoverage", await Util.GetTokenAsync("CustomerLimited"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
Util.ValidateHTTPStatusCode(a, 200); Util.ValidateHTTPStatusCode(a, 200);
var RequestedKeyCount = a.ObjectResponse["data"]["requestedKeyCount"].Value<int>(); var RequestedKeyCount = a.ObjectResponse["data"]["requestedKeyCount"].Value<int>();
RequestedKeyCount.Should().BeGreaterOrEqualTo(2); RequestedKeyCount.Should().BeGreaterOrEqualTo(2);
var NotRequestedKeyCount = a.ObjectResponse["data"]["notRequestedKeyCount"].Value<int>(); var NotRequestedKeyCount = a.ObjectResponse["data"]["notRequestedKeyCount"].Value<int>();
NotRequestedKeyCount.Should().BeGreaterThan(1);//For now at least, once we have this dialed in it will be zero ultimately NotRequestedKeyCount.Should().BeGreaterThan(1);//For now at least, once we have this dialed in it will be zero ultimately
//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 //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"]["requestedKeys"]).Count.Should().Be(RequestedKeyCount); ((JArray)a.ObjectResponse["data"]["requestedKeys"]).Count.Should().Be(RequestedKeyCount);
((JArray)a.ObjectResponse["data"]["notRequestedKeys"]).Count.Should().Be(NotRequestedKeyCount); ((JArray)a.ObjectResponse["data"]["notRequestedKeys"]).Count.Should().Be(NotRequestedKeyCount);
} }
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

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

View File

@@ -1,263 +1,263 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class UserCrud public class UserCrud
{ {
/// <summary> /// <summary>
/// Test all CRUD routes for a User /// Test all CRUD routes for a User
/// </summary> /// </summary>
[Fact] [Fact]
public async void CRUD() public async Task CRUD()
{ {
//CREATE //CREATE
dynamic D1 = new JObject(); dynamic D1 = new JObject();
D1.name = Util.Uniquify("First Test User"); D1.name = Util.Uniquify("First Test User");
D1.active = true; D1.active = true;
D1.login = Util.Uniquify("LOGIN"); D1.login = Util.Uniquify("LOGIN");
D1.password = Util.Uniquify("PASSWORD"); D1.password = Util.Uniquify("PASSWORD");
D1.roles = 0;//norole D1.roles = 0;//norole
D1.userType = 3;//non scheduleable D1.userType = 3;//non scheduleable
//Required by form custom rules //Required by form custom rules
D1.notes = "notes"; D1.notes = "notes";
D1.customFields = Util.UserRequiredCustomFieldsJsonString(); D1.customFields = Util.UserRequiredCustomFieldsJsonString();
ApiResponse R1 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString()); ApiResponse R1 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
Util.ValidateDataReturnResponseOk(R1); Util.ValidateDataReturnResponseOk(R1);
long d1Id = R1.ObjectResponse["data"]["id"].Value<long>(); long d1Id = R1.ObjectResponse["data"]["id"].Value<long>();
dynamic D2 = new JObject(); dynamic D2 = new JObject();
D2.name = Util.Uniquify("Second Test User"); D2.name = Util.Uniquify("Second Test User");
//Required by form custom rules //Required by form custom rules
D2.notes = "notes"; D2.notes = "notes";
D2.customFields = Util.UserRequiredCustomFieldsJsonString(); D2.customFields = Util.UserRequiredCustomFieldsJsonString();
D2.active = true; D2.active = true;
D2.login = Util.Uniquify("LOGIN"); D2.login = Util.Uniquify("LOGIN");
D2.password = Util.Uniquify("PASSWORD"); D2.password = Util.Uniquify("PASSWORD");
D2.roles = 0;//norole D2.roles = 0;//norole
D2.userType = 3;//non scheduleable D2.userType = 3;//non scheduleable
ApiResponse R2 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString()); ApiResponse R2 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
Util.ValidateDataReturnResponseOk(R2); Util.ValidateDataReturnResponseOk(R2);
long d2Id = R2.ObjectResponse["data"]["id"].Value<long>(); long d2Id = R2.ObjectResponse["data"]["id"].Value<long>();
//RETRIEVE //RETRIEVE
//Get one //Get one
ApiResponse R3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse R3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(R3); Util.ValidateDataReturnResponseOk(R3);
R3.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString()); R3.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
//UPDATE //UPDATE
//PUT //PUT
//update w2id //update w2id
D2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User"); D2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
D2.concurrency = R2.ObjectResponse["data"]["concurrency"].Value<uint>(); D2.concurrency = R2.ObjectResponse["data"]["concurrency"].Value<uint>();
D2.id=d2Id; D2.id=d2Id;
ApiResponse PUTTestResponse = await Util.PutAsync("User" , await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("User" , await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200); Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//check PUT worked //check PUT worked
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateNoErrorInResponse(checkPUTWorked); Util.ValidateNoErrorInResponse(checkPUTWorked);
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString()); checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>(); uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
//DELETE //DELETE
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204); Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void UserWithActivityShouldNotBeDeleteable() public async Task UserWithActivityShouldNotBeDeleteable()
{ {
ApiResponse a = await Util.DeleteAsync("User/1", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.DeleteAsync("User/1", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
a.ObjectResponse["error"]["details"][0]["message"].Value<string>().Should().Contain("LT:ErrorDBForeignKeyViolation"); a.ObjectResponse["error"]["details"][0]["message"].Value<string>().Should().Contain("LT:ErrorDBForeignKeyViolation");
} }
/// <summary> /// <summary>
/// Test not found /// Test not found
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetNonExistentItemShouldError() public async Task GetNonExistentItemShouldError()
{ {
//Get non existant //Get non existant
//Should return status code 404, api error code 2010 //Should return status code 404, api error code 2010
ApiResponse R = await Util.GetAsync("User/999999", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse R = await Util.GetAsync("User/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateResponseNotFound(R); Util.ValidateResponseNotFound(R);
} }
/// <summary> /// <summary>
/// Test bad modelstate /// Test bad modelstate
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetBadModelStateShouldError() public async Task GetBadModelStateShouldError()
{ {
//Get non existant //Get non existant
//Should return status code 400, api error code 2200 and a first target in details of "id" //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")); ApiResponse R = await Util.GetAsync("User/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateBadModelStateResponse(R, "id"); Util.ValidateBadModelStateResponse(R, "id");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void PutConcurrencyViolationShouldFail() public async Task PutConcurrencyViolationShouldFail()
{ {
//CREATE //CREATE
dynamic D = new JObject(); dynamic D = new JObject();
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail"); D.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
D.notes = "notes"; D.notes = "notes";
D.customFields = Util.UserRequiredCustomFieldsJsonString(); D.customFields = Util.UserRequiredCustomFieldsJsonString();
D.active = true; D.active = true;
D.login = Util.Uniquify("LOGIN"); D.login = Util.Uniquify("LOGIN");
D.password = Util.Uniquify("PASSWORD"); D.password = Util.Uniquify("PASSWORD");
D.roles = 0;//norole D.roles = 0;//norole
D.userType = 3;//non scheduleable D.userType = 3;//non scheduleable
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString()); ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(R); Util.ValidateDataReturnResponseOk(R);
long D1Id = R.ObjectResponse["data"]["id"].Value<long>(); long D1Id = R.ObjectResponse["data"]["id"].Value<long>();
uint OriginalConcurrencyToken = R.ObjectResponse["data"]["concurrency"].Value<uint>(); uint OriginalConcurrencyToken = R.ObjectResponse["data"]["concurrency"].Value<uint>();
//UPDATE //UPDATE
//PUT //PUT
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT "); D.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
D.concurrency = OriginalConcurrencyToken - 1;//bad token D.concurrency = OriginalConcurrencyToken - 1;//bad token
D.id=D1Id; D.id=D1Id;
ApiResponse PUTTestResponse = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
Util.ValidateConcurrencyError(PUTTestResponse); Util.ValidateConcurrencyError(PUTTestResponse);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void PutPasswordShouldWork() public async Task PutPasswordShouldWork()
{ {
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("PutPasswordShouldWork"); d.name = Util.Uniquify("PutPasswordShouldWork");
d.active = true; d.active = true;
d.login = Util.Uniquify("LOGIN"); d.login = Util.Uniquify("LOGIN");
d.password = Util.Uniquify("PASSWORD"); d.password = Util.Uniquify("PASSWORD");
d.roles = 0;//norole d.roles = 0;//norole
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
//Required by form custom rules //Required by form custom rules
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
long UserId = a.ObjectResponse["data"]["id"].Value<long>(); long UserId = a.ObjectResponse["data"]["id"].Value<long>();
uint OriginalConcurrencyToken = a.ObjectResponse["data"]["concurrency"].Value<uint>(); uint OriginalConcurrencyToken = a.ObjectResponse["data"]["concurrency"].Value<uint>();
//Test can login //Test can login
dynamic DCreds = new JObject(); dynamic DCreds = new JObject();
DCreds.password = d.password; DCreds.password = d.password;
DCreds.login = d.login; DCreds.login = d.login;
a = await Util.PostAsync("auth", null, DCreds.ToString()); a = await Util.PostAsync("auth", null, DCreds.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//GET user (login changed concurrency token above) //GET user (login changed concurrency token above)
a = await Util.GetAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); a = await Util.GetAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
d = a.ObjectResponse["data"]; d = a.ObjectResponse["data"];
//PUT //PUT
var NewPassword = "NEW_PASSWORD"; var NewPassword = "NEW_PASSWORD";
d.password = NewPassword; d.password = NewPassword;
d.login=DCreds.login; d.login=DCreds.login;
a = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); a = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//Test can login with new creds //Test can login with new creds
//dynamic DCreds = new JObject(); //dynamic DCreds = new JObject();
DCreds.password = NewPassword; DCreds.password = NewPassword;
// DCreds.login = d.login; // DCreds.login = d.login;
a = await Util.PostAsync("auth", null, DCreds.ToString()); a = await Util.PostAsync("auth", null, DCreds.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void NonUniqueLoginShouldFail() public async Task NonUniqueLoginShouldFail()
{ {
var UniqueLogin = Util.Uniquify("NonUniqueLoginShouldFail"); var UniqueLogin = Util.Uniquify("NonUniqueLoginShouldFail");
//CREATE FIRST USER //CREATE FIRST USER
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("NonUniqueLoginShouldFail"); d.name = Util.Uniquify("NonUniqueLoginShouldFail");
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
d.active = false; d.active = false;
d.login = UniqueLogin; d.login = UniqueLogin;
d.password = Util.Uniquify("PASSWORD"); d.password = Util.Uniquify("PASSWORD");
d.roles = 0;//norole d.roles = 0;//norole
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//Attempt create second with same login //Attempt create second with same login
d = new JObject(); d = new JObject();
d.name = Util.Uniquify("2NonUniqueLoginShouldFail"); d.name = Util.Uniquify("2NonUniqueLoginShouldFail");
d.notes = "notes"; d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString(); d.customFields = Util.UserRequiredCustomFieldsJsonString();
d.active = false; d.active = false;
d.login = UniqueLogin; d.login = UniqueLogin;
d.password = Util.Uniquify("PASSWORD"); d.password = Util.Uniquify("PASSWORD");
d.roles = 0;//norole d.roles = 0;//norole
d.userType = 3;//non scheduleable d.userType = 3;//non scheduleable
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Login", "2206"); Util.ShouldContainValidationError(a, "Login", "2206");
/* /*
"{\"error\":{\"code\":\"2200\",\"details\":[{\"target\":\"Login\",\"error\":\"2206\"}],\"message\":\"Object did not pass validation\"}}" "{\"error\":{\"code\":\"2200\",\"details\":[{\"target\":\"Login\",\"error\":\"2206\"}],\"message\":\"Object did not pass validation\"}}"
*/ */
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,29 +1,29 @@
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace raven_integration namespace raven_integration
{ {
public class UserInactive public class UserInactive
{ {
/// <summary> /// <summary>
/// Inactive user should not be able to login /// Inactive user should not be able to login
/// </summary> /// </summary>
[Fact] [Fact]
public async void InactiveUserCantLogin() public async Task InactiveUserCantLogin()
{ {
dynamic DCreds = new JObject(); dynamic DCreds = new JObject();
DCreds.password = DCreds.login = "TEST_INACTIVE"; DCreds.password = DCreds.login = "TEST_INACTIVE";
ApiResponse a = await Util.PostAsync("auth", null, DCreds.ToString()); ApiResponse a = await Util.PostAsync("auth", null, DCreds.ToString());
Util.ValidateErrorCodeResponse(a,2003, 401); Util.ValidateErrorCodeResponse(a,2003, 401);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,122 +1,122 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class UserOptions public class UserOptions
{ {
/// <summary> /// <summary>
/// Test all CRUD routes for a UserOptions object /// Test all CRUD routes for a UserOptions object
/// </summary> /// </summary>
[Fact] [Fact]
public async void CRUD() public async Task CRUD()
{ {
//CREATE a user //CREATE a user
dynamic D1 = new JObject(); dynamic D1 = new JObject();
D1.name = Util.Uniquify("Test UserOptions User"); D1.name = Util.Uniquify("Test UserOptions User");
D1.active = true; D1.active = true;
D1.login = Util.Uniquify("LOGIN"); D1.login = Util.Uniquify("LOGIN");
D1.password = Util.Uniquify("PASSWORD"); D1.password = Util.Uniquify("PASSWORD");
D1.roles = 0;//norole D1.roles = 0;//norole
D1.userType = 3;//non scheduleable D1.userType = 3;//non scheduleable
D1.notes = "notes"; D1.notes = "notes";
D1.customFields = Util.UserRequiredCustomFieldsJsonString(); D1.customFields = Util.UserRequiredCustomFieldsJsonString();
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString()); ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
Util.ValidateDataReturnResponseOk(R); Util.ValidateDataReturnResponseOk(R);
long UserId = R.ObjectResponse["data"]["id"].Value<long>(); long UserId = R.ObjectResponse["data"]["id"].Value<long>();
//Now there should be a user options available for this user //Now there should be a user options available for this user
//RETRIEVE companion USEROPTIONS object //RETRIEVE companion USEROPTIONS object
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(R); Util.ValidateDataReturnResponseOk(R);
//ensure the default value is set //ensure the default value is set
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000"); R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>(); uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
//UPDATE //UPDATE
//PUT //PUT
dynamic D2 = new JObject(); dynamic D2 = new JObject();
D2.translationId = 1; D2.translationId = 1;
D2.emailAddress = "testuseroptions@helloayanova.com"; D2.emailAddress = "testuseroptions@helloayanova.com";
D2.languageOverride = "de-DE"; D2.languageOverride = "de-DE";
D2.timeZoneOverride = "Europe/Berlin"; D2.timeZoneOverride = "Europe/Berlin";
D2.currencyName = "EUR"; D2.currencyName = "EUR";
D2.hour12 = false; D2.hour12 = false;
D2.uiColor = "#ffaaff"; D2.uiColor = "#ffaaff";
D2.concurrency = concurrency; D2.concurrency = concurrency;
ApiResponse PUTTestResponse = await Util.PutAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200); Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//VALIDATE //VALIDATE
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(R); Util.ValidateDataReturnResponseOk(R);
//ensure the default value is set //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}}" "{\"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"]["emailAddress"].Value<string>().Should().Be(D2.emailAddress.ToString());
R.ObjectResponse["data"]["languageOverride"].Value<string>().Should().Be(D2.languageOverride.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"]["timeZoneOverride"].Value<string>().Should().Be(D2.timeZoneOverride.ToString());
R.ObjectResponse["data"]["currencyName"].Value<string>().Should().Be(D2.currencyName.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"]["hour12"].Value<bool>().Should().Be((bool)D2.hour12);
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be(D2.uiColor.ToString()); R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be(D2.uiColor.ToString());
R.ObjectResponse["data"]["translationId"].Value<long>().Should().Be((long)D2.translationId); R.ObjectResponse["data"]["translationId"].Value<long>().Should().Be((long)D2.translationId);
concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>(); concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
//DELETE USER //DELETE USER
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204); Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
//CHECK DELETE USER REMOVED USEROPTIONS //CHECK DELETE USER REMOVED USEROPTIONS
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateResponseNotFound(R); Util.ValidateResponseNotFound(R);
} }
/// <summary> /// <summary>
/// Test not found /// Test not found
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetNonExistentItemShouldError() public async Task GetNonExistentItemShouldError()
{ {
//Get non existant //Get non existant
//Should return status code 404, api error code 2010 //Should return status code 404, api error code 2010
ApiResponse R = await Util.GetAsync("user-option/999999", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse R = await Util.GetAsync("user-option/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateResponseNotFound(R); Util.ValidateResponseNotFound(R);
} }
/// <summary> /// <summary>
/// Test bad modelstate /// Test bad modelstate
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetBadModelStateShouldError() public async Task GetBadModelStateShouldError()
{ {
//Get non existant //Get non existant
//Should return status code 400, api error code 2200 and a first target in details of "id" //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")); ApiResponse R = await Util.GetAsync("user-option/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateBadModelStateResponse(R, "id"); Util.ValidateBadModelStateResponse(R, "id");
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,199 +1,199 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
namespace raven_integration namespace raven_integration
{ {
public class WidgetCrud public class WidgetCrud
{ {
/// <summary> /// <summary>
/// Test all CRUD routes for a widget /// Test all CRUD routes for a widget
/// </summary> /// </summary>
[Fact] [Fact]
public async void CRUD() public async Task CRUD()
{ {
/* /*
{ {
"id": 0, "id": 0,
"name": "string", "name": "string",
"dollarAmount": 0, "dollarAmount": 0,
"active": true, "active": true,
"roles": 0 "roles": 0
} }
*/ */
//CREATE //CREATE
dynamic w1 = new JObject(); dynamic w1 = new JObject();
w1.name = Util.Uniquify("First Test WIDGET"); w1.name = Util.Uniquify("First Test WIDGET");
w1.dollarAmount = 1.11m; w1.dollarAmount = 1.11m;
w1.active = true; w1.active = true;
w1.usertype = 1; w1.usertype = 1;
w1.notes = "The quick brown fox jumped over the six lazy dogs!"; w1.notes = "The quick brown fox jumped over the six lazy dogs!";
w1.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w1.customFields = Util.WidgetRequiredCustomFieldsJsonString();
//Tags //Tags
dynamic dTagsArray = new JArray(); dynamic dTagsArray = new JArray();
dTagsArray.Add("Red Tag"); dTagsArray.Add("Red Tag");
dTagsArray.Add("ORANGE IS THE NEW BLACK"); dTagsArray.Add("ORANGE IS THE NEW BLACK");
dTagsArray.Add("yellow"); dTagsArray.Add("yellow");
dTagsArray.Add("green"); dTagsArray.Add("green");
dTagsArray.Add("blue"); dTagsArray.Add("blue");
dTagsArray.Add("indigo"); dTagsArray.Add("indigo");
dTagsArray.Add("VIOLET Tag"); dTagsArray.Add("VIOLET Tag");
w1.tags = dTagsArray; w1.tags = dTagsArray;
ApiResponse r1 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w1.ToString()); ApiResponse r1 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w1.ToString());
Util.ValidateDataReturnResponseOk(r1); Util.ValidateDataReturnResponseOk(r1);
long w1Id = r1.ObjectResponse["data"]["id"].Value<long>(); long w1Id = r1.ObjectResponse["data"]["id"].Value<long>();
((long)r1.ObjectResponse["data"]["serial"]).Should().NotBe(0); ((long)r1.ObjectResponse["data"]["serial"]).Should().NotBe(0);
dynamic w2 = new JObject(); dynamic w2 = new JObject();
w2.name = Util.Uniquify("Second Test WIDGET"); w2.name = Util.Uniquify("Second Test WIDGET");
w2.dollarAmount = 2.22m; w2.dollarAmount = 2.22m;
w2.active = true; w2.active = true;
w2.usertype = 1; w2.usertype = 1;
w2.notes = "What is the frequency Kenneth?"; w2.notes = "What is the frequency Kenneth?";
w2.tags = dTagsArray; w2.tags = dTagsArray;
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString()); ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
Util.ValidateDataReturnResponseOk(r2); Util.ValidateDataReturnResponseOk(r2);
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>(); long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
//RETRIEVE //RETRIEVE
//Get one //Get one
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateDataReturnResponseOk(r3); Util.ValidateDataReturnResponseOk(r3);
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString()); r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
r3.ObjectResponse["data"]["notes"].Value<string>().Should().Be(w2.notes.ToString()); r3.ObjectResponse["data"]["notes"].Value<string>().Should().Be(w2.notes.ToString());
var returnedTags = ((JArray)r3.ObjectResponse["data"]["tags"]); var returnedTags = ((JArray)r3.ObjectResponse["data"]["tags"]);
returnedTags.Count.Should().Be(7); returnedTags.Count.Should().Be(7);
//UPDATE //UPDATE
//PUT //PUT
//update w2id //update w2id
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET"); w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
w2.id = w2Id; w2.id = w2Id;
w2.serial = 123456L; w2.serial = 123456L;
w2.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>(); w2.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200); Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//check PUT worked //check PUT worked
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateNoErrorInResponse(checkPUTWorked); Util.ValidateNoErrorInResponse(checkPUTWorked);
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString()); checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
checkPUTWorked.ObjectResponse["data"]["serial"].Value<long>().Should().Be(123456L); checkPUTWorked.ObjectResponse["data"]["serial"].Value<long>().Should().Be(123456L);
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>(); uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
//DELETE //DELETE
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204); Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
} }
/// <summary> /// <summary>
/// Test not found /// Test not found
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetNonExistentItemShouldError() public async Task GetNonExistentItemShouldError()
{ {
//Get non existant //Get non existant
//Should return status code 404, api error code 2010 //Should return status code 404, api error code 2010
ApiResponse a = await Util.GetAsync("widget/999999", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("widget/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateResponseNotFound(a); Util.ValidateResponseNotFound(a);
} }
/// <summary> /// <summary>
/// Test bad modelstate /// Test bad modelstate
/// </summary> /// </summary>
[Fact] [Fact]
public async void GetBadModelStateShouldError() public async Task GetBadModelStateShouldError()
{ {
//Get non existant //Get non existant
//Should return status code 400, api error code 2200 and a first target in details of "id" //Should return status code 400, api error code 2200 and a first target in details of "id"
ApiResponse a = await Util.GetAsync("widget/2q2", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("widget/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateBadModelStateResponse(a, "id"); Util.ValidateBadModelStateResponse(a, "id");
} }
/// <summary> /// <summary>
/// Test server exception /// Test server exception
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerExceptionShouldErrorPropertly() public async Task ServerExceptionShouldErrorPropertly()
{ {
//Get non existant //Get non existant
//Should return status code 400, api error code 2200 and a first target in details of "id" //Should return status code 400, api error code 2200 and a first target in details of "id"
ApiResponse a = await Util.GetAsync("widget/exception", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("widget/exception", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateServerExceptionResponse(a); Util.ValidateServerExceptionResponse(a);
} }
/// <summary> /// <summary>
/// Test server alt exception /// Test server alt exception
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerAltExceptionShouldErrorPropertly() public async Task ServerAltExceptionShouldErrorPropertly()
{ {
//Get non existant //Get non existant
//Should return status code 400, api error code 2200 and a first target in details of "id" //Should return status code 400, api error code 2200 and a first target in details of "id"
ApiResponse a = await Util.GetAsync("widget/altexception", await Util.GetTokenAsync("superuser", "l3tm3in")); ApiResponse a = await Util.GetAsync("widget/altexception", await Util.GetTokenAsync("superuser", "l3tm3in"));
Util.ValidateServerExceptionResponse(a); Util.ValidateServerExceptionResponse(a);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void PutConcurrencyViolationShouldFail() public async Task PutConcurrencyViolationShouldFail()
{ {
//CREATE //CREATE
dynamic w2 = new JObject(); dynamic w2 = new JObject();
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail"); w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
w2.dollarAmount = 2.22m; w2.dollarAmount = 2.22m;
w2.active = true; w2.active = true;
w2.usertype = 1; w2.usertype = 1;
w2.notes = "blah"; w2.notes = "blah";
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString(); w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString()); ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
Util.ValidateDataReturnResponseOk(r2); Util.ValidateDataReturnResponseOk(r2);
uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value<uint>(); uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
w2 = r2.ObjectResponse["data"]; w2 = r2.ObjectResponse["data"];
//UPDATE //UPDATE
//PUT //PUT
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT "); w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
w2.concurrency = OriginalConcurrencyToken - 1;//bad token w2.concurrency = OriginalConcurrencyToken - 1;//bad token
ApiResponse PUTTestResponse = await Util.PutAsync("widget/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString()); ApiResponse PUTTestResponse = await Util.PutAsync("widget/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
Util.ValidateConcurrencyError(PUTTestResponse); Util.ValidateConcurrencyError(PUTTestResponse);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,81 +1,81 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
// [Collection("APICOLLECTION")] // [Collection("APICOLLECTION")]
public class WidgetRights public class WidgetRights
{ {
/// <summary> /// <summary>
/// Test not authorized error return /// Test not authorized error return
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerShouldNotAllowUnauthenticatedAccess() public async Task ServerShouldNotAllowUnauthenticatedAccess()
{ {
ApiResponse a = await Util.GetAsync("widget/list"); ApiResponse a = await Util.GetAsync("widget/list");
Util.ValidateHTTPStatusCode(a, 401); Util.ValidateHTTPStatusCode(a, 401);
} }
/// <summary> /// <summary>
/// Test insufficient read rights error return /// Test insufficient read rights error return
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerShouldNotAllowReadUnauthorizedAccess() public async Task ServerShouldNotAllowReadUnauthorizedAccess()
{ {
ApiResponse a = await Util.GetAsync("widget/listwidgets", await Util.GetTokenAsync( "OpsAdminFull")); ApiResponse a = await Util.GetAsync("widget/listwidgets", await Util.GetTokenAsync( "OpsAdminFull"));
//2004 unauthorized //2004 unauthorized
Util.ValidateErrorCodeResponse(a, 2004, 403); Util.ValidateErrorCodeResponse(a, 2004, 403);
} }
/// <summary> /// <summary>
/// Test insufficient create rights error return /// Test insufficient create rights error return
/// </summary> /// </summary>
[Fact] [Fact]
public async void ServerShouldNotAllowCreateUnauthorizedAccess() public async Task ServerShouldNotAllowCreateUnauthorizedAccess()
{ {
//CREATE //CREATE
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("ServerShouldNotAllowCreateUnauthorizedAccess TEST WIDGET"); d.name = Util.Uniquify("ServerShouldNotAllowCreateUnauthorizedAccess TEST WIDGET");
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//BizAdminLimited user should not be able to create a widget, only read them //BizAdminLimited user should not be able to create a widget, only read them
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync( "BizAdminLimited"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync( "BizAdminLimited"), d.ToString());
//2004 unauthorized //2004 unauthorized
Util.ValidateErrorCodeResponse(a, 2004, 403); Util.ValidateErrorCodeResponse(a, 2004, 403);
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

View File

@@ -1,239 +1,239 @@
using System; using System;
using Xunit; using Xunit;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using FluentAssertions; using FluentAssertions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace raven_integration namespace raven_integration
{ {
public class WidgetValidationTest public class WidgetValidationTest
{ {
// /// <summary> // /// <summary>
// /// Test business rule should be active on new // /// Test business rule should be active on new
// /// </summary> // /// </summary>
// [Fact] // [Fact]
// public async void BusinessRuleNewShouldBeActiveShouldWork() // public async Task BusinessRuleNewShouldBeActiveShouldWork()
// { // {
// //CREATE attempt with broken rules // //CREATE attempt with broken rules
// dynamic d = new JObject(); // dynamic d = new JObject();
// d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET"); // d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET");
// d.created = DateTime.Now.ToString(); // d.created = DateTime.Now.ToString();
// d.dollarAmount = 1.11m; // d.dollarAmount = 1.11m;
// d.active = false;//<--- BROKEN RULE new widget must be active = true!! // d.active = false;//<--- BROKEN RULE new widget must be active = true!!
// d.usertype = 1; // d.usertype = 1;
// //create via inventory full test user // //create via inventory full test user
// ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); // ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
// Util.ValidateErrorCodeResponse(a, 2200, 400); // Util.ValidateErrorCodeResponse(a, 2200, 400);
// Util.ShouldContainValidationError(a, "Active", "2203"); // Util.ShouldContainValidationError(a, "Active", "2203");
// } // }
/// <summary> /// <summary>
/// Test business rule name should be unique /// Test business rule name should be unique
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleNameMustBeUnique() public async Task BusinessRuleNameMustBeUnique()
{ {
//CREATE attempt with broken rules //CREATE attempt with broken rules
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET"); d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET");
d.notes = "blah"; d.notes = "blah";
d.customFields = Util.WidgetRequiredCustomFieldsJsonString(); d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
Util.ValidateDataReturnResponseOk(a); Util.ValidateDataReturnResponseOk(a);
//Now try to create again with same name //Now try to create again with same name
a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Name", "2206"); Util.ShouldContainValidationError(a, "Name", "2206");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleNameRequired() public async Task BusinessRuleNameRequired()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.name = ""; d.name = "";
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
//This is a modelstate error so even though it would be a 2201 in other circumstances here it's a 2203 //This is a modelstate error so even though it would be a 2201 in other circumstances here it's a 2203
//Maybe a todo is to refine this a bit //Maybe a todo is to refine this a bit
Util.ShouldContainValidationError(a, "Name", "2203"); Util.ShouldContainValidationError(a, "Name", "2203");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleNameLengthExceeded() public async Task BusinessRuleNameLengthExceeded()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.name = new string('A', 256); ; d.name = new string('A', 256); ;
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Name", "2202", "255 max"); Util.ShouldContainValidationError(a, "Name", "2202", "255 max");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleStartDateWithoutEndDateShouldError() public async Task BusinessRuleStartDateWithoutEndDateShouldError()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleStartDateWithoutEndDateShouldError TEST"); d.name = Util.Uniquify("BusinessRuleStartDateWithoutEndDateShouldError TEST");
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.startDate = d.created; d.startDate = d.created;
//NO END DATE ERRROR //NO END DATE ERRROR
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "EndDate", "2201"); Util.ShouldContainValidationError(a, "EndDate", "2201");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleEndDateWithoutStartDateShouldError() public async Task BusinessRuleEndDateWithoutStartDateShouldError()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleEndDateWithoutStartDateShouldError TEST"); d.name = Util.Uniquify("BusinessRuleEndDateWithoutStartDateShouldError TEST");
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.endDate = d.created; d.endDate = d.created;
//NO START DATE ERRROR //NO START DATE ERRROR
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "StartDate", "2201"); Util.ShouldContainValidationError(a, "StartDate", "2201");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleEndDateBeforeStartDateShouldError() public async Task BusinessRuleEndDateBeforeStartDateShouldError()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleEndDateBeforeStartDateShouldError TEST"); d.name = Util.Uniquify("BusinessRuleEndDateBeforeStartDateShouldError TEST");
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
d.startDate = DateTime.Now.ToString(); d.startDate = DateTime.Now.ToString();
d.endDate = DateTime.Now.AddHours(-1).ToString(); d.endDate = DateTime.Now.AddHours(-1).ToString();
//NO START DATE ERRROR //NO START DATE ERRROR
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = 1; d.usertype = 1;
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "StartDate", "2207"); Util.ShouldContainValidationError(a, "StartDate", "2207");
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Fact] [Fact]
public async void BusinessRuleEnumInvalidShouldError() public async Task BusinessRuleEnumInvalidShouldError()
{ {
dynamic d = new JObject(); dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST"); d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST");
d.created = DateTime.Now.ToString(); d.created = DateTime.Now.ToString();
//NO END DATE ERRROR //NO END DATE ERRROR
d.dollarAmount = 1.11m; d.dollarAmount = 1.11m;
d.active = true; d.active = true;
d.usertype = -1;//<---BAD VALUE d.usertype = -1;//<---BAD VALUE
d.Notes = "blah"; d.Notes = "blah";
d.customFields = Util.WidgetRequiredCustomFieldsJsonString(); d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
//create via inventory full test user //create via inventory full test user
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString()); ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected //2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "UserType", "2203"); Util.ShouldContainValidationError(a, "UserType", "2203");
} }
//================================================== //==================================================
}//eoc }//eoc
}//eons }//eons

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<GenerateFullPaths>true</GenerateFullPaths> <GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> <PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" /> <PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

1308
util.cs

File diff suppressed because it is too large Load Diff