Compare commits
3 Commits
560d0efffc
...
aafd99ab94
| Author | SHA1 | Date | |
|---|---|---|---|
| aafd99ab94 | |||
| bce1cf6437 | |||
| 1682dcd542 |
@ -90,6 +90,8 @@ namespace Mocha.Core
|
|||||||
public static Guid ExecutableReturningElement { get; } = new Guid("{a15a4f52-1f1a-4ef3-80a7-033d45cc0548}");
|
public static Guid ExecutableReturningElement { get; } = new Guid("{a15a4f52-1f1a-4ef3-80a7-033d45cc0548}");
|
||||||
public static Guid ExecutableReturningWorkData { get; } = new Guid("{a0365b76-ad1f-462e-84da-d6a1d5b9c88c}");
|
public static Guid ExecutableReturningWorkData { get; } = new Guid("{a0365b76-ad1f-462e-84da-d6a1d5b9c88c}");
|
||||||
|
|
||||||
|
public static Guid Calculation { get; } = new Guid("{ab4fdf54-b8b7-4b07-bdaf-2548bdb4c290}");
|
||||||
|
|
||||||
public static Guid Event { get; set; } = new Guid("{ca727ecd-8536-4aeb-9e75-352dbb958767}");
|
public static Guid Event { get; set; } = new Guid("{ca727ecd-8536-4aeb-9e75-352dbb958767}");
|
||||||
|
|
||||||
public static Guid WorkData { get; set; } = new Guid("{05e8f023-88cb-416b-913e-75299e665eb2}");
|
public static Guid WorkData { get; set; } = new Guid("{05e8f023-88cb-416b-913e-75299e665eb2}");
|
||||||
|
|||||||
@ -451,5 +451,8 @@ namespace Mocha.Core
|
|||||||
public static Guid Numeric_Attribute__returned_by__Calculate_Numeric_Method { get; } = new Guid("{03275ef5-c9cf-4816-a4f5-4f3aaf0f9479}");
|
public static Guid Numeric_Attribute__returned_by__Calculate_Numeric_Method { get; } = new Guid("{03275ef5-c9cf-4816-a4f5-4f3aaf0f9479}");
|
||||||
|
|
||||||
public static Guid Arithmetic_Calculation__has__Arithmetic_Operator { get; } = new Guid("{f286edc6-0875-41bf-8fe9-127b8c0664ae}");
|
public static Guid Arithmetic_Calculation__has__Arithmetic_Operator { get; } = new Guid("{f286edc6-0875-41bf-8fe9-127b8c0664ae}");
|
||||||
|
|
||||||
|
public static Guid Arithmetic_Calculation__has_first_operand__Calculation { get; } = new Guid("{4f002495-dee4-4eca-8a15-beb8f928648d}");
|
||||||
|
public static Guid Arithmetic_Calculation__has_second_operand__Calculation { get; } = new Guid("{0d74918d-5e7b-4492-9fa4-e35558f40ef3}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,8 +39,30 @@ public class CalculateNumericMethodImplementation : MethodImplementation
|
|||||||
throw new InvalidOperationException("no Arithmetic Operator specified for Arithmetic Calculation");
|
throw new InvalidOperationException("no Arithmetic Operator specified for Arithmetic Calculation");
|
||||||
}
|
}
|
||||||
|
|
||||||
decimal primaryOperandValue = oms.GetAttributeValue<decimal>(method, oms.GetInstance(KnownAttributeGuids.Numeric.PrimaryOperandValue));
|
decimal primaryOperandValue = 0.0M;
|
||||||
decimal secondaryOperandValue = oms.GetAttributeValue<decimal>(method, oms.GetInstance(KnownAttributeGuids.Numeric.SecondaryOperandValue));
|
decimal secondaryOperandValue = 0.0M;
|
||||||
|
|
||||||
|
if (oms.TryGetAttributeValue<decimal>(method, oms.GetInstance(KnownAttributeGuids.Numeric.PrimaryOperandValue), out decimal v))
|
||||||
|
{
|
||||||
|
primaryOperandValue = v;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InstanceHandle hFirstOperand = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Arithmetic_Calculation__has_first_operand__Calculation));
|
||||||
|
InstanceHandle hResult = oms.Execute(context, hFirstOperand);
|
||||||
|
primaryOperandValue = context.GetWorkData<decimal>(hResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oms.TryGetAttributeValue<decimal>(method, oms.GetInstance(KnownAttributeGuids.Numeric.SecondaryOperandValue), out decimal v2))
|
||||||
|
{
|
||||||
|
secondaryOperandValue = v2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InstanceHandle hSecondOperand = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Arithmetic_Calculation__has_second_operand__Calculation));
|
||||||
|
InstanceHandle hResult = oms.Execute(context, hSecondOperand);
|
||||||
|
secondaryOperandValue = context.GetWorkData<decimal>(hResult);
|
||||||
|
}
|
||||||
|
|
||||||
decimal value = 0.0M;
|
decimal value = 0.0M;
|
||||||
if (arithmeticOperator.Equals(ArithmeticOperator.Add))
|
if (arithmeticOperator.Equals(ArithmeticOperator.Add))
|
||||||
|
|||||||
@ -24,21 +24,35 @@ public class GetAttributeMethodImplementation : MethodImplementation
|
|||||||
{
|
{
|
||||||
InstanceHandle irForClass = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Method__for__Class));
|
InstanceHandle irForClass = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||||
InstanceHandle returnsAttribute = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Get_Attribute_Method__returns__Attribute));
|
InstanceHandle returnsAttribute = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Get_Attribute_Method__returns__Attribute));
|
||||||
|
bool isStatic = oms.GetAttributeValue<bool>(method, oms.GetInstance(KnownAttributeGuids.Boolean.Static));
|
||||||
|
|
||||||
if (returnsAttribute == InstanceHandle.Empty)
|
if (returnsAttribute == InstanceHandle.Empty)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("no Work Set specified for method");
|
throw new InvalidOperationException("no Work Set specified for method");
|
||||||
}
|
}
|
||||||
|
|
||||||
IInstanceReference? forInstance = (IInstanceReference?) context.GetWorkData(irForClass);
|
IInstanceReference? forInstance = null;
|
||||||
if (forInstance == null)
|
if (isStatic)
|
||||||
{
|
{
|
||||||
throw new NullReferenceException(String.Format("non-static method call without instance reference {0}", oms.GetGlobalIdentifier(irForClass)));
|
forInstance = irForClass;
|
||||||
|
if (forInstance == null)
|
||||||
|
{
|
||||||
|
// we should never get here
|
||||||
|
// throw new NullReferenceException(String.Format("static method call without instance reference {0}", oms.GetGlobalIdentifier(irForClass)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forInstance = (IInstanceReference?)context.GetWorkData(irForClass);
|
||||||
|
if (forInstance == null)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException(String.Format("non-static method call without instance reference {0}", oms.GetGlobalIdentifier(irForClass)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oms.IsInstanceOf(forInstance, oms.GetInstance(KnownInstanceGuids.Classes.WorkSet)))
|
if (oms.IsInstanceOf(forInstance, oms.GetInstance(KnownInstanceGuids.Classes.WorkSet)))
|
||||||
{
|
{
|
||||||
forInstance = (InstanceHandle?) context.GetWorkData(forInstance);
|
forInstance = (InstanceHandle?)context.GetWorkData(forInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forInstance is InstanceHandle forInstanceHandle)
|
if (forInstance is InstanceHandle forInstanceHandle)
|
||||||
|
|||||||
@ -402,8 +402,18 @@ public abstract class Oms
|
|||||||
InstanceHandle ihSourceClass = GetRelatedInstance(relationship, GetInstance(KnownRelationshipGuids.Relationship__has_source__Class));
|
InstanceHandle ihSourceClass = GetRelatedInstance(relationship, GetInstance(KnownRelationshipGuids.Relationship__has_source__Class));
|
||||||
InstanceHandle ihDestinationClass = GetRelatedInstance(relationship, GetInstance(KnownRelationshipGuids.Relationship__has_destination__Class));
|
InstanceHandle ihDestinationClass = GetRelatedInstance(relationship, GetInstance(KnownRelationshipGuids.Relationship__has_destination__Class));
|
||||||
List<InstanceHandle> ignoreClasses = new List<InstanceHandle>();
|
List<InstanceHandle> ignoreClasses = new List<InstanceHandle>();
|
||||||
ignoreClasses.Add(GetInstance(KnownInstanceGuids.Classes.Instance));
|
if (TryGetInstance(KnownInstanceGuids.Classes.Instance, out InstanceHandle __ih_1))
|
||||||
ignoreClasses.Add(GetInstance(KnownInstanceGuids.Classes.ExecutableReturningWorkData));
|
{
|
||||||
|
ignoreClasses.Add(__ih_1);
|
||||||
|
}
|
||||||
|
if (TryGetInstance(KnownInstanceGuids.Classes.ExecutableReturningWorkData, out InstanceHandle __ih_2))
|
||||||
|
{
|
||||||
|
ignoreClasses.Add(__ih_2);
|
||||||
|
}
|
||||||
|
if (TryGetInstance(KnownInstanceGuids.Classes.Calculation, out InstanceHandle __ih_3))
|
||||||
|
{
|
||||||
|
ignoreClasses.Add(__ih_3);
|
||||||
|
}
|
||||||
|
|
||||||
if (ihSourceClass != InstanceHandle.Empty)
|
if (ihSourceClass != InstanceHandle.Empty)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -391,4 +391,14 @@ public class OmsMethodBuilder
|
|||||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Calculate_Numeric_Method__returns__Numeric_Attribute), returnsAttribute.GetHandle());
|
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Calculate_Numeric_Method__returns__Numeric_Attribute), returnsAttribute.GetHandle());
|
||||||
return new CalculateNumericMethod(method);
|
return new CalculateNumericMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CalculateNumericMethod CreateCalculateNumericMethod(InstanceHandle clasz, string verb, string name, AccessModifier accessModifier, bool isStatic, IInstanceReference returnsAttribute, IInstanceReference primaryOperand, ArithmeticOperator oper, decimal secondaryOperand)
|
||||||
|
{
|
||||||
|
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.CalculateNumericMethod), clasz, verb, name, accessModifier, isStatic);
|
||||||
|
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Arithmetic_Calculation__has_first_operand__Calculation), primaryOperand);
|
||||||
|
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Arithmetic_Calculation__has__Arithmetic_Operator), oper.GetHandle());
|
||||||
|
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Numeric.SecondaryOperandValue), secondaryOperand);
|
||||||
|
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Calculate_Numeric_Method__returns__Numeric_Attribute), returnsAttribute.GetHandle());
|
||||||
|
return new CalculateNumericMethod(method);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -161,6 +161,37 @@ namespace Mocha.Core.Tests.MethodTests
|
|||||||
|
|
||||||
Assert.That(value, Is.EqualTo(test_result));
|
Assert.That(value, Is.EqualTo(test_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Add_GA_Plus_Literal_Number_Test()
|
||||||
|
{
|
||||||
|
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||||
|
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||||
|
decimal test_value = 20.0M;
|
||||||
|
|
||||||
|
InstanceHandle irAttribute = Oms.GetInstance(KnownAttributeGuids.Numeric.MaximumLength);
|
||||||
|
Oms.SetAttributeValue(irTestClassInstance, irAttribute, test_value);
|
||||||
|
// `Test Class Instance`.`Maximum Length` is now 20.0M
|
||||||
|
|
||||||
|
decimal test_addition = 5.0M;
|
||||||
|
decimal test_result = test_value + test_addition;
|
||||||
|
|
||||||
|
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||||
|
GetAttributeMethod ih_GA = builder.CreateGetAttributeMethod(irTestClass, "get", "Maximum Length", irAttribute);
|
||||||
|
|
||||||
|
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), ih_GA, ArithmeticOperator.Add, test_addition);
|
||||||
|
|
||||||
|
OmsContext context = Oms.CreateContext();
|
||||||
|
|
||||||
|
// below is REQUIRED, else we get "cannot call non-static method without instance reference"
|
||||||
|
context.SetWorkData(irTestClass, irTestClassInstance);
|
||||||
|
|
||||||
|
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||||
|
object value = context.GetWorkData(ih_test);
|
||||||
|
|
||||||
|
Assert.That(value, Is.EqualTo(test_result));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ namespace Mocha.Core.Tests.MethodTests
|
|||||||
{
|
{
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetAttributeMethodTest()
|
public void GetInstanceAttributeMethodTest()
|
||||||
{
|
{
|
||||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||||
@ -54,5 +54,36 @@ namespace Mocha.Core.Tests.MethodTests
|
|||||||
Assert.That(testAttributeValue2, Is.EqualTo(testAttributeValue));
|
Assert.That(testAttributeValue2, Is.EqualTo(testAttributeValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetStaticAttributeMethodTest()
|
||||||
|
{
|
||||||
|
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||||
|
|
||||||
|
InstanceHandle irTestAttribute = Oms.GetInstance(TEST_ATTR_GUID);
|
||||||
|
Assert.That(irTestAttribute, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||||
|
Oms.AddAttribute(irTestClass, irTestAttribute);
|
||||||
|
|
||||||
|
Oms.SetAttributeValue(irTestClass, irTestAttribute, TEST_ATTR_VALUE);
|
||||||
|
|
||||||
|
string testAttributeValue = Oms.GetAttributeValue<string>(irTestClass, irTestAttribute);
|
||||||
|
Assert.That(testAttributeValue, Is.EqualTo(TEST_ATTR_VALUE));
|
||||||
|
|
||||||
|
// here, the test attribute has a particular value.
|
||||||
|
// let's make sure that calling a GA- Get Attribute method on TestClass returns the same
|
||||||
|
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||||
|
|
||||||
|
GetAttributeMethod gaMethod = methodBuilder.CreateGetAttributeMethod(irTestClass, "get", "Test Attribute", AccessModifier.Public, true, irTestAttribute);
|
||||||
|
// Method is: `Test Class@get Test Attribute(GA)*S`
|
||||||
|
|
||||||
|
ReturnAttributeMethodBinding gaMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gaMethod);
|
||||||
|
|
||||||
|
OmsContext context = Oms.CreateContext();
|
||||||
|
|
||||||
|
object? testAttributeValue2 = Oms.ExecuteReturningAttributeValue(context, gaMethodRamb, null);
|
||||||
|
Assert.That(testAttributeValue2, Is.TypeOf<String>());
|
||||||
|
Assert.That(testAttributeValue2, Is.EqualTo(testAttributeValue));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user