4648
This commit is contained in:
75
Vendor/VendorCrud.cs
vendored
Normal file
75
Vendor/VendorCrud.cs
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class VendorCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Full CRUD for a Vendor, including concurrency violation and alert retrieval.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
var token = await Util.GetTokenAsync("BizAdmin");
|
||||
|
||||
// CREATE
|
||||
var name = Util.Uniquify("Test Vendor");
|
||||
var payload = $$"""
|
||||
{"id":0,"concurrency":0,"name":"{{name}}","active":true,"notes":"Test vendor notes","wiki":null,"customFields":"{\"c1\":\"test\"}","tags":[],"contact":null,"contactNotes":null,"alertNotes":"Vendor alert test text","webAddress":null,"accountNumber":null,"phone1":"555-1234","phone2":null,"phone3":null,"phone4":null,"phone5":null,"emailAddress":null,"postAddress":null,"postCity":null,"postRegion":null,"postCountry":null,"postCode":null,"address":null,"city":null,"region":null,"country":null,"addressPostal":null,"latitude":null,"longitude":null}
|
||||
""";
|
||||
|
||||
ApiResponse a = await Util.PostAsync("vendor", token, payload);
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long Id = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
Id.Should().BeGreaterThan(0);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(name);
|
||||
|
||||
// GET
|
||||
a = await Util.GetAsync($"vendor/{Id}", token);
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(name);
|
||||
a.ObjectResponse["data"]["phone1"].Value<string>().Should().Be("555-1234");
|
||||
var concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
// GET ALERT
|
||||
a = await Util.GetAsync($"vendor/alert/{Id}", token);
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"].Value<string>().Should().Be("Vendor alert test text");
|
||||
|
||||
// PUT (update name and phone)
|
||||
var updatedName = Util.Uniquify("Updated Vendor");
|
||||
var putPayload = $$"""
|
||||
{"id":{{Id}},"concurrency":{{concurrency}},"name":"{{updatedName}}","active":true,"notes":"Test vendor notes","wiki":null,"customFields":"{\"c1\":\"test\"}","tags":[],"contact":null,"contactNotes":null,"alertNotes":"Vendor alert test text","webAddress":null,"accountNumber":null,"phone1":"555-9999","phone2":null,"phone3":null,"phone4":null,"phone5":null,"emailAddress":null,"postAddress":null,"postCity":null,"postRegion":null,"postCountry":null,"postCode":null,"address":null,"city":null,"region":null,"country":null,"addressPostal":null,"latitude":null,"longitude":null}
|
||||
""";
|
||||
a = await Util.PutAsync("vendor", token, putPayload);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
var newConcurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
newConcurrency.Should().NotBe(concurrency, "concurrency should have been bumped by the update");
|
||||
|
||||
// Verify the update was persisted
|
||||
a = await Util.GetAsync($"vendor/{Id}", token);
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(updatedName);
|
||||
a.ObjectResponse["data"]["phone1"].Value<string>().Should().Be("555-9999");
|
||||
|
||||
// CONCURRENCY VIOLATION: PUT with stale concurrency should return 409
|
||||
a = await Util.PutAsync("vendor", token, putPayload); // putPayload still has old concurrency
|
||||
Util.ValidateConcurrencyError(a);
|
||||
|
||||
// DELETE
|
||||
a = await Util.DeleteAsync($"vendor/{Id}", token);
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
// Confirm deleted
|
||||
a = await Util.GetAsync($"vendor/{Id}", token);
|
||||
Util.ValidateResponseNotFound(a);
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user