From f87ef70aae81b434d9dd40de527fa37dbbb77d50 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 26 Feb 2026 07:56:10 -0800 Subject: [PATCH] 4648 --- EventLog/EventLog.cs | 14 +- Project/WidgetCrud.cs | 171 ++++++++++++++++ {Widget => Project}/WidgetRights.cs | 0 {Widget => Project}/WidgetValidationTests.cs | 0 User/UserCrud.cs | 13 -- Widget/WidgetCrud.cs | 199 ------------------- util.cs | 1 - 7 files changed, 172 insertions(+), 226 deletions(-) create mode 100644 Project/WidgetCrud.cs rename {Widget => Project}/WidgetRights.cs (100%) rename {Widget => Project}/WidgetValidationTests.cs (100%) delete mode 100644 Widget/WidgetCrud.cs diff --git a/EventLog/EventLog.cs b/EventLog/EventLog.cs index 3eae7e5..d9aa32a 100644 --- a/EventLog/EventLog.cs +++ b/EventLog/EventLog.cs @@ -21,19 +21,7 @@ namespace raven_integration public async Task ObjectLogWorks() { //CRUD a project and confirm it logs properly - //http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1 - //http://localhost:7575/api/v8.0/event-log/objectlog?AyType=2&AyId=242 - //http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24 - - //dynamic w = new JObject(); - // w.name = Util.Uniquify("EventLog Test Project"); - // w.notes = "blah"; - // w.created = DateTime.Now.ToString(); - // w.dollarAmount = 2.22m; - // w.active = true; - // w.usertype = 1; - - + var projectName = Util.Uniquify("EventLogTestProject"); var dateStarted = DateTime.Now.ToString("o"); var payload = $$""" diff --git a/Project/WidgetCrud.cs b/Project/WidgetCrud.cs new file mode 100644 index 0000000..917d624 --- /dev/null +++ b/Project/WidgetCrud.cs @@ -0,0 +1,171 @@ +using System; +using Xunit; +using Newtonsoft.Json.Linq; +using FluentAssertions; + +namespace raven_integration +{ + + public class ProjectCrud + { + + /// + /// Test all CRUD routes for a project + /// + [Fact] + public async Task CRUD() + { + + //Tags + var TagNameStart = Util.Uniquify("crud-tag-test-") + "-";//ensure this run gets it's own unique tags + List TagsList = + [ + TagNameStart + "Red Tag", + TagNameStart + "ORANGE IS THE NEW BLACK", + TagNameStart + "yellow", + TagNameStart + "green", + TagNameStart + "blue", + TagNameStart + "indigo", + TagNameStart + "VIOLET Tag", + ]; + var tagsJson = string.Join(", ", TagsList.Select(t => $"\"{t}\"")); + + //CREATE + var projectName = Util.Uniquify("First Test PROJECT"); + var dateStarted = DateTime.Now.ToString("o"); + var payload = $$""" + {"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"The quick brown fox jumped over the six lazy dogs!","wiki":null,"customFields":"{}","tags":[{{tagsJson}}],"dateStarted":"{{dateStarted}}","dateCompleted":null,"projectOverseerId":null,"accountNumber":null} + """; + ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload); + Util.ValidateDataReturnResponseOk(a); + long FirstObjectId = a.ObjectResponse["data"]["id"].Value(); + ((long)a.ObjectResponse["data"]["serial"]).Should().NotBe(0); + //another + projectName = Util.Uniquify("Second Test PROJECT"); + payload = $$""" + {"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"What's the frequency Kenneth?","wiki":null,"customFields":"{}","tags":[{{tagsJson}}],"dateStarted":"{{dateStarted}}","dateCompleted":null,"projectOverseerId":null,"accountNumber":null} + """; + a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload); + Util.ValidateDataReturnResponseOk(a); + long SecondObjectId = a.ObjectResponse["data"]["id"].Value(); + + //RETRIEVE + a = await Util.GetAsync("project/" + SecondObjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); + Util.ValidateDataReturnResponseOk(a); + a.ObjectResponse["data"]["name"].Value().Should().Be("Second Test PROJECT"); + a.ObjectResponse["data"]["notes"].Value().Should().Be("What's the frequency Kenneth?"); + ((JArray)a.ObjectResponse["data"]["tags"]).Count.Should().Be(7); + + //UPDATE + var oUpdate = a.ObjectResponse["data"]; + oUpdate["name"] = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET"); + a = await Util.PutAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), oUpdate.ToString()); + Util.ValidateHTTPStatusCode(a, 200); + + //check PUT worked + a = await Util.GetAsync("project/" + SecondObjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); + Util.ValidateNoErrorInResponse(a); + a.ObjectResponse["data"]["name"].Value().Should().Be("UPDATED VIA PUT SECOND TEST WIDGET"); + + //DELETE + a = await Util.DeleteAsync("project/" + FirstObjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); + Util.ValidateHTTPStatusCode(a, 204); + a = await Util.DeleteAsync("project/" + SecondObjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); + Util.ValidateHTTPStatusCode(a, 204); + } + + + /// + /// Test not found + /// + [Fact] + public async Task GetNonExistentItemShouldError() + { + //Get non existant + //Should return status code 404, api error code 2010 + ApiResponse a = await Util.GetAsync("project/999999", await Util.GetTokenAsync("superuser", "l3tm3in")); + Util.ValidateResponseNotFound(a); + } + + // /// + // /// Test bad modelstate + // /// + // [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("project/2q2", await Util.GetTokenAsync("superuser", "l3tm3in")); + // Util.ValidateBadModelStateResponse(a, "id"); + // } + + + // /// + // /// Test server exception + // /// + // [Fact] + // public async Task ServerExceptionShouldErrorProperty() + // { + // //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("project/exception", await Util.GetTokenAsync("superuser", "l3tm3in")); + // Util.ValidateServerExceptionResponse(a); + // } + + + + // /// + // /// Test server alt exception + // /// + // [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("project/altexception", await Util.GetTokenAsync("superuser", "l3tm3in")); + // Util.ValidateServerExceptionResponse(a); + // } + + + + + /// + /// + /// + [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"; + + + + ApiResponse r2 = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString()); + Util.ValidateDataReturnResponseOk(r2); + uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value(); + 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("project/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString()); + Util.ValidateConcurrencyError(PUTTestResponse); + + } + + + + + //================================================== + + }//eoc +}//eons diff --git a/Widget/WidgetRights.cs b/Project/WidgetRights.cs similarity index 100% rename from Widget/WidgetRights.cs rename to Project/WidgetRights.cs diff --git a/Widget/WidgetValidationTests.cs b/Project/WidgetValidationTests.cs similarity index 100% rename from Widget/WidgetValidationTests.cs rename to Project/WidgetValidationTests.cs diff --git a/User/UserCrud.cs b/User/UserCrud.cs index e7dc143..e612bf9 100644 --- a/User/UserCrud.cs +++ b/User/UserCrud.cs @@ -95,19 +95,6 @@ namespace raven_integration a.ObjectResponse["error"]["details"][0]["target"].Value().Should().Be("generalerror"); a.ObjectResponse["error"]["details"][0]["error"].Value().Should().Be("2208");//referential integrity error } -// {{ -// "error": { -// "code": "2200", -// "details": [ -// { -// "message": "Memo", -// "target": "generalerror", -// "error": "2208" -// } -// ], -// "message": "ErrorAPI2200" -// } -// }} /// /// Test not found diff --git a/Widget/WidgetCrud.cs b/Widget/WidgetCrud.cs deleted file mode 100644 index ef5d111..0000000 --- a/Widget/WidgetCrud.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System; -using Xunit; -using Newtonsoft.Json.Linq; -using FluentAssertions; - -namespace raven_integration -{ - - public class WidgetCrud - { - - /// - /// Test all CRUD routes for a widget - /// - [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)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(); - - //RETRIEVE - - //Get one - ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); - Util.ValidateDataReturnResponseOk(r3); - r3.ObjectResponse["data"]["name"].Value().Should().Be(w2.name.ToString()); - r3.ObjectResponse["data"]["notes"].Value().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(); - 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().Should().Be(w2.name.ToString()); - checkPUTWorked.ObjectResponse["data"]["serial"].Value().Should().Be(123456L); - uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value(); - - //DELETE - ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); - Util.ValidateHTTPStatusCode(DELETETestResponse, 204); - } - - - - - - - /// - /// Test not found - /// - [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); - } - - /// - /// Test bad modelstate - /// - [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"); - } - - - /// - /// Test server exception - /// - [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); - } - - - - /// - /// Test server alt exception - /// - [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); - } - - - - - /// - /// - /// - [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(); - 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 diff --git a/util.cs b/util.cs index 1b4420c..c0c5d08 100644 --- a/util.cs +++ b/util.cs @@ -386,7 +386,6 @@ namespace raven_integration { ((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().Should().Be(2005); }