diff --git a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/LocalTests.cs b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/LocalTests.cs index 294efbc..2488d4c 100644 --- a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/LocalTests.cs +++ b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/LocalTests.cs @@ -17,19 +17,12 @@ using Mocha.Core; using Mocha.Core.OmsImplementations; +using Mocha.Testing; namespace Mocha.Oms.Server.Tests; -public class LocalTests +public class LocalTests : OmsTestsBase { - public Mocha.Core.Oms? Oms { get; private set; } - - [SetUp] - public void SetUp() - { - Oms = new EmbeddedMiniOms(); - } - [Test] public void TestInstanceTaskWithGAS_GetGlobalIdentifier() { @@ -40,4 +33,4 @@ public class LocalTests Dictionary form = new Dictionary(); Response resp = Oms.ProcessElement(context, ProcessingInstance, form); } -} \ No newline at end of file +} diff --git a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/Mocha.Oms.Server.Tests.csproj b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/Mocha.Oms.Server.Tests.csproj index 2901ec2..f4b4d40 100644 --- a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/Mocha.Oms.Server.Tests.csproj +++ b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/Mocha.Oms.Server.Tests.csproj @@ -22,6 +22,7 @@ + diff --git a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/RemoteTests.cs b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/RemoteTests.cs index 9dac075..b73f924 100644 --- a/mocha-dotnet/tests/Mocha.Oms.Server.Tests/RemoteTests.cs +++ b/mocha-dotnet/tests/Mocha.Oms.Server.Tests/RemoteTests.cs @@ -2,6 +2,7 @@ using System.Data.SqlTypes; using System.Net; using System.Net.Http.Json; +using System.Runtime.CompilerServices; using System.Text.Json.Nodes; using Mocha.Core; using NUnit.Framework.Interfaces; @@ -22,6 +23,12 @@ public class RemoteTests int exitCode = program.Start(); } + protected int GetPort() + { + return 4436; + // return program.Port; + } + [TearDown] public void TearDown() { @@ -30,14 +37,18 @@ public class RemoteTests protected string? BuildUrl(string v) { - return String.Format("http://localhost:{0}{1}", program.Port, v); + return String.Format("http://localhost:{0}{1}", GetPort(), v); } + [Test] + public async Task Does_Test_Program_Boot() + { + Assert.That(program, Is.Not.Null); + } + [Test] public async Task Tenant_List_Test() { - Assert.That(program, Is.Not.Null); - HttpClient client = new HttpClient(); HttpResponseMessage resp = client.Send(new HttpRequestMessage(HttpMethod.Get, BuildUrl("/tenants"))); @@ -55,8 +66,6 @@ public class RemoteTests [Test] public async Task Instance_Json_Test() { - Assert.That(program, Is.Not.Null); - InstanceHandle h = program.Oms.GetInstance(KnownInstanceGuids.Classes.Class); InstanceKey k = program.Oms.GetInstanceKey(h); Guid g = program.Oms.GetGlobalIdentifier(h); @@ -79,8 +88,6 @@ public class RemoteTests [Test, TestCase("1$1"), TestCase("1$2"), TestCase("1$3"), TestCase("4$1"), TestCase("6$3")] public async Task Instance_Json_Test_Multi(string ik) { - Assert.That(program, Is.Not.Null); - InstanceHandle h = program.Oms.GetInstance(InstanceKey.Parse(ik)); InstanceKey k = program.Oms.GetInstanceKey(h); Guid g = program.Oms.GetGlobalIdentifier(h); @@ -99,13 +106,35 @@ public class RemoteTests Assert.That(new Guid(json["globalIdentifier"].ToString()), Is.EqualTo(g)); Assert.That(json["text"].ToString(), Is.EqualTo(sz)); } + + [Test] + public async Task Element_with_Parameters_Test() + { + InstanceHandle h = program.Oms.GetInstance(KnownInstanceGuids.Classes.Class); + InstanceKey k = program.Oms.GetInstanceKey(h); + Guid g = program.Oms.GetGlobalIdentifier(h); + string sz = program.Oms.GetInstanceText(h); + + HttpClient client = new HttpClient(); + + Dictionary coll = new Dictionary(); + coll["56$272"] = "86$1"; + HttpResponseMessage resp = client.Send(new HttpRequestMessage(HttpMethod.Post, BuildUrl("/tenants/super/instances/2997$48/element")) { Content = new FormUrlEncodedContent(coll) }); + + 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"]["widget"].ToString(), Is.EqualTo("root")); + } [Test] public async Task Element_Test() { - Assert.That(program, Is.Not.Null); - InstanceHandle h = program.Oms.GetInstance(KnownInstanceGuids.Classes.Class); InstanceKey k = program.Oms.GetInstanceKey(h); Guid g = program.Oms.GetGlobalIdentifier(h); @@ -127,15 +156,22 @@ public class RemoteTests [Test] public async Task Instance_Task_Test_with_GAS_Get_Global_Identifier() { - Assert.That(program, Is.Not.Null); - InstanceHandle h = program.Oms.GetInstance(KnownInstanceGuids.Classes.Class); InstanceKey k = program.Oms.GetInstanceKey(h); Guid g = program.Oms.GetGlobalIdentifier(h); string sz = program.Oms.GetInstanceText(h); HttpClient client = new HttpClient(); - HttpResponseMessage resp = client.Send(new HttpRequestMessage(HttpMethod.Get, BuildUrl("/tenants/super/instances/56$51/element"))); + HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, BuildUrl("/tenants/super/instances/56$51/element")); + + // when a related task is executed, the url is ~/d/inst/{iid}/rel-task/{task-iid}.htmld + // {iid} in this case is passed in as a Work Set to the related task + // how to determine what Work Set it should be passed in as? I don't think it's simply `Related Instance` + + Dictionary dict = new Dictionary(); + dict[KnownInstanceGuids.Classes.Instance.ToString("b")] = ""; + message.Content = new FormUrlEncodedContent(dict); + HttpResponseMessage resp = client.Send(message); Assert.That(resp.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.OK)); Assert.That(resp.Content.Headers.ContentType.ToString(), Is.EqualTo("application/json")); @@ -150,8 +186,6 @@ public class RemoteTests [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)))); @@ -168,8 +202,6 @@ public class RemoteTests [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") });