diff --git a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/BasicTests.cs b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/BasicTests.cs index c6dca83..12eabb1 100644 --- a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/BasicTests.cs +++ b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/BasicTests.cs @@ -1,4 +1,5 @@ +using System.Data.SqlTypes; using System.Net; using System.Net.Http.Json; using System.Text.Json.Nodes; @@ -122,4 +123,47 @@ public class Tests Assert.That(json["result"].ToString(), Is.EqualTo("success")); Assert.That(json["value"]["widget"].ToString(), Is.EqualTo("root")); } + + [Test] + public async Task Globals_Test_Get_Empty_Value() + { + Assert.That(program, Is.Not.Null); + + HttpClient client = new HttpClient(); + HttpResponseMessage resp = client.Send(new HttpRequestMessage(HttpMethod.Get, BuildUrl(String.Format("/globals/{0}", KnownAttributeGuids.Text.ReferralURL)))); + + Assert.That(resp.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.OK)); + Assert.That(resp.Content.Headers.ContentType.ToString(), Is.EqualTo("application/json")); + + string content = await resp.Content.ReadAsStringAsync(); + + JsonObject json = JsonNode.Parse(content) as JsonObject; + Assert.That(json["result"].ToString(), Is.EqualTo("success")); + Assert.That(json["value"], Is.Null); + } + + [Test] + public async Task Globals_Test_Set_Value() + { + Assert.That(program, Is.Not.Null); + + HttpClient client = new HttpClient(); + HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, BuildUrl(String.Format("/globals/{0}", KnownAttributeGuids.Text.ReferralURL))); + msg.Content = new System.Net.Http.FormUrlEncodedContent(new KeyValuePair[] { new KeyValuePair("value", "test attribute value") }); + HttpResponseMessage resp = client.Send(msg); + + Assert.That(resp.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.OK)); + Assert.That(resp.Content.Headers.ContentType.ToString(), Is.EqualTo("application/json")); + + HttpResponseMessage resp2 = client.Send(new HttpRequestMessage(HttpMethod.Get, BuildUrl(String.Format("/globals/{0}", KnownAttributeGuids.Text.ReferralURL)))); + + Assert.That(resp2.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.OK)); + Assert.That(resp2.Content.Headers.ContentType.ToString(), Is.EqualTo("application/json")); + + string content = await resp2.Content.ReadAsStringAsync(); + + JsonObject json = JsonNode.Parse(content) as JsonObject; + Assert.That(json["result"].ToString(), Is.EqualTo("success")); + Assert.That(json["value"].ToString(), Is.EqualTo("test attribute value")); + } } \ No newline at end of file