691 lines
29 KiB
C#
691 lines
29 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 = "no 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("workorder", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
dynamic WorkorderToUpdate = a.ObjectResponse["data"];
|
|
long WorkOrderId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
((long)a.ObjectResponse["data"]["serial"]).Should().NotBe(0);
|
|
|
|
#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("workorder/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("workorder/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("workorder/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("workorder/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("workorder/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("workorder/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("workorder/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("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//expense
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-expense";
|
|
d.wiki = "# expense test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("expense-Red");
|
|
dTagsArray.Add("expense-green");
|
|
dTagsArray.Add("expense-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/expenses", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long TestExpenseId = (long)a.ObjectResponse["data"]["id"];
|
|
|
|
|
|
//loan
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-loan";
|
|
d.wiki = "# loan test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("loan-Red");
|
|
dTagsArray.Add("loan-green");
|
|
dTagsArray.Add("loan-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/loans", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//partrequest
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "partrequest-2-partrequest";
|
|
d.wiki = "# partrequest test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("partrequest-Red");
|
|
dTagsArray.Add("partrequest-green");
|
|
dTagsArray.Add("partrequest-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/partrequests", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//scheduleduser
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-scheduleduser";
|
|
d.wiki = "# scheduleduser test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("scheduleduser-Red");
|
|
dTagsArray.Add("scheduleduser-green");
|
|
dTagsArray.Add("scheduleduser-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/scheduledusers", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//task
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-task";
|
|
d.wiki = "# task test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("task-Red");
|
|
dTagsArray.Add("task-green");
|
|
dTagsArray.Add("task-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/tasks", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//travel
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-travel";
|
|
d.wiki = "# travel test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("travel-Red");
|
|
dTagsArray.Add("travel-green");
|
|
dTagsArray.Add("travel-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/travels", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
//unit
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-unit";
|
|
d.wiki = "# unit test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
//Tags
|
|
dTagsArray = new JArray();
|
|
dTagsArray.Add("unit-Red");
|
|
dTagsArray.Add("unit-green");
|
|
dTagsArray.Add("unit-blue");
|
|
d.tags = dTagsArray;
|
|
|
|
a = await Util.PostAsync("workorder/items/units", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
#endregion create second woitem
|
|
|
|
#region UPDATE
|
|
/////////////////////////////////////////////////////////////////////////
|
|
//UPDATES
|
|
//
|
|
|
|
dLaborOne.notes = "UpdatedLaborNotes";
|
|
a = await Util.PutAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), dLaborOne.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
dPartToUpdate.notes = "UpdatedPartNotes";
|
|
a = await Util.PutAsync("workorder/items/parts", await Util.GetTokenAsync("manager", "l3tm3in"), dPartToUpdate.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
WorkOrderItemToUpdate.notes = "UpdatedWoItemNotes";
|
|
a = await Util.PutAsync("workorder/items", await Util.GetTokenAsync("manager", "l3tm3in"), WorkOrderItemToUpdate.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
WorkorderToUpdate.notes = "UpdatedWoNotes";
|
|
a = await Util.PutAsync("workorder", await Util.GetTokenAsync("manager", "l3tm3in"), WorkorderToUpdate.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
#endregion update
|
|
|
|
#region Validate all create and update
|
|
|
|
//RETRIEVE WORKORDER AND VALIDATE ENTIRE
|
|
a = await Util.GetAsync("workorder/" + 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();
|
|
|
|
woitem2["expenses"].Count().Should().Be(1);
|
|
woitem2["loans"].Count().Should().Be(1);
|
|
woitem2["partRequests"].Count().Should().Be(1);
|
|
woitem2["scheduledUsers"].Count().Should().Be(1);
|
|
woitem2["tasks"].Count().Should().Be(1);
|
|
woitem2["travels"].Count().Should().Be(1);
|
|
woitem2["units"].Count().Should().Be(1);
|
|
|
|
|
|
#endregion validate entire
|
|
|
|
|
|
//Test get ancestor route
|
|
var AyaTypeWorkOrderItemExpense = 36;
|
|
a = await Util.GetAsync($"search/ancestor/{AyaTypeWorkOrderItemExpense}/{TestExpenseId}", await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
|
|
#region DELETE
|
|
a = await Util.DeleteAsync("workorder/items/labors/" + Labor1Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
a = await Util.GetAsync("workorder/items/labors/" + Labor1Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 404);
|
|
|
|
a = await Util.DeleteAsync("workorder/items/" + WorkOrderItem2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
a = await Util.GetAsync("workorder/items/" + WorkOrderItem2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 404);
|
|
|
|
a = await Util.DeleteAsync("workorder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
a = await Util.GetAsync("workorder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 404);
|
|
|
|
#endregion delete
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
public async void ConfirmDeleteTransactionWorksAtServer()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
var BuildMode = (string)a.ObjectResponse["data"]["buildMode"];
|
|
|
|
if (BuildMode == "DEBUG")//The key phrase that triggers exception during delete only exists in debug builds of server
|
|
{
|
|
|
|
dynamic d = new JObject();
|
|
d.active = true;
|
|
d.notes = "WOHEADER";
|
|
d.wiki = "INTEGRATION_DELETE_TEST_FAIL_BEFORE_COMMIT";//<-- key phrase triggers server exception in Workorder immediately before it would normally commit the whole thing
|
|
|
|
a = await Util.PostAsync("workorder", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long WorkOrderId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE WOITEM 1
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderId = WorkOrderId;
|
|
a = await Util.PostAsync("workorder/items", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long WorkOrderItem1Id = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE WOITEMPART
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
a = await Util.PostAsync("workorder/items/parts", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//CREATE TWO WOITEMLABORS
|
|
//ONE
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
a = await Util.PostAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//TWO
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
a = await Util.PostAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//CREATE WOITEM-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderId = WorkOrderId;
|
|
a = await Util.PostAsync("workorder/items", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long WorkOrderItem2Id = (long)a.ObjectResponse["data"]["id"];
|
|
|
|
//CREATE WOITEMPART-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
a = await Util.PostAsync("workorder/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.workOrderItemId = WorkOrderItem2Id;
|
|
a = await Util.PostAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//TWO-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
a = await Util.PostAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
a = await Util.DeleteAsync("workorder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
|
|
|
//now confirm the workorder is still there and with it's children intact
|
|
//RETRIEVE WORKORDER AND VALIDATE ENTIRE
|
|
a = await Util.GetAsync("workorder/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
var w = a.ObjectResponse["data"];
|
|
w["items"].Count().Should().Be(2);
|
|
|
|
var woitem1 = w["items"].FirstOrDefault(z => (long)z["id"] == WorkOrderItem1Id);
|
|
woitem1["labors"].Count().Should().Be(2);
|
|
woitem1["parts"].Count().Should().Be(1);
|
|
|
|
var woitem2 = w["items"].FirstOrDefault(z => (long)z["id"] == WorkOrderItem2Id);
|
|
woitem2["labors"].Count().Should().Be(2);
|
|
woitem2["parts"].Count().Should().Be(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Test all CRUD routes for a WorkOrder
|
|
/// Build up graph, update graph, remove graph bit by bit
|
|
/// </summary>
|
|
[Fact]
|
|
public async void DuplicateWorks()
|
|
{
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// CREATE
|
|
//
|
|
dynamic d = new JObject();
|
|
d.active = true;
|
|
d.notes = "WOHEADER DuplicateWorks";
|
|
d.wiki = "DuplicateWorks integration test";
|
|
|
|
ApiResponse a = await Util.PostAsync("workorder", 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 DuplicateWorks";
|
|
d.wiki = "# woitem test wiki";
|
|
d.workOrderId = WorkOrderId;
|
|
|
|
a = await Util.PostAsync("workorder/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 DuplicateWorks";
|
|
// d.wiki = "# woitempart test wiki";
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
|
|
a = await Util.PostAsync("workorder/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 DuplicateWorks";
|
|
// d.wiki = "# woitemlabor test wiki";
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
|
|
|
|
a = await Util.PostAsync("workorder/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 DuplicateWorks";
|
|
// d.wiki = "# woitemlabor2 test wiki";
|
|
d.workOrderItemId = WorkOrderItem1Id;
|
|
|
|
|
|
a = await Util.PostAsync("workorder/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 DuplicateWorks";
|
|
d.wiki = "# woitem test wiki";
|
|
d.workOrderId = WorkOrderId;
|
|
|
|
a = await Util.PostAsync("workorder/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-partDuplicateWorks";
|
|
// d.wiki = "# woitempart test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
|
|
a = await Util.PostAsync("workorder/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-laborDuplicateWorks";
|
|
//d.wiki = "# woitemlabor test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
a = await Util.PostAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//TWO-2
|
|
d = new JObject();
|
|
d.active = true;
|
|
d.notes = "woitem-2-labor2DuplicateWorks";
|
|
//d.wiki = "# woitemlabor2 test wiki";
|
|
d.workOrderItemId = WorkOrderItem2Id;
|
|
a = await Util.PostAsync("workorder/items/labors", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
#endregion create second woitem
|
|
|
|
|
|
|
|
#region Duplicate and Validate
|
|
|
|
//DUPLICATE - should make a copy of above, save and return entire object graph just like a get operation
|
|
a = await Util.PostAsync("workorder/duplicate/" + WorkOrderId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long DuplicateWorkOrderId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
DuplicateWorkOrderId.Should().NotBe(WorkOrderId);
|
|
((long)a.ObjectResponse["data"]["serial"]).Should().NotBe(0);
|
|
|
|
// //RETRIEVE WORKORDER AND VALIDATE ENTIRE
|
|
// a = await Util.GetAsync("workorder/" + 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("WOHEADER DuplicateWorks");
|
|
|
|
|
|
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("woitem DuplicateWorks");
|
|
((string)woitem1["labors"].FirstOrDefault(z => (long)z["id"] == Labor1Id)["notes"]).Should().Be("woitemlabor DuplicateWorks");
|
|
((string)woitem1["parts"].FirstOrDefault(z => (long)z["id"] == PartId)["notes"]).Should().Be("woitempart DuplicateWorks");
|
|
|
|
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 DuplicateWorks");
|
|
woitem2["labors"].FirstOrDefault(z => (string)z["notes"] == "woitem-2-labor2DuplicateWorks").Should().NotBeNull();
|
|
woitem2["parts"].FirstOrDefault(z => (string)z["notes"] == "woitem-2-partDuplicateWorks").Should().NotBeNull();
|
|
|
|
#endregion validate entire
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|