415 lines
16 KiB
C#
415 lines
16 KiB
C#
using System.Linq;
|
|
using Xunit;
|
|
using Newtonsoft.Json.Linq;
|
|
using FluentAssertions;
|
|
|
|
namespace raven_integration
|
|
{
|
|
|
|
public class WorkOrderCrud
|
|
{
|
|
|
|
/// <summary>
|
|
/// Test all CRUD routes for a WorkOrder
|
|
/// Build up graph, update graph, remove graph bit by bit
|
|
/// </summary>
|
|
[Fact]
|
|
public async void CRUD()
|
|
{
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// CREATE
|
|
//
|
|
dynamic d = new JObject();
|
|
d.active = true;
|
|
d.notes = "WOHEADER The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# WOHEADER test wiki";
|
|
|
|
//Tags
|
|
dynamic dTagsArray = new JArray();
|
|
dTagsArray.Add("wo-Red");
|
|
dTagsArray.Add("wo-green");
|
|
dTagsArray.Add("wo-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
ApiResponse a = await Util.PostAsync("workorders", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
dynamic WorkorderToUpdate = a.ObjectResponse["data"];
|
|
long WorkOrderId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
#region CREATE first woitem
|
|
|
|
//CREATE WOITEM 1
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# woitem test wiki";
|
|
d.workOrderId = WorkOrderId;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitem-Red");
|
|
dTagsArray.Add("woitem-green");
|
|
dTagsArray.Add("woitem-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
dynamic WorkOrderItemToUpdate = a.ObjectResponse["data"];
|
|
|
|
long WorkOrderItem1Id = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
|
|
//CREATE WOITEMPART
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitempart The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# woitempart test wiki";
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitempart-Red");
|
|
dTagsArray.Add("woitempart-green");
|
|
dTagsArray.Add("woitempart-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items/parts", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
dynamic dPartToUpdate = a.ObjectResponse["data"];
|
|
long PartId = (long)a.ObjectResponse["data"]["id"];
|
|
|
|
|
|
//CREATE TWO WOITEMLABORS
|
|
//ONE
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitemlabor The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# woitemlabor test wiki";
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitemlabor-Red");
|
|
dTagsArray.Add("woitemlabor-green");
|
|
dTagsArray.Add("woitemlabor-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
dynamic dLaborOne = a.ObjectResponse["data"];
|
|
long Labor1Id = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//TWO
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitemlabor2 The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# woitemlabor2 test wiki";
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitemlabor-Red");
|
|
dTagsArray.Add("woitemlabor-green");
|
|
dTagsArray.Add("woitemlabor-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long WorkOrderItemLaborId2 = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
#endregion create first woitem
|
|
|
|
#region CREATE Second woitem
|
|
/////////////////////////////////////////
|
|
// Second woitem
|
|
//
|
|
|
|
//CREATE WOITEM-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2";
|
|
d.wiki = "# woitem test wiki";
|
|
d.workOrderId = WorkOrderId;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitem-Red");
|
|
dTagsArray.Add("woitem-green");
|
|
dTagsArray.Add("woitem-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long WorkOrderItem2Id = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
|
|
//CREATE WOITEMPART-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-part";
|
|
d.wiki = "# woitempart test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitempart-Red");
|
|
dTagsArray.Add("woitempart-green");
|
|
dTagsArray.Add("woitempart-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items/parts", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//CREATE WOITEMLABOR(S)-2
|
|
|
|
//ONE-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-labor The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# woitemlabor test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitemlabor-Red");
|
|
dTagsArray.Add("woitemlabor-green");
|
|
dTagsArray.Add("woitemlabor-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//TWO-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-labor2 The quick brown fox jumped over the six lazy dogs!";
|
|
d.wiki = "# woitemlabor2 test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("woitemlabor-Red");
|
|
dTagsArray.Add("woitemlabor-green");
|
|
dTagsArray.Add("woitemlabor-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorders/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
#endregion create second woitem
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
//UPDATES
|
|
//
|
|
|
|
dLaborOne.notes = "UpdatedLaborNotes";
|
|
a = await Util.PutAsync("workorders/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), dLaborOne.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
dPartToUpdate.notes = "UpdatedPartNotes";
|
|
a = await Util.PutAsync("workorders/items/parts", await Util.GetTokenAsync("manager", "l3tm3in"), dPartToUpdate.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
WorkOrderItemToUpdate.notes = "UpdatedWoItemNotes";
|
|
a = await Util.PutAsync("workorders/items", await Util.GetTokenAsync("manager", "l3tm3in"), WorkOrderItemToUpdate.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
WorkorderToUpdate.notes = "UpdatedWoNotes";
|
|
a = await Util.PutAsync("workorders", await Util.GetTokenAsync("manager", "l3tm3in"), WorkorderToUpdate.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//RETRIEVE WORKORDER AND VALIDATE ENTIRE
|
|
a = await Util.GetAsync("workorders/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
var w = a.ObjectResponse["data"];
|
|
w["items"].Count().Should().Be(2);
|
|
((string)w["notes"]).Should().Be("UpdatedWoNotes");
|
|
|
|
|
|
var woitem1 = w["items"].FirstOrDefault(z => (long)z["id"] == WorkOrderItem1Id);
|
|
woitem1["labors"].Count().Should().Be(2);
|
|
woitem1["parts"].Count().Should().Be(1);
|
|
((string)woitem1["notes"]).Should().Be("UpdatedWoItemNotes");
|
|
((string)woitem1["labors"].FirstOrDefault(z => (long)z["id"] == Labor1Id)["notes"]).Should().Be("UpdatedLaborNotes");
|
|
((string)woitem1["parts"].FirstOrDefault(z => (long)z["id"] == PartId)["notes"]).Should().Be("UpdatedPartNotes");
|
|
|
|
var woitem2 = w["items"].FirstOrDefault(z => (long)z["id"] == WorkOrderItem2Id);
|
|
woitem2["labors"].Count().Should().Be(2);
|
|
woitem2["parts"].Count().Should().Be(1);
|
|
((string)woitem2["notes"]).Should().Be("woitem-2");
|
|
woitem2["labors"].FirstOrDefault(z => (string)z["notes"] == "woitem-2-labor2 The quick brown fox jumped over the six lazy dogs!").Should().NotBeNull();
|
|
woitem2["parts"].FirstOrDefault(z => (string)z["notes"] == "woitem-2-part").Should().NotBeNull();
|
|
woitem2["parts"].FirstOrDefault(z => (string)z["notes"] == "bogus").Should().BeNull();
|
|
|
|
|
|
|
|
|
|
// //UPDATE
|
|
|
|
// d.name = Util.Uniquify("UPDATED VIA PUT TEST WorkOrder");
|
|
|
|
// d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
|
// a = await Util.PutAsync("WorkOrder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
// Util.ValidateHTTPStatusCode(a, 200);
|
|
|
|
// //check PUT worked
|
|
// a = await Util.GetAsync("WorkOrder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
// Util.ValidateNoErrorInResponse(a);
|
|
// a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
|
|
// uint concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
|
|
|
//todo: delete extra labor
|
|
//todo: delete woitem
|
|
//todo: delete wo outright
|
|
|
|
// //DELETE
|
|
// a = await Util.DeleteAsync("WorkOrder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
// Util.ValidateHTTPStatusCode(a, 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("WorkOrder/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("WorkOrder/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("WorkOrder/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("WorkOrder/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.dollarAmount = 2.22m;
|
|
// w2.active = true;
|
|
// w2.usertype = 1;
|
|
|
|
// w2.notes = "blah";
|
|
// w2.customFields = Util.WorkOrderRequiredCustomFieldsJsonString();
|
|
|
|
|
|
// ApiResponse r2 = await Util.PostAsync("WorkOrder", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
|
// Util.ValidateDataReturnResponseOk(r2);
|
|
// long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
|
// uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
|
|
|
|
|
|
|
// //UPDATE
|
|
// //PUT
|
|
|
|
// w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
|
|
|
// w2.concurrencyToken = OriginalConcurrencyToken - 1;//bad token
|
|
// ApiResponse PUTTestResponse = await Util.PutAsync("WorkOrder/" + 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.notes = "blah";
|
|
// w2.customFields = Util.WorkOrderRequiredCustomFieldsJsonString();
|
|
// w2.dollarAmount = 2.22m;
|
|
// w2.active = true;
|
|
// w2.usertype = 1;
|
|
// w2.customFields = Util.WorkOrderRequiredCustomFieldsJsonString();
|
|
|
|
// ApiResponse r2 = await Util.PostAsync("WorkOrder", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
|
// Util.ValidateDataReturnResponseOk(r2);
|
|
// long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
|
// uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["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("WorkOrder/" + w2Id.ToString() + "/" + (OriginalConcurrencyToken - 1).ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
|
// Util.ValidateConcurrencyError(PATCHTestResponse);
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|