improvements to OMS method builder and tests
This commit is contained in:
parent
d555ac984f
commit
9cda89829c
@ -1 +1 @@
|
||||
Subproject commit 5a411ddf69be2a2f32c601fe57004e839e3805c0
|
||||
Subproject commit 8bea362b3ca08a642ba196b8670e8e44e5e799e3
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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<KeyValuePair<InstanceHandle, InstanceHandle>>? parameterAssignments)
|
||||
@ -82,6 +85,18 @@ public class OmsMethodBuilder
|
||||
return new BuildResponseMethodBinding(methodBinding);
|
||||
}
|
||||
|
||||
public ExecuteUpdateMethodBinding CreateExecuteUpdateMethodBinding(Method method, IEnumerable<KeyValuePair<InstanceHandle, InstanceHandle>>? parameterAssignments = null)
|
||||
{
|
||||
InstanceHandle methodBinding = CreateMethodBindingBase(c_ExecuteUpdateMethodBinding, method, parameterAssignments);
|
||||
return new ExecuteUpdateMethodBinding(methodBinding);
|
||||
}
|
||||
|
||||
public ExecuteUpdateMethodBinding CreateProcessUpdatesMethodBinding(Method method, IEnumerable<KeyValuePair<InstanceHandle, InstanceHandle>>? 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<ExecuteUpdateMethodBinding> executeUpdateMethodBindings)
|
||||
{
|
||||
InstanceHandle ih = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.PUMProcess));
|
||||
List<InstanceHandle> list = new List<InstanceHandle>();
|
||||
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<ExecuteUpdateMethodBinding> 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);
|
||||
}
|
||||
}
|
||||
@ -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) { }
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2025 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class ProcessRelatedUpdatesMethod : Method
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.MethodClasses.ProcessRelatedUpdatesMethod;
|
||||
internal ProcessRelatedUpdatesMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2025 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class ProcessUpdatesMethod : Method
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.MethodClasses.ProcessUpdatesMethod;
|
||||
internal ProcessUpdatesMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
25
mocha-dotnet/src/lib/Mocha.Core/Oop/PUMProcess.cs
Normal file
25
mocha-dotnet/src/lib/Mocha.Core/Oop/PUMProcess.cs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2025 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class PUMProcess : ConcreteInstanceWrapper
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.Classes.PUMProcess;
|
||||
internal PUMProcess(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -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<ExecuteUpdateMethodBinding> eumbs = new List<ExecuteUpdateMethodBinding>();
|
||||
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]
|
||||
|
||||
@ -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<string> testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate (Oms oms, OmsContext context)
|
||||
{
|
||||
string value = context.GetWorkData<string>(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<string>(context, gasMethodRamb, null, new KeyValuePair<InstanceHandle, object>[]
|
||||
{
|
||||
// !!! 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<InstanceHandle, object>(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<string> testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate (Oms oms, OmsContext context)
|
||||
{
|
||||
string value = context.GetWorkData<string>(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<InstanceHandle, InstanceHandle>[]
|
||||
{
|
||||
// assign from work data: `User Name` to parm: `Token`
|
||||
new KeyValuePair<InstanceHandle, InstanceHandle>(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<string>(context, gasMethodRamb, null, new KeyValuePair<InstanceHandle, object>[]
|
||||
{
|
||||
// !!! 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<InstanceHandle, object>(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"));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user