This commit is contained in:
2018-08-28 18:09:44 +00:00
parent 57334c65ae
commit 12c0d7b507
2 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
using System;
using Xunit;
using Newtonsoft.Json.Linq;
using FluentAssertions;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace raven_integration
{
public class EventLog
{
/// <summary>
///
/// </summary>
[Fact]
public async void ObjectLogWorks()
{
//CRUD a widget and confirm it logs properly
//http://localhost:7575/api/v8.0/EventLog/UserLog?AyType=3&AyId=1
//http://localhost:7575/api/v8.0/EventLog/ObjectLog?AyType=2&AyId=242
//http://localhost:7575/api/v8.0/EventLog/UserLog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24
dynamic w = new JObject();
w.name = Util.Uniquify("EventLog Test WIDGET");
w.created = DateTime.Now.ToString();
w.dollarAmount = 2.22m;
w.active = true;
w.roles = 0;
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
Util.ValidateDataReturnResponseOk(r2);
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
//RETRIEVE
//Get one
ApiResponse r3 = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateDataReturnResponseOk(r3);
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(w.name.ToString());
//UPDATE
//PUT
//update w2id
w.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
w.OwnerId = 1;
w.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"), w.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//check PUT worked
ApiResponse checkPUTWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateNoErrorInResponse(checkPUTWorked);
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(w.name.ToString());
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
//PATCH
var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST WIDGET");
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("InventoryFull"), patchJson);
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
//check PATCH worked
ApiResponse checkPATCHWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateNoErrorInResponse(checkPATCHWorked);
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName);
//DELETE
ApiResponse DELETETestResponse = await Util.DeleteAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
ApiTextResponse t = await Util.GetTextResultAsync("EventLog/", await Util.GetTokenAsync("BizAdminFull"));
Util.ValidateHTTPStatusCode(t, 200);
t.TextResponse.Should().Contain("|INFO|");//assumes any log will have at least one INFO log item in it
}
//==================================================
}//eoc
}//eons