4648
This commit is contained in:
@@ -1,199 +1,199 @@
|
||||
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",
|
||||
"dollarAmount": 0,
|
||||
"active": true,
|
||||
"roles": 0
|
||||
}
|
||||
*/
|
||||
//CREATE
|
||||
dynamic w1 = new JObject();
|
||||
w1.name = Util.Uniquify("First Test WIDGET");
|
||||
w1.dollarAmount = 1.11m;
|
||||
w1.active = true;
|
||||
w1.usertype = 1;
|
||||
w1.notes = "The quick brown fox jumped over the six lazy dogs!";
|
||||
w1.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
//Tags
|
||||
dynamic dTagsArray = new JArray();
|
||||
dTagsArray.Add("Red Tag");
|
||||
dTagsArray.Add("ORANGE IS THE NEW BLACK");
|
||||
dTagsArray.Add("yellow");
|
||||
dTagsArray.Add("green");
|
||||
dTagsArray.Add("blue");
|
||||
dTagsArray.Add("indigo");
|
||||
dTagsArray.Add("VIOLET Tag");
|
||||
w1.tags = dTagsArray;
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
long w1Id = r1.ObjectResponse["data"]["id"].Value<long>();
|
||||
((long)r1.ObjectResponse["data"]["serial"]).Should().NotBe(0);
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("Second Test WIDGET");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "What is the frequency Kenneth?";
|
||||
w2.tags = dTagsArray;
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
r3.ObjectResponse["data"]["notes"].Value<string>().Should().Be(w2.notes.ToString());
|
||||
var returnedTags = ((JArray)r3.ObjectResponse["data"]["tags"]);
|
||||
returnedTags.Count.Should().Be(7);
|
||||
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
|
||||
w2.id = w2Id;
|
||||
w2.serial = 123456L;
|
||||
w2.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
checkPUTWorked.ObjectResponse["data"]["serial"].Value<long>().Should().Be(123456L);
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "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("superuser", "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("superuser", "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("superuser", "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("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "blah";
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
w2 = r2.ObjectResponse["data"];
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
w2.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
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 Task CRUD()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"dollarAmount": 0,
|
||||
"active": true,
|
||||
"roles": 0
|
||||
}
|
||||
*/
|
||||
//CREATE
|
||||
dynamic w1 = new JObject();
|
||||
w1.name = Util.Uniquify("First Test WIDGET");
|
||||
w1.dollarAmount = 1.11m;
|
||||
w1.active = true;
|
||||
w1.usertype = 1;
|
||||
w1.notes = "The quick brown fox jumped over the six lazy dogs!";
|
||||
w1.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
//Tags
|
||||
dynamic dTagsArray = new JArray();
|
||||
dTagsArray.Add("Red Tag");
|
||||
dTagsArray.Add("ORANGE IS THE NEW BLACK");
|
||||
dTagsArray.Add("yellow");
|
||||
dTagsArray.Add("green");
|
||||
dTagsArray.Add("blue");
|
||||
dTagsArray.Add("indigo");
|
||||
dTagsArray.Add("VIOLET Tag");
|
||||
w1.tags = dTagsArray;
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
long w1Id = r1.ObjectResponse["data"]["id"].Value<long>();
|
||||
((long)r1.ObjectResponse["data"]["serial"]).Should().NotBe(0);
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("Second Test WIDGET");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "What is the frequency Kenneth?";
|
||||
w2.tags = dTagsArray;
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
r3.ObjectResponse["data"]["notes"].Value<string>().Should().Be(w2.notes.ToString());
|
||||
var returnedTags = ((JArray)r3.ObjectResponse["data"]["tags"]);
|
||||
returnedTags.Count.Should().Be(7);
|
||||
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
|
||||
w2.id = w2Id;
|
||||
w2.serial = 123456L;
|
||||
w2.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
checkPUTWorked.ObjectResponse["data"]["serial"].Value<long>().Should().Be(123456L);
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse a = await Util.GetAsync("widget/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(a, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server alt exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "blah";
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
w2 = r2.ObjectResponse["data"];
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
w2.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
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/listwidgets", await Util.GetTokenAsync( "OpsAdminFull"));
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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.usertype = 1;
|
||||
|
||||
//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, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
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 Task ServerShouldNotAllowUnauthenticatedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("widget/list");
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient read rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerShouldNotAllowReadUnauthorizedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("widget/listwidgets", await Util.GetTokenAsync( "OpsAdminFull"));
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient create rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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.usertype = 1;
|
||||
|
||||
//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, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,239 +1,239 @@
|
||||
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.usertype = 1;
|
||||
|
||||
// //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", "2203");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <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.notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//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", "2206");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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.usertype = 1;
|
||||
|
||||
//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);
|
||||
//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
|
||||
Util.ShouldContainValidationError(a, "Name", "2203");
|
||||
|
||||
}
|
||||
|
||||
/// <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.usertype = 1;
|
||||
|
||||
//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", "2202", "255 max");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <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.usertype = 1;
|
||||
|
||||
//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", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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.usertype = 1;
|
||||
|
||||
//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", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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.usertype = 1;
|
||||
|
||||
//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", "2207");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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.usertype = -1;//<---BAD VALUE
|
||||
d.Notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
//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, "UserType", "2203");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
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 Task 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.usertype = 1;
|
||||
|
||||
// //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", "2203");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test business rule name should be unique
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleNameMustBeUnique()
|
||||
{
|
||||
//CREATE attempt with broken rules
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET");
|
||||
d.notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//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", "2206");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleNameRequired()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = "";
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//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);
|
||||
//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
|
||||
Util.ShouldContainValidationError(a, "Name", "2203");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleNameLengthExceeded()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = new string('A', 256); ;
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//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", "2202", "255 max");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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.usertype = 1;
|
||||
|
||||
//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", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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.usertype = 1;
|
||||
|
||||
//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", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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.usertype = 1;
|
||||
|
||||
//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", "2207");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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.usertype = -1;//<---BAD VALUE
|
||||
d.Notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
//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, "UserType", "2203");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
Reference in New Issue
Block a user