This commit is contained in:
28
test/raven-integration/.vscode/launch.json
vendored
Normal file
28
test/raven-integration/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/raven-integration.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
test/raven-integration/.vscode/settings.json
vendored
Normal file
3
test/raven-integration/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"editor.codeLens": true
|
||||
}
|
||||
15
test/raven-integration/.vscode/tasks.json
vendored
Normal file
15
test/raven-integration/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/raven-integration.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
13
test/raven-integration/ApiResponse.cs
Normal file
13
test/raven-integration/ApiResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public HttpResponseMessage HttpResponse {get;set;}
|
||||
public JObject ObjectResponse {get;set;}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
13
test/raven-integration/ApiTextResponse.cs
Normal file
13
test/raven-integration/ApiTextResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class ApiTextResponse
|
||||
{
|
||||
public HttpResponseMessage HttpResponse {get;set;}
|
||||
public string TextResponse {get;set;}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
182
test/raven-integration/Attachments/AttachmentTest.cs
Normal file
182
test/raven-integration/Attachments/AttachmentTest.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
//https://stackoverflow.com/questions/17725882/testing-asp-net-web-api-multipart-form-data-file-upload
|
||||
public class AttachmentTest
|
||||
{
|
||||
/// <summary>
|
||||
/// test attach CRUD
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void AttachmentUploadDownloadDeleteShouldWork()
|
||||
{
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// Upload the files
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data like the bizobject type and id
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
//or if testing non-existant this is probably safe: long.MaxValue
|
||||
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
StreamContent file2 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.zip"));
|
||||
file2.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
|
||||
file2.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file2.Headers.ContentDisposition.FileName = "test.zip";
|
||||
formDataContent.Add(file2);
|
||||
|
||||
//create via inventory full test user as attachments use the role of the object attaching to
|
||||
ApiResponse a = await Util.PostFormDataAsync("Attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
|
||||
long lTestPngAttachmentId = a.ObjectResponse["result"][0]["id"].Value<long>();
|
||||
long lTestZipAttachmentId = a.ObjectResponse["result"][1]["id"].Value<long>();
|
||||
|
||||
//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
|
||||
lTestPngAttachmentId.Should().BePositive();
|
||||
lTestZipAttachmentId.Should().BePositive();
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DOWNLOAD: Get the file attachment
|
||||
|
||||
//Get the inventoryfull account download token
|
||||
// {
|
||||
// "result": {
|
||||
// "dlkey": "w7iE1cXF8kOxo8eomd1r8A",
|
||||
// "expires": "2018-04-25T23:45:39.05665"
|
||||
// }
|
||||
// }
|
||||
a = await Util.GetAsync("Attachment/DownloadToken", await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
string downloadToken = a.ObjectResponse["result"]["dlkey"].Value<string>();
|
||||
|
||||
//now get the file https://rockfish.ayanova.com/api/rfcaseblob/download/248?dlkey=9O2eDAAlZ0Wknj19SBK2iA
|
||||
var dlresponse = await Util.DownloadFileAsync("Attachment/Download/" + lTestZipAttachmentId.ToString() + "?dlkey=" + downloadToken, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//ensure it's the zip file we expected
|
||||
dlresponse.Content.Headers.ContentDisposition.FileName.Should().Be("test.zip");
|
||||
dlresponse.Content.Headers.ContentLength.Should().BeGreaterThan(2000);
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DELETE: Delete the file attachments
|
||||
ApiResponse d = await Util.DeleteAsync("Attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateHTTPStatusCode(d, 204);
|
||||
|
||||
d = await Util.DeleteAsync("Attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateHTTPStatusCode(d, 204);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test no rights
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void NoRightsTest()
|
||||
{
|
||||
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
|
||||
//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"));
|
||||
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 401);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test not attachable
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UnattachableTest()
|
||||
{
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data bizobject type and id
|
||||
|
||||
//HERE IS THE ERROR CONDITION: LICENSE TYPE OBJECT WHICH IS UNATTACHABLE
|
||||
formDataContent.Add(new StringContent("5"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
ApiResponse a = await Util.PostFormDataAsync("Attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//2203 unattachable object
|
||||
Util.ValidateErrorCodeResponse(a, 2203, 400);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test bad object values
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BadObject()
|
||||
{
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data like the bizobject type and id
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
|
||||
//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
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
ApiResponse a = await Util.PostFormDataAsync("Attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//2203 invalid attachment object
|
||||
Util.ValidateErrorCodeResponse(a, 2203, 400);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
36
test/raven-integration/Authentication/Auth.cs
Normal file
36
test/raven-integration/Authentication/Auth.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Auth
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BadLoginShouldNotWork()
|
||||
{
|
||||
//Expect status code 401 and result:
|
||||
// {{
|
||||
// "error": {
|
||||
// "code": "2003",
|
||||
// "message": "Authentication failed"
|
||||
// }
|
||||
// }}
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.login = "BOGUS";
|
||||
d.password = "ACCOUNT";
|
||||
ApiResponse a = await Util.PostAsync("Auth", null, d.ToString());
|
||||
Util.ValidateErrorCodeResponse(a,2003,401);
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
36
test/raven-integration/AyaType/AyaType.cs
Normal file
36
test/raven-integration/AyaType/AyaType.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class AyaType
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void AyaTypeListShouldWork()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("AyaType");
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be at least 8 of them (at time of writing late March 2018)
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterOrEqualTo(8);
|
||||
|
||||
//Number 2 is widget and list is zero based so confirm:
|
||||
a.ObjectResponse["result"][2]["id"].Value<long>().Should().Be(2);
|
||||
a.ObjectResponse["result"][2]["name"].Value<string>().Should().Be("Widget [Attachable] [Taggable]");
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
57
test/raven-integration/ImportV7/ImportV7.cs
Normal file
57
test/raven-integration/ImportV7/ImportV7.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ImportV7
|
||||
{
|
||||
//==================================================
|
||||
/// <summary>
|
||||
/// Test Importv7 stuff
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ImportV7FileRoutesShouldWork()
|
||||
{
|
||||
|
||||
string UploadFileName = "ayanova.data.dump.xxx.zip";
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// Upload the files
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\{UploadFileName}"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = UploadFileName;
|
||||
formDataContent.Add(file1);
|
||||
|
||||
ApiResponse a = await Util.PostFormDataAsync("ImportAyaNova7", formDataContent, await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
string importFileName = a.ObjectResponse["result"][0].Value<string>();
|
||||
importFileName.Should().Be(UploadFileName);
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DELETE: Delete the file
|
||||
ApiResponse d = await Util.DeleteAsync($"ImportAyaNova7/{UploadFileName}", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(d, 204);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
59
test/raven-integration/JobOperations/JobOperations.cs
Normal file
59
test/raven-integration/JobOperations/JobOperations.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class JobOperations
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TestJobShouldSubmit()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("Widget/TestWidgetJob", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
//Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 202);
|
||||
//should return something like this:
|
||||
/*
|
||||
{
|
||||
"testJobId": 4
|
||||
}
|
||||
*/
|
||||
|
||||
String jobId = a.ObjectResponse["jobId"].Value<String>();
|
||||
|
||||
//Get a list of operations
|
||||
a = await Util.GetAsync("JobOperations", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
|
||||
|
||||
//there should be at least 1
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterOrEqualTo(1);
|
||||
|
||||
//See if our job is in there
|
||||
bool bFound=false;
|
||||
foreach(JToken t in a.ObjectResponse["result"])
|
||||
{
|
||||
if(t["gId"].Value<String>()==jobId)
|
||||
bFound=true;
|
||||
}
|
||||
bFound.Should().BeTrue();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
164
test/raven-integration/Locale/Locale.cs
Normal file
164
test/raven-integration/Locale/Locale.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Locale
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
ImportLocale(ct, ResourceFolderPath, "en"); - id 1
|
||||
ImportLocale(ct, ResourceFolderPath, "es"); - id 2
|
||||
ImportLocale(ct, ResourceFolderPath, "fr"); - id 3
|
||||
ImportLocale(ct, ResourceFolderPath, "de"); - id 4
|
||||
*/
|
||||
|
||||
[Fact]
|
||||
public async void LocalePickListWorks()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("Locale/picklist", await Util.GetTokenAsync("ClientLimited"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be at least 4 of them as there are 4 stock locales
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterThan(3);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void GetFullLocaleWorks()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("Locale/1", await Util.GetTokenAsync("ClientLimited"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["result"]["localeItems"]).Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void GetSubsetWorks()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"localeId": 0,
|
||||
"keys": [
|
||||
"string"
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { "AddressType", "ClientName", "RateName", "WorkorderService" });
|
||||
dynamic d = new JObject();
|
||||
d.localeId = 1;
|
||||
d.keys = JToken.FromObject(keys);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Locale/subset", await Util.GetTokenAsync("ClientLimited"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().Be(4);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void DuplicateUpdateAndDeleteWorks()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"id": 1,
|
||||
"name": "CustomTest1"
|
||||
}
|
||||
*/
|
||||
|
||||
//DUPLICATE
|
||||
dynamic d = new JObject();
|
||||
d.id = 1;
|
||||
d.name = Util.Uniquify("INTEGRATION-TEST-LOCALE");
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Locale/Duplicate", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 201);
|
||||
//verify the object returned is as expected
|
||||
a.ObjectResponse["result"]["name"].Value<string>().Should().Be(d.name.ToString());
|
||||
a.ObjectResponse["result"]["stock"].Value<bool>().Should().Be(false);
|
||||
a.ObjectResponse["result"]["id"].Value<long>().Should().BeGreaterThan(4);
|
||||
a.ObjectResponse["result"]["concurrencyToken"].Value<uint>().Should().BeGreaterThan(0);
|
||||
((JArray)a.ObjectResponse["result"]["localeItems"]).Count.Should().BeGreaterThan(0);
|
||||
|
||||
long NewId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//UPDATE
|
||||
//Update locale name
|
||||
|
||||
/*
|
||||
|
||||
{
|
||||
"id": 10,
|
||||
"newText": "What the hell?",
|
||||
"concurrencyToken": 25174
|
||||
}
|
||||
|
||||
*/
|
||||
dynamic d2 = new JObject();
|
||||
d2.id = NewId;
|
||||
d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALE NAME UPDATE");
|
||||
d2.concurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Locale/UpdateLocaleName", await Util.GetTokenAsync("BizAdminFull"), d2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("Locale/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(d2.newText.ToString());
|
||||
//uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
|
||||
//Update locale key
|
||||
var FirstLocaleKey = ((JArray)a.ObjectResponse["result"]["localeItems"])[0];
|
||||
long UpdatedLocaleKeyId = FirstLocaleKey["id"].Value<long>();
|
||||
d2.id = UpdatedLocaleKeyId;
|
||||
d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALEITEM DISPLAY UPDATE");
|
||||
d2.concurrencyToken = FirstLocaleKey["concurrencyToken"].Value<uint>();
|
||||
|
||||
string UpdatedLocaleKey = FirstLocaleKey["key"].Value<string>();
|
||||
|
||||
PUTTestResponse = await Util.PutAsync("Locale/UpdateLocaleItemDisplayText", await Util.GetTokenAsync("BizAdminFull"), d2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { UpdatedLocaleKey });
|
||||
dynamic d3 = new JObject();
|
||||
d3.localeId = NewId;
|
||||
d3.keys = JToken.FromObject(keys);
|
||||
|
||||
checkPUTWorked = await Util.PostAsync("Locale/subset", await Util.GetTokenAsync("ClientLimited"), d3.ToString());
|
||||
Util.ValidateDataReturnResponseOk(checkPUTWorked);
|
||||
Util.ValidateHTTPStatusCode(checkPUTWorked, 200);
|
||||
((JArray)checkPUTWorked.ObjectResponse["result"]).Count.Should().Be(1);
|
||||
var FirstLocaleKeyUpdated = ((JArray)checkPUTWorked.ObjectResponse["result"])[0];
|
||||
|
||||
FirstLocaleKeyUpdated["value"].Value<string>().Should().Be(d2.newText.ToString());
|
||||
|
||||
//DELETE
|
||||
|
||||
a = await Util.DeleteAsync("Locale/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
31
test/raven-integration/LogFiles/LogFiles.cs
Normal file
31
test/raven-integration/LogFiles/LogFiles.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class LogFiles
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void MostRecentLogShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetTextResultAsync("LogFiles/log-ayanova.txt", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
t.TextResponse.Should().Contain("|INFO|");//assumes any log will have at least one INFO log item in it
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
51
test/raven-integration/Metrics/Metrics.cs
Normal file
51
test/raven-integration/Metrics/Metrics.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Metrics
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TextMetricsShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetTextResultAsync("Metrics/TextSnapShot", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
|
||||
t.TextResponse.Should().StartWith("# TIMESTAMP:");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JsonMetricsShouldFetch()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("Metrics/JsonSnapShot", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
a.ObjectResponse["result"]["timestamp"].Should().NotBeNull();
|
||||
((JArray)a.ObjectResponse["result"]["contexts"]).Count.Should().BeGreaterThan(0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
28
test/raven-integration/Privacy/Privacy.cs
Normal file
28
test/raven-integration/Privacy/Privacy.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Privacy
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void LogShouldNotContainPrivateData()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("AyaType", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
|
||||
ApiTextResponse t = await Util.GetTextResultAsync("LogFiles/log-ayanova.txt", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
t.TextResponse.Should().NotContain("TEST_PRIVACY_USER_ACCOUNT");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
79
test/raven-integration/ServerState/ServerStateTest.cs
Normal file
79
test/raven-integration/ServerState/ServerStateTest.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Xunit;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ServerStateTest
|
||||
{
|
||||
|
||||
|
||||
// ApiFixture fixture;
|
||||
|
||||
// public ServerStateTest(ApiFixture _fixture)
|
||||
// {
|
||||
// this.fixture = _fixture;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test get state
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerStateShouldReturnOk()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("ServerState");
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//can't test this because it fucks up other tests and the fixture
|
||||
|
||||
// /// <summary>
|
||||
// /// Test set state
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async void ServerStateShouldSet()
|
||||
// {
|
||||
|
||||
// /*{
|
||||
// "serverState": "open"
|
||||
// } */
|
||||
|
||||
|
||||
// //open
|
||||
// dynamic dd = new JObject();
|
||||
// dd.serverState = "open";
|
||||
|
||||
// ApiResponse aa = await Util.PostAsync("ServerState", fixture.ManagerAuthToken, dd.ToString());
|
||||
// Util.ValidateHTTPStatusCode(aa, 204);
|
||||
|
||||
// //close
|
||||
// dynamic d = new JObject();
|
||||
// d.serverState = "closed";
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("ServerState", fixture.ManagerAuthToken, d.ToString());
|
||||
// Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
// //open
|
||||
// dynamic ddd = new JObject();
|
||||
// dd.serverState = "open";
|
||||
|
||||
// ApiResponse aaa = await Util.PostAsync("ServerState", fixture.ManagerAuthToken, ddd.ToString());
|
||||
// Util.ValidateHTTPStatusCode(aaa, 204);
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
106
test/raven-integration/Tags/TagCrud.cs
Normal file
106
test/raven-integration/Tags/TagCrud.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class TagCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a widget
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"name": "TestTag"
|
||||
}
|
||||
*/
|
||||
|
||||
//CREATE
|
||||
dynamic w1 = new JObject();
|
||||
w1.name = Util.Uniquify("TeStTaG");
|
||||
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long tagId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
string tagName = a.ObjectResponse["result"]["name"].Value<string>();
|
||||
tagName.Should().StartWith("testtag");
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
/*
|
||||
{
|
||||
"result": {
|
||||
"id": 24,
|
||||
"created": "2018-03-28T21:07:41.9703503Z",
|
||||
"concurrencyToken": 9502,
|
||||
"ownerId": 1,
|
||||
"name": "یونیکُد چیست؟"
|
||||
}
|
||||
}
|
||||
*/
|
||||
//Get one
|
||||
a = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["result"]["name"].Value<string>().Should().StartWith("testtag");
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
w1.Id = tagId;
|
||||
w1.name = Util.Uniquify("PutTestTag");
|
||||
w1.created = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
|
||||
w1.concurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
w1.OwnerId = 1L;
|
||||
|
||||
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"), w1.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(w1.name.ToString().ToLowerInvariant());
|
||||
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
//PATCH
|
||||
var newName = Util.Uniquify("PatchUpdate");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Tag/" + tagId.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("BizAdminFull"), patchJson);
|
||||
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
||||
|
||||
//check PATCH worked
|
||||
ApiResponse checkPATCHWorked = await Util.GetAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPATCHWorked);
|
||||
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName.ToLowerInvariant());
|
||||
|
||||
// //DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
82
test/raven-integration/Tags/TagLists.cs
Normal file
82
test/raven-integration/Tags/TagLists.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class TagLists
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PickListSearchRouteShouldWorkAsExpected()
|
||||
{
|
||||
List<long> createdTagList = new List<long>();
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
|
||||
|
||||
d.name = Util.Uniquify("Apple");
|
||||
ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("Applesauce");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("Apple-Tar-Tar");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("Apple-Tini");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("Apple-Pie");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("AppleJack");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
|
||||
//Get all
|
||||
a = await Util.GetAsync("Tag/picklist?Offset=1&Limit=25&q=ApPlE", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be at least 5 of them
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterThan(4);
|
||||
|
||||
|
||||
//Delete them all here (just a cleanup)
|
||||
foreach (long lId in createdTagList)
|
||||
{
|
||||
a = await Util.DeleteAsync("Tag/" + lId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
274
test/raven-integration/Tags/TagMapOps.cs
Normal file
274
test/raven-integration/Tags/TagMapOps.cs
Normal file
@@ -0,0 +1,274 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class TagMapOps
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test tagmap map unmap and etc
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void MapUnmapShouldWork()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"name": "TestTag"
|
||||
}
|
||||
*/
|
||||
|
||||
//CREATE TAG
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("test-tag-4-widget");
|
||||
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long tagId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE WIDGET
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify("WIDGET_TAG");
|
||||
w.created = DateTime.Now.ToString();
|
||||
w.dollarAmount = 1.11m;
|
||||
w.active = true;
|
||||
w.roles = 0;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("BizAdminFull"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long widgetId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//CREATE TAGMAP (tag the widget)
|
||||
/*
|
||||
{
|
||||
"tagId": 0,
|
||||
"tagToObjectId": 0,
|
||||
"tagToObjectType": 0
|
||||
}
|
||||
*/
|
||||
dynamic tm = new JObject();
|
||||
tm.tagId = tagId;
|
||||
tm.tagToObjectId = widgetId;
|
||||
tm.tagToObjectType = 2;//widget
|
||||
|
||||
|
||||
a = await Util.PostAsync("TagMap", await Util.GetTokenAsync("BizAdminFull"), tm.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long tagMapId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//VERIFY TAGMAP
|
||||
a = await Util.GetAsync("TagMap/" + tagMapId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["result"]["id"].Value<long>().Should().Be(tagMapId);
|
||||
|
||||
|
||||
//ATTEMPT TO DELETE TAG THAT HAS TAGMAP SHOULD FAIL with 2200 / 400
|
||||
a = await Util.DeleteAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateViolatesReferentialIntegrityError(a);
|
||||
|
||||
//TODO:
|
||||
//Test delete parent object deletes tagmaps (widget delete)
|
||||
|
||||
|
||||
//DELETE TAGMAP
|
||||
a = await Util.DeleteAsync("TagMap/" + tagMapId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//DELETE TAG
|
||||
a = await Util.DeleteAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//DELETE WIDGET
|
||||
a = await Util.DeleteAsync("Widget/" + widgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TagMapShouldDeleteWhenParentDeletes()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"name": "TestTag"
|
||||
}
|
||||
*/
|
||||
|
||||
//CREATE TAG
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("test-unmap-tag-4-widget");
|
||||
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long tagId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE WIDGET
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify("WIDGET_TAG_AUTO_UNMAP");
|
||||
w.created = DateTime.Now.ToString();
|
||||
w.dollarAmount = 1.11m;
|
||||
w.active = true;
|
||||
w.roles = 0;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("BizAdminFull"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long widgetId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//CREATE TAGMAP (tag the widget)
|
||||
/*
|
||||
{
|
||||
"tagId": 0,
|
||||
"tagToObjectId": 0,
|
||||
"tagToObjectType": 0
|
||||
}
|
||||
*/
|
||||
dynamic tm = new JObject();
|
||||
tm.tagId = tagId;
|
||||
tm.tagToObjectId = widgetId;
|
||||
tm.tagToObjectType = 2;//widget
|
||||
|
||||
|
||||
a = await Util.PostAsync("TagMap", await Util.GetTokenAsync("BizAdminFull"), tm.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long tagMapId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//VERIFY TAGMAP
|
||||
a = await Util.GetAsync("TagMap/" + tagMapId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["result"]["id"].Value<long>().Should().Be(tagMapId);
|
||||
|
||||
|
||||
//DELETE PARENT (WIDGET)
|
||||
a = await Util.DeleteAsync("Widget/" + widgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//VERIFY TAGMAP GONE
|
||||
a = await Util.GetAsync("TagMap/" + tagMapId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
|
||||
|
||||
////////////////////////
|
||||
//CLEANUP
|
||||
|
||||
//DELETE TAG
|
||||
a = await Util.DeleteAsync("Tag/" + tagId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TagMapListForObject()
|
||||
{
|
||||
List<long> createdTagList = new List<long>();
|
||||
|
||||
//CREATE a bunch of tags
|
||||
dynamic d = new JObject();
|
||||
|
||||
|
||||
d.name = Util.Uniquify("Red");
|
||||
ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("red-green");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("red-rum");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("red-dit");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
d.name = Util.Uniquify("red-tailed-hawk");
|
||||
a = await Util.PostAsync("Tag", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
createdTagList.Add(a.ObjectResponse["result"]["id"].Value<long>());
|
||||
|
||||
|
||||
//Create a widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify("WIDGET_4_TAG_LIST_TEST");
|
||||
w.created = DateTime.Now.ToString();
|
||||
w.dollarAmount = 1.11m;
|
||||
w.active = true;
|
||||
w.roles = 0;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("BizAdminFull"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long widgetId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
|
||||
//Tag all the tags to the widget
|
||||
dynamic tm = new JObject();
|
||||
foreach (long tagId in createdTagList)
|
||||
{
|
||||
tm.tagId = tagId;
|
||||
tm.tagToObjectId = widgetId;
|
||||
tm.tagToObjectType = 2;//widget
|
||||
|
||||
a = await Util.PostAsync("TagMap", await Util.GetTokenAsync("BizAdminFull"), tm.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
//GET TAGS FOR WIDGET
|
||||
dynamic tid = new JObject();
|
||||
tid.objectId = widgetId;
|
||||
tid.objectType = 2;//widget
|
||||
a = await Util.GetAsync("TagMap/TagsOnObject/", await Util.GetTokenAsync("BizAdminFull"), tid.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be at least 5 of them
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterOrEqualTo(createdTagList.Count);
|
||||
|
||||
//delete widget (which will delete tagmaps as well)
|
||||
a = await Util.DeleteAsync("Widget/" + widgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
|
||||
//CLEANUP TAGS
|
||||
foreach (long lId in createdTagList)
|
||||
{
|
||||
a = await Util.DeleteAsync("Tag/" + lId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
227
test/raven-integration/Widget/WidgetCrud.cs
Normal file
227
test/raven-integration/Widget/WidgetCrud.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class WidgetCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a widget
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"created": "2018-02-09T16:45:56.057Z",
|
||||
"dollarAmount": 0,
|
||||
"active": true,
|
||||
"roles": 0
|
||||
}
|
||||
*/
|
||||
//CREATE
|
||||
dynamic w1 = new JObject();
|
||||
w1.name = Util.Uniquify("First Test WIDGET");
|
||||
w1.created = DateTime.Now.ToString();
|
||||
w1.dollarAmount = 1.11m;
|
||||
w1.active = true;
|
||||
w1.roles = 0;
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
long w1Id = r1.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("Second Test WIDGET");
|
||||
w2.created = DateTime.Now.ToString();
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.roles = 0;
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
|
||||
w2.OwnerId = 1;
|
||||
w2.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
//PATCH
|
||||
var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST WIDGET");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
||||
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
||||
|
||||
//check PATCH worked
|
||||
ApiResponse checkPATCHWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPATCHWorked);
|
||||
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName);
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse a = await Util.GetAsync("Widget/999999", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("Widget/2q2", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(a, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerExceptionShouldErrorPropertly()
|
||||
{
|
||||
//Get non existant
|
||||
//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( "manager", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server alt exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerAltExceptionShouldErrorPropertly()
|
||||
{
|
||||
//Get non existant
|
||||
//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( "manager", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
w2.created = DateTime.Now.ToString();
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.roles = 0;
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
w2.OwnerId = 1;
|
||||
w2.concurrencyToken = OriginalConcurrencyToken - 1;//bad token
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PatchConcurrencyViolationShouldFail()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("PatchConcurrencyViolationShouldFail");
|
||||
w2.created = DateTime.Now.ToString();
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.roles = 0;
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
|
||||
//PATCH
|
||||
var newName = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATED VIA PATCH");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + (OriginalConcurrencyToken - 1).ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
||||
Util.ValidateConcurrencyError(PATCHTestResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
74
test/raven-integration/Widget/WidgetLists.cs
Normal file
74
test/raven-integration/Widget/WidgetLists.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class WidgetLists
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PickListSearchRouteShouldWorkAsExpected()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Soft PickListSearchRouteShouldWorkAsExpected");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("Widget/picklist?Offset=2&Limit=3&q=%25of%25", await Util.GetTokenAsync( "InventoryLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Paging test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PagingShouldWorkAsExpected()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("Widget/list?Offset=2&Limit=3", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert aAll contains at least two records
|
||||
((JArray)a.ObjectResponse["result"]).Count.Should().Be(3);
|
||||
|
||||
JObject jp = (JObject)a.ObjectResponse["paging"];
|
||||
jp["count"].Value<long>().Should().BeGreaterThan(5);
|
||||
jp["offset"].Value<int>().Should().Be(2);
|
||||
jp["limit"].Value<int>().Should().Be(3);
|
||||
jp["first"].Value<string>().Should().EndWith("&pageSize=3");
|
||||
jp["previous"].Value<string>().Should().EndWith("&pageSize=3");
|
||||
jp["next"].Value<string>().Should().EndWith("&pageSize=3");
|
||||
jp["last"].Value<string>().Should().EndWith("&pageSize=3");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
261
test/raven-integration/Widget/WidgetRights.cs
Normal file
261
test/raven-integration/Widget/WidgetRights.cs
Normal file
@@ -0,0 +1,261 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
// [Collection("APICOLLECTION")]
|
||||
public class WidgetRights
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not authorized error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldNotAllowUnauthenticatedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("Widget/list");
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient read rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldNotAllowReadUnauthorizedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("Widget/list", await Util.GetTokenAsync( "OpsAdminFull"));
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient create rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldNotAllowCreateUnauthorizedAccess()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldNotAllowCreateUnauthorizedAccess TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//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());
|
||||
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test owner rights to modify
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldAllowOwnerOnlyRightsUserToPatchOwn()
|
||||
{
|
||||
|
||||
// TECH FULL has owner only rights to widget
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldAllowOwnerOnlyRightsUserToPatchOwn TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "TechFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
//Now attempt to modify it via patch
|
||||
var newName = Util.Uniquify("ServerShouldAllowOwnerOnlyRightsUserToPatchOwn - UPDATED TEST WIDGET");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
a = await Util.PatchAsync("Widget/" + Id.ToString() + "/" + OriginalConcurrencyToken.ToString(), await Util.GetTokenAsync( "TechFull"), patchJson);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test owner rights fails to modify other creator object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned()
|
||||
{
|
||||
// TECH FULL has owner only rights to widget
|
||||
//INVENTORY FULL has full rights to widget
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
//Now TechFullAuthToken attempt to modify it via patch
|
||||
var newName = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned - UPDATED TEST WIDGET");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
a = await Util.PatchAsync("Widget/" + Id.ToString() + "/" + OriginalConcurrencyToken.ToString(), await Util.GetTokenAsync( "TechFull"), patchJson);
|
||||
//2004 unauthorized expected
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 401);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test owner rights to modify
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldAllowOwnerOnlyRightsUserToPutOwn()
|
||||
{
|
||||
|
||||
// TECH FULL has owner only rights to widget
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldAllowOwnerOnlyRightsUserToPutOwn TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "TechFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
|
||||
//Now attempt to modify it via patch
|
||||
var newName = Util.Uniquify("ServerShouldAllowOwnerOnlyRightsUserToPutOwn - UPDATED TEST WIDGET");
|
||||
d.OwnerId = 1;
|
||||
d.name = newName;
|
||||
d.concurrencyToken = OriginalConcurrencyToken;
|
||||
|
||||
a = await Util.PutAsync("Widget/" + Id.ToString(), await Util.GetTokenAsync( "TechFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test owner rights fails to modify other creator object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldDisAllowOwnerOnlyRightsUserToPutNonOwned()
|
||||
{
|
||||
// TECH FULL has owner only rights to widget
|
||||
//INVENTORY FULL has full rights to widget
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPutNonOwned TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//Now TechFullAuthToken attempt to modify it via patch
|
||||
var newName = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPutNonOwned - UPDATED TEST WIDGET");
|
||||
d.name = newName;
|
||||
a = await Util.PutAsync("Widget/" + Id.ToString(), await Util.GetTokenAsync( "TechFull"), d.ToString());
|
||||
//2004 unauthorized expected
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 401);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test owner rights to delete
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldAllowOwnerOnlyRightsUserToDelete()
|
||||
{
|
||||
|
||||
// TECH FULL has owner only rights to widget
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldAllowOwnerOnlyRightsUserToDelete TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "TechFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//Now attempt to delete it
|
||||
a = await Util.DeleteAsync("Widget/" + Id.ToString(), await Util.GetTokenAsync( "TechFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test owner rights fails to delete other creator object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned()
|
||||
{
|
||||
// TECH FULL has owner only rights to widget
|
||||
//INVENTORY FULL has full rights to widget
|
||||
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//Now attempt delete
|
||||
a = await Util.DeleteAsync("Widget/" + Id.ToString(), await Util.GetTokenAsync( "TechFull"));
|
||||
//2004 unauthorized expected
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 401);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
260
test/raven-integration/Widget/WidgetValidationTests.cs
Normal file
260
test/raven-integration/Widget/WidgetValidationTests.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class WidgetValidationTest
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test business rule should be active on new
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNewShouldBeActiveShouldWork()
|
||||
{
|
||||
//CREATE attempt with broken rules
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = false;//<--- BROKEN RULE new widget must be active = true!!
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Active", "InvalidValue");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test business rule name should be unique
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNameMustBeUnique()
|
||||
{
|
||||
//CREATE attempt with broken rules
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Now try to create again with same name
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "NotUnique");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNameRequired()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = "";
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNameLengthExceeded()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = new string('A', 256); ;
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "LengthExceeded", "255 max");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleOwnerIdMustExistOnUpdate()
|
||||
{
|
||||
//CREATE attempt with broken rules
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleOwnerIdMustExistOnUpdate TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
//Now put a change with no ownerId set
|
||||
d.active = false;
|
||||
a = await Util.PutAsync("Widget/" + Id.ToString(), await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "OwnerId", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleStartDateWithoutEndDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleStartDateWithoutEndDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.startDate = d.created;
|
||||
//NO END DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "EndDate", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEndDateWithoutStartDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEndDateWithoutStartDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.endDate = d.created;
|
||||
//NO START DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "StartDate", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEndDateBeforeStartDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEndDateBeforeStartDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.startDate = DateTime.Now.ToString();
|
||||
d.endDate = DateTime.Now.AddHours(-1).ToString();
|
||||
//NO START DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 0;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "StartDate", "StartDateMustComeBeforeEndDate");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEnumInvalidShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
|
||||
//NO END DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.roles = 99999;//<---BAD ROLE VALUE
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync( "InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Roles", "InvalidValue");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
17
test/raven-integration/raven-integration.csproj
Normal file
17
test/raven-integration/raven-integration.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<GenerateFullPaths>true</GenerateFullPaths>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
BIN
test/raven-integration/testdata/ayanova.data.dump.xxx.zip
vendored
Normal file
BIN
test/raven-integration/testdata/ayanova.data.dump.xxx.zip
vendored
Normal file
Binary file not shown.
BIN
test/raven-integration/testdata/test.png
vendored
Normal file
BIN
test/raven-integration/testdata/test.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
test/raven-integration/testdata/test.zip
vendored
Normal file
BIN
test/raven-integration/testdata/test.zip
vendored
Normal file
Binary file not shown.
373
test/raven-integration/util.cs
Normal file
373
test/raven-integration/util.cs
Normal file
@@ -0,0 +1,373 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public static class Util
|
||||
{
|
||||
private static HttpClient client { get; } = new HttpClient();
|
||||
|
||||
private static string API_BASE_URL = "http://localhost:7575/api/v8.0/";
|
||||
//private static string API_BASE_URL = "https://test.helloayanova.com/api/v8.0/";
|
||||
|
||||
public static string TEST_DATA_FOLDER = @"..\..\..\testdata\";
|
||||
|
||||
public static ConcurrentDictionary<string, string> authDict = new ConcurrentDictionary<string, string>();//10,32
|
||||
|
||||
public static string Uniquify(string s)
|
||||
{
|
||||
|
||||
return s + ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
public async static Task<string> GetTokenAsync(string login, string password = null)
|
||||
{
|
||||
// Console.WriteLine($"GetTokenAsync:{login}");
|
||||
//System.Diagnostics.Trace.WriteLine($"GetTokenAsync:{login}");
|
||||
|
||||
if (password == null)
|
||||
password = login;
|
||||
|
||||
if (!authDict.ContainsKey(login))
|
||||
{
|
||||
dynamic creds = new JObject();
|
||||
creds.login = login;
|
||||
creds.password = password;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Auth", null, creds.ToString());
|
||||
//Put this in when having concurrency issue during auth and old style dl token creation during login
|
||||
//ValidateDataReturnResponseOk(a);
|
||||
|
||||
authDict[login] = a.ObjectResponse["result"]["token"].Value<string>();
|
||||
}
|
||||
return authDict[login];
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool bInitialized = false;
|
||||
private static void init()
|
||||
{
|
||||
if (bInitialized) return;
|
||||
if (!System.IO.Directory.Exists(TEST_DATA_FOLDER))
|
||||
throw new ArgumentOutOfRangeException($"Test data folder {TEST_DATA_FOLDER} not found, current folder is {System.AppDomain.CurrentDomain.BaseDirectory}");
|
||||
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
bInitialized = true;
|
||||
}
|
||||
|
||||
public static string CleanApiRoute(string route)
|
||||
{
|
||||
route = route.TrimStart('/');
|
||||
return API_BASE_URL + route;
|
||||
}
|
||||
|
||||
public async static Task<ApiResponse> GetAsync(string route, string authToken = null, string bodyJsonData = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(bodyJsonData))
|
||||
requestMessage.Content = new StringContent(bodyJsonData, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
|
||||
public async static Task<ApiTextResponse> GetTextResultAsync(string route, string authToken = null, string bodyJsonData = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(bodyJsonData))
|
||||
requestMessage.Content = new StringContent(bodyJsonData, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiTextResponse() { HttpResponse = response, TextResponse = responseAsString };
|
||||
}
|
||||
|
||||
public static async Task<HttpResponseMessage> DownloadFileAsync(string route, string authToken = null)
|
||||
{
|
||||
|
||||
init();
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
return response;
|
||||
// if (response.IsSuccessStatusCode)
|
||||
// {
|
||||
// return await response.Content.ReadAsByteArrayAsync();
|
||||
// }
|
||||
|
||||
// return null;
|
||||
}
|
||||
|
||||
|
||||
public async static Task<ApiResponse> PostAsync(string route, string authToken = null, string postJson = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Post, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(postJson))
|
||||
requestMessage.Content = new StringContent(postJson, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
public async static Task<ApiResponse> PostFormDataAsync(string route, MultipartFormDataContent formContent, string authToken = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Post, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
requestMessage.Content = formContent;
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
|
||||
public async static Task<ApiResponse> PutAsync(string route, string authToken = null, string putJson = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Put, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(putJson))
|
||||
requestMessage.Content = new StringContent(putJson, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
|
||||
public async static Task<ApiResponse> PatchAsync(string route, string authToken = null, string patchJson = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var method = new HttpMethod("PATCH");
|
||||
|
||||
var requestMessage = new HttpRequestMessage(method, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(patchJson))
|
||||
requestMessage.Content = new StringContent(patchJson, System.Text.Encoding.UTF8, "application/json-patch+json");
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
|
||||
public async static Task<ApiResponse> DeleteAsync(string route, string authToken = null)
|
||||
{
|
||||
init();
|
||||
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Delete, CleanApiRoute(route));
|
||||
if (!string.IsNullOrWhiteSpace(authToken))
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(requestMessage);
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="jsonString"></param>
|
||||
/// <returns></returns>
|
||||
private static JObject Parse(string jsonString)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(jsonString))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return JObject.Parse(jsonString);
|
||||
}
|
||||
|
||||
//https://www.newtonsoft.com/json/help/html/FromObject.htm
|
||||
private static string ObjectToJsonString(object o)
|
||||
{
|
||||
JObject j = (JObject)JToken.FromObject(o);
|
||||
return j.ToString();
|
||||
}
|
||||
|
||||
public static void ValidateDataReturnResponseOk(ApiResponse a)
|
||||
{
|
||||
a.ObjectResponse["error"].Should().BeNull("There should not be an error on an api call");
|
||||
a.ObjectResponse["result"].Should().NotBeNull("A result should be returned");
|
||||
}
|
||||
|
||||
public static void ValidateNoErrorInResponse(ApiResponse a)
|
||||
{
|
||||
a.ObjectResponse["error"].Should().BeNull("There should not be an error on an api call");
|
||||
}
|
||||
|
||||
public static void ValidateHTTPStatusCode(ApiResponse a, int DesiredStatusCode)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(DesiredStatusCode);
|
||||
}
|
||||
|
||||
public static void ValidateHTTPStatusCode(ApiTextResponse t, int DesiredStatusCode)
|
||||
{
|
||||
((int)t.HttpResponse.StatusCode).Should().Be(DesiredStatusCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// validate a not found response
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
public static void ValidateResponseNotFound(ApiResponse a)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(404);
|
||||
a.ObjectResponse["error"].Should().NotBeNull("There should be an error on the api call");
|
||||
a.ObjectResponse["error"]["code"].Value<int>().Should().Be(2010);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// validate a concurrency error
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
public static void ValidateConcurrencyError(ApiResponse a)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(409);
|
||||
a.ObjectResponse["error"].Should().NotBeNull("There should be an error on the api call");
|
||||
a.ObjectResponse["error"]["code"].Value<int>().Should().Be(2005);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// validate that the call violates referential integrity
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
public static void ValidateViolatesReferentialIntegrityError(ApiResponse a)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(400);
|
||||
a.ObjectResponse["error"].Should().NotBeNull("There should be an error on the api call");
|
||||
a.ObjectResponse["error"]["code"].Value<int>().Should().Be(2200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// validate a bad ModelState response
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
public static void ValidateBadModelStateResponse(ApiResponse a, string CheckFirstTargetExists = null)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(400);
|
||||
a.ObjectResponse["error"].Should().NotBeNull("There should be an error on the api call");
|
||||
a.ObjectResponse["error"]["code"].Value<int>().Should().Be(2200);
|
||||
a.ObjectResponse["error"]["details"].Should().NotBeNull("There should be error details on the api call");
|
||||
if (!string.IsNullOrWhiteSpace(CheckFirstTargetExists))
|
||||
{
|
||||
a.ObjectResponse["error"]["details"][0]["target"].Value<string>().Should().Be(CheckFirstTargetExists);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// public enum ValidationErrorType
|
||||
// {
|
||||
// RequiredPropertyEmpty = 1,
|
||||
// LengthExceeded = 2,
|
||||
// NotUnique = 3,
|
||||
// StartDateMustComeBeforeEndDate = 4,
|
||||
// InvalidValue = 5
|
||||
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// assert contains validation target and error code
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="error"></param>
|
||||
public static void ShouldContainValidationError(ApiResponse a, string target, string error, string message = null)
|
||||
{
|
||||
a.ObjectResponse["error"]["details"].Should().NotBeNull("There should be Details on the api call");
|
||||
if (message != null)
|
||||
{
|
||||
a.ObjectResponse["error"]["details"].Should().Contain(
|
||||
m => m["target"].Value<string>() == target &&
|
||||
m["error"].Value<string>() == error &&
|
||||
m["message"].Value<string>() == message);
|
||||
}
|
||||
else
|
||||
{
|
||||
a.ObjectResponse["error"]["details"].Should().Contain(m => m["target"].Value<string>() == target && m["error"].Value<string>() == error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// validate server exception response
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
public static void ValidateServerExceptionResponse(ApiResponse a)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(500);
|
||||
a.ObjectResponse["error"].Should().NotBeNull("There should be an error on the api call");
|
||||
a.ObjectResponse["error"]["code"].Value<int>().Should().Be(2002);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validate an expected api error code and http code response
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="apiErrorCode"></param>
|
||||
/// <param name="httpStatusCode"></param>
|
||||
public static void ValidateErrorCodeResponse(ApiResponse a, int apiErrorCode, int httpStatusCode)
|
||||
{
|
||||
((int)a.HttpResponse.StatusCode).Should().Be(httpStatusCode);
|
||||
a.ObjectResponse["error"].Should().NotBeNull("There should be an error on the api call");
|
||||
a.ObjectResponse["error"]["code"].Value<int>().Should().Be(apiErrorCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user