From 9cda89829c6aa5d6d1c41fd54cfe1d5fff208e69 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 22 Oct 2025 20:06:47 -0400 Subject: [PATCH] improvements to OMS method builder and tests --- mocha-common | 2 +- .../src/lib/Mocha.Core/KnownInstanceGuids.cs | 3 ++ .../src/lib/Mocha.Core/OmsMethodBuilder.cs | 41 ++++++++++++++++++- .../src/lib/Mocha.Core/Oop/MethodBinding.cs | 5 +++ .../Methods/ProcessRelatedUpdatesMethod.cs | 25 +++++++++++ .../Oop/Methods/ProcessUpdatesMethod.cs | 25 +++++++++++ .../src/lib/Mocha.Core/Oop/PUMProcess.cs | 25 +++++++++++ .../MethodTests/MethodBindingTests.cs | 26 +++++------- .../MethodTests/SystemRoutineTests.cs | 41 +++++++++++++++++++ 9 files changed, 176 insertions(+), 17 deletions(-) create mode 100644 mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessRelatedUpdatesMethod.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessUpdatesMethod.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/Oop/PUMProcess.cs diff --git a/mocha-common b/mocha-common index 5a411dd..8bea362 160000 --- a/mocha-common +++ b/mocha-common @@ -1 +1 @@ -Subproject commit 5a411ddf69be2a2f32c601fe57004e839e3805c0 +Subproject commit 8bea362b3ca08a642ba196b8670e8e44e5e799e3 diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs index 3d7f9f3..5d52fc4 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs @@ -84,6 +84,8 @@ namespace Mocha.Core public static Guid ReturnInstanceSetMethodBinding { get; } = new Guid("{AADC20F9-7559-429B-AEF0-97E059295C76}"); public static Guid ReturnElementMethodBinding { get; } = new Guid("{f8944cc1-1306-4c60-8079-93448ca01fd0}"); public static Guid BuildResponseMethodBinding { get; } = new Guid("{b457f34f-1f54-4cda-be03-2da48ec747ab}"); + public static Guid ExecuteUpdateMethodBinding { get; } = new Guid("{b831bdaf-72d8-4585-a9a8-8341ab1005cb}"); + public static Guid ProcessUpdatesMethodBinding { get; } = new Guid("{a7eb8676-2e47-4981-96a7-f20158660d26}"); public static Guid Executable { get; } = new Guid("{6A1F66F7-8EA6-43D1-B2AF-198F63B84710}"); public static Guid ExecutableReturningAttribute { get; } = new Guid("{50b2db7a-3623-4be4-b40d-98fab89d3ff5}"); @@ -194,6 +196,7 @@ namespace Mocha.Core public static Guid RouteTable { get; } = new Guid("{76e5ce90-5f64-4355-a0ee-f659cf615a63}"); public static Guid Domain { get; } = new Guid("{49bbe159-0901-4788-b683-fd8f6d41b222}"); + public static Guid PUMProcess { get; } = new Guid("{2cdb2169-7c26-4adb-bc26-e9e75ab1b246}"); } public static class Methods { diff --git a/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs b/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs index 9072968..63e5eb2 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs @@ -25,7 +25,7 @@ namespace Mocha.Core; public class OmsMethodBuilder { - private InstanceHandle c_ReturnAttributeMethodBinding, c_ReturnInstanceSetMethodBinding, c_ReturnElementMethodBinding, c_BuildResponseMethodBinding; + private InstanceHandle c_ReturnAttributeMethodBinding, c_ReturnInstanceSetMethodBinding, c_ReturnElementMethodBinding, c_BuildResponseMethodBinding, c_ExecuteUpdateMethodBinding, c_ProcessUpdatesMethodBinding; public Oms Oms { get; } public OmsMethodBuilder(Oms oms) @@ -35,6 +35,9 @@ public class OmsMethodBuilder c_ReturnAttributeMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.ReturnAttributeMethodBinding); c_ReturnInstanceSetMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.ReturnInstanceSetMethodBinding); c_ReturnElementMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.ReturnElementMethodBinding); + c_BuildResponseMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.BuildResponseMethodBinding); + c_ExecuteUpdateMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.ExecuteUpdateMethodBinding); + c_ProcessUpdatesMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.ProcessUpdatesMethodBinding); } private InstanceHandle CreateMethodBindingBase(InstanceHandle parentClass, Method method, IEnumerable>? parameterAssignments) @@ -82,6 +85,18 @@ public class OmsMethodBuilder return new BuildResponseMethodBinding(methodBinding); } + public ExecuteUpdateMethodBinding CreateExecuteUpdateMethodBinding(Method method, IEnumerable>? parameterAssignments = null) + { + InstanceHandle methodBinding = CreateMethodBindingBase(c_ExecuteUpdateMethodBinding, method, parameterAssignments); + return new ExecuteUpdateMethodBinding(methodBinding); + } + + public ExecuteUpdateMethodBinding CreateProcessUpdatesMethodBinding(Method method, IEnumerable>? parameterAssignments = null) + { + InstanceHandle methodBinding = CreateMethodBindingBase(c_ProcessUpdatesMethodBinding, method, parameterAssignments); + return new ExecuteUpdateMethodBinding(methodBinding); + } + public GetAttributeMethod CreateGetAttributeMethod(IInstanceReference forClassInstance, string verb, string name, InstanceHandle attributeInstance) { return CreateGetAttributeMethod(forClassInstance, verb, name, null, false, attributeInstance); @@ -473,4 +488,28 @@ public class OmsMethodBuilder } return new InvokeWebServiceMethod(ih); } + + public PUMProcess CreatePUMProcess(IEnumerable executeUpdateMethodBindings) + { + InstanceHandle ih = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.PUMProcess)); + List list = new List(); + foreach (ExecuteUpdateMethodBinding eumb in executeUpdateMethodBindings) + { + list.Add(eumb.GetHandle()); + } + Oms.AssignRelationship(ih, Oms.GetInstance(KnownRelationshipGuids.PUM_Process__invokes__Execute_Update_Method_Binding), list); + return new PUMProcess(ih); + } + + public ProcessUpdatesMethod CreateProcessUpdatesMethod(IInstanceReference forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, IEnumerable executeUpdateMethodBindings) + { + PUMProcess pumProcess = CreatePUMProcess(executeUpdateMethodBindings); + return CreateProcessUpdatesMethod(forClassInstance, verb, name, accessModifier, isStatic, pumProcess); + } + public ProcessUpdatesMethod CreateProcessUpdatesMethod(IInstanceReference forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, PUMProcess pumProcess) + { + InstanceHandle ih = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.ProcessUpdatesMethod), forClassInstance, verb, name, accessModifier, isStatic); + Oms.AssignRelationship(ih, Oms.GetInstance(KnownRelationshipGuids.Process_Updates_Method__has__PUM_Process), pumProcess); + return new ProcessUpdatesMethod(ih); + } } \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/MethodBinding.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/MethodBinding.cs index 78b199e..bb084e3 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oop/MethodBinding.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/MethodBinding.cs @@ -41,4 +41,9 @@ public class BuildResponseMethodBinding : MethodBinding //, IExecutableBuildingR { public override Guid ClassId => KnownInstanceGuids.Classes.BuildResponseMethodBinding; internal BuildResponseMethodBinding(InstanceHandle handle) : base(handle) { } +} +public class ExecuteUpdateMethodBinding : MethodBinding //, IExecutableBuildingResponse +{ + public override Guid ClassId => KnownInstanceGuids.Classes.ExecuteUpdateMethodBinding; + internal ExecuteUpdateMethodBinding(InstanceHandle handle) : base(handle) { } } \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessRelatedUpdatesMethod.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessRelatedUpdatesMethod.cs new file mode 100644 index 0000000..4dc26c0 --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessRelatedUpdatesMethod.cs @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Michael Becker +// +// This file is part of Mocha.NET. +// +// Mocha.NET is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Mocha.NET is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Mocha.NET. If not, see . + + +namespace Mocha.Core.Oop.Methods; + +public class ProcessRelatedUpdatesMethod : Method +{ + public override Guid ClassId => KnownInstanceGuids.MethodClasses.ProcessRelatedUpdatesMethod; + internal ProcessRelatedUpdatesMethod(InstanceHandle handle) : base(handle) { } +} diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessUpdatesMethod.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessUpdatesMethod.cs new file mode 100644 index 0000000..4be4258 --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/ProcessUpdatesMethod.cs @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Michael Becker +// +// This file is part of Mocha.NET. +// +// Mocha.NET is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Mocha.NET is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Mocha.NET. If not, see . + + +namespace Mocha.Core.Oop.Methods; + +public class ProcessUpdatesMethod : Method +{ + public override Guid ClassId => KnownInstanceGuids.MethodClasses.ProcessUpdatesMethod; + internal ProcessUpdatesMethod(InstanceHandle handle) : base(handle) { } +} diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/PUMProcess.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/PUMProcess.cs new file mode 100644 index 0000000..8e0f49e --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/PUMProcess.cs @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Michael Becker +// +// This file is part of Mocha.NET. +// +// Mocha.NET is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Mocha.NET is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Mocha.NET. If not, see . + + +namespace Mocha.Core.Oop.Methods; + +public class PUMProcess : ConcreteInstanceWrapper +{ + public override Guid ClassId => KnownInstanceGuids.Classes.PUMProcess; + internal PUMProcess(InstanceHandle handle) : base(handle) { } +} diff --git a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/MethodBindingTests.cs b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/MethodBindingTests.cs index d71218c..333e35c 100644 --- a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/MethodBindingTests.cs +++ b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/MethodBindingTests.cs @@ -33,17 +33,17 @@ public class MethodBindingTests : MethodTestsBase [Test] public void REMBInheritsFromMethodBinding() { - /* OmsMethodBuilder mb = new OmsMethodBuilder(Oms); InstanceHandle c_MethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.MethodBinding); InstanceHandle a_Text = Oms.GetInstance(KnownAttributeGuids.Text.Value); - MethodReturningAttribute dummy = mb.CreateGetAttributeMethod(c_TestClass, "get", "Test Attribute", a_Text); + InstanceHandle hasBemProcess = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.BEMProcess)); + InstanceHandle elem = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.Element)); - InstanceHandle handle = mb.CreateReturnAttributeMethodBinding(dummy).Handle; + MethodReturningElement dummy = mb.CreateBuildElementMethod(c_TestClass, "get", "Test Element", AccessModifier.Public, true, hasBemProcess, elem); + + InstanceHandle handle = mb.CreateReturnElementMethodBinding(dummy).GetHandle(); Assert.That(Oms.IsInstanceOf(handle, c_MethodBinding)); - */ - Assert.Ignore(); } [Test] public void BRMBInheritsFromMethodBinding() @@ -75,32 +75,28 @@ public class MethodBindingTests : MethodTestsBase [Test] public void PUMBInheritsFromMethodBinding() { - /* OmsMethodBuilder mb = new OmsMethodBuilder(Oms); InstanceHandle c_MethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.MethodBinding); InstanceHandle a_Text = Oms.GetInstance(KnownAttributeGuids.Text.Value); - MethodReturningAttribute dummy = mb.CreateGetAttributeMethod(c_TestClass, "get", "Test Attribute", a_Text); + List eumbs = new List(); + ProcessUpdatesMethod dummy = mb.CreateProcessUpdatesMethod(c_TestClass, "process", "Test Attribute", AccessModifier.Public, true, eumbs); - InstanceHandle handle = mb.CreateReturnAttributeMethodBinding(dummy).Handle; + InstanceHandle handle = mb.CreateProcessUpdatesMethodBinding(dummy).GetHandle(); Assert.That(Oms.IsInstanceOf(handle, c_MethodBinding)); - */ - Assert.Ignore(); } [Test] public void EUMBInheritsFromMethodBinding() { - /* OmsMethodBuilder mb = new OmsMethodBuilder(Oms); InstanceHandle c_MethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.MethodBinding); InstanceHandle a_Text = Oms.GetInstance(KnownAttributeGuids.Text.Value); + InstanceHandle a_Token = Oms.GetInstance(KnownAttributeGuids.Text.Token); - MethodReturningAttribute dummy = mb.CreateGetAttributeMethod(c_TestClass, "get", "Test Attribute", a_Text); + AssignAttributeMethod dummy = mb.CreateAssignAttributeMethod(c_TestClass, "set", "Test Attribute", AccessModifier.Public, true, a_Token, a_Text); - InstanceHandle handle = mb.CreateReturnAttributeMethodBinding(dummy).Handle; + InstanceHandle handle = mb.CreateExecuteUpdateMethodBinding(dummy).GetHandle(); Assert.That(Oms.IsInstanceOf(handle, c_MethodBinding)); - */ - Assert.Ignore(); } [Test] diff --git a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs index d86112e..0ffeece 100644 --- a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs +++ b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs @@ -53,22 +53,63 @@ public class SystemRoutineTests : MethodTestsBase OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms); OmsSystemRoutineBuilder systemRoutineBuilder = new OmsSystemRoutineBuilder(Oms); + // create a System Attribute Routine to return a test value SystemAttributeRoutine testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate (Oms oms, OmsContext context) { string value = context.GetWorkData(oms.GetInstance(KnownAttributeGuids.Text.Token)); return TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE + value; }); + // create a GAS - Get Attribute by System Routine method which returns the attribute via the above system routine GetAttributeBySystemRoutineMethod gasMethod = methodBuilder.CreateGetAttributeBySystemRoutineMethod(irTestClass, "get", "Test System Routine Text Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Text.Value), testSystemAttributeRoutine); ReturnAttributeMethodBinding gasMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gasMethod); OmsContext context = Oms.CreateContext(); + + // execute the above RAMB, passing in the `Token` parameter with an expected hardcoded string string value = Oms.ExecuteReturningAttributeValue(context, gasMethodRamb, null, new KeyValuePair[] { // !!! WARNING: do not use 'Value' here as it is the return type attribute of the GAS method and WILL be overwritten after execution !!! new KeyValuePair(Oms.GetInstance(KnownAttributeGuids.Text.Token), "pqdms") }); + // check to ensure that the result is the above executed System Routine which combines the test value with the passed in parameter + Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE + "pqdms")); + } + + [Test] + public void PassParmViaSystemRoutineTest_AssignedViaRAMB() + { + InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID); + OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms); + OmsSystemRoutineBuilder systemRoutineBuilder = new OmsSystemRoutineBuilder(Oms); + + // create a System Attribute Routine to return a test value + SystemAttributeRoutine testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate (Oms oms, OmsContext context) + { + string value = context.GetWorkData(oms.GetInstance(KnownAttributeGuids.Text.Token)); + return TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE + value; + }); + + // create a GAS - Get Attribute by System Routine method which returns the attribute via the above system routine + GetAttributeBySystemRoutineMethod gasMethod = methodBuilder.CreateGetAttributeBySystemRoutineMethod(irTestClass, "get", "Test System Routine Text Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Text.Value), testSystemAttributeRoutine); + ReturnAttributeMethodBinding gasMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gasMethod, new KeyValuePair[] + { + // assign from work data: `User Name` to parm: `Token` + new KeyValuePair(Oms.GetInstance(KnownAttributeGuids.Text.Token), Oms.GetInstance(KnownAttributeGuids.Text.UserName)) + }); + + OmsContext context = Oms.CreateContext(); + + // execute the above RAMB, passing in the `Token` parameter with an expected hardcoded string + // here we specify `User Name` attribute instead of `Token`; the RAMB is set to assign `Token` = + string value = Oms.ExecuteReturningAttributeValue(context, gasMethodRamb, null, new KeyValuePair[] + { + // !!! WARNING: do not use 'Value' here as it is the return type attribute of the GAS method and WILL be overwritten after execution !!! + new KeyValuePair(Oms.GetInstance(KnownAttributeGuids.Text.UserName), "pqdms") + }); + + // check to ensure that the result is the above executed System Routine which combines the test value with the passed in parameter Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE + "pqdms")); }