add some more method and relationship tests
This commit is contained in:
parent
e1c143d48c
commit
7910696fa1
@ -153,14 +153,15 @@ public class OmsMethodBuilder
|
|||||||
return new AssignAttributeMethod(method);
|
return new AssignAttributeMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRelationshipMethod CreateGetRelationshipMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsRelationship)
|
public GetRelationshipMethod CreateGetRelationshipMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsRelationship, bool singular = false)
|
||||||
{
|
{
|
||||||
return CreateGetRelationshipMethod(forClassInstance, verb, name, accessModifier, isStatic, Guid.NewGuid(), returnsRelationship);
|
return CreateGetRelationshipMethod(forClassInstance, verb, name, accessModifier, isStatic, Guid.NewGuid(), returnsRelationship, singular);
|
||||||
}
|
}
|
||||||
public GetRelationshipMethod CreateGetRelationshipMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, Guid globalIdentifier, InstanceHandle returnsRelationship)
|
public GetRelationshipMethod CreateGetRelationshipMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, Guid globalIdentifier, InstanceHandle returnsRelationship, bool singular = false)
|
||||||
{
|
{
|
||||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetRelationshipMethod), forClassInstance, verb, name, accessModifier, isStatic, globalIdentifier);
|
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetRelationshipMethod), forClassInstance, verb, name, accessModifier, isStatic, globalIdentifier);
|
||||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Relationship_Method__returns__Relationship), returnsRelationship);
|
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Relationship_Method__returns__Relationship), returnsRelationship);
|
||||||
|
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Boolean.Singular), singular);
|
||||||
return new GetRelationshipMethod(method);
|
return new GetRelationshipMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,19 +24,90 @@ public class GetRelationshipTests : MethodTestsBase
|
|||||||
{
|
{
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetRelationshipTest()
|
public void SingularGetRelationshipTestForSingularRelationship()
|
||||||
{
|
{
|
||||||
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||||
InstanceHandle c_TestClass2 = Oms.GetInstance(TEST_CLASS2_GUID);
|
InstanceHandle c_TestClass2 = Oms.GetInstance(TEST_CLASS2_GUID);
|
||||||
|
|
||||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
InstanceHandle i_TestClass = Oms.CreateInstanceOf(c_TestClass);
|
||||||
|
InstanceHandle i_TestClass2 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
|
||||||
GetRelationshipMethod method = builder.CreateGetRelationshipMethod(c_TestClass, "get", "Test Class.has Test Class 2", AccessModifier.Public, true, r_Test_Class__has__Test_Class_2);
|
Oms.AssignRelationship(i_TestClass, r_Test_Class__has__Test_Class_2, i_TestClass2);
|
||||||
|
|
||||||
|
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||||
|
GetRelationshipMethod method = builder.CreateGetRelationshipMethod(c_TestClass, "get", "Test Class.has Test Class 2", AccessModifier.Public, true, r_Test_Class__has__Test_Class_2, true);
|
||||||
ReturnInstanceSetMethodBinding rsmb = builder.CreateReturnInstanceSetMethodBinding(method);
|
ReturnInstanceSetMethodBinding rsmb = builder.CreateReturnInstanceSetMethodBinding(method);
|
||||||
|
|
||||||
OmsContext context = Oms.CreateContext();
|
OmsContext context = Oms.CreateContext();
|
||||||
object? value = Oms.Execute(context, rsmb);
|
context.SetWorkData(c_TestClass, i_TestClass); // set the `this` parm
|
||||||
Assert.That(value, Is.EqualTo(r_Test_Class__has__Test_Class_2));
|
|
||||||
|
InstanceHandle valueIH = Oms.Execute(context, rsmb);
|
||||||
|
|
||||||
|
object? value = context.GetWorkData(valueIH);
|
||||||
|
Assert.That(value, Is.EqualTo(i_TestClass2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SingularGetRelationshipTestForNonsingularRelationship()
|
||||||
|
{
|
||||||
|
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||||
|
InstanceHandle c_TestClass2 = Oms.GetInstance(TEST_CLASS2_GUID);
|
||||||
|
|
||||||
|
InstanceHandle i_TestClass = Oms.CreateInstanceOf(c_TestClass);
|
||||||
|
|
||||||
|
InstanceHandle i_TestClass2_1 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
InstanceHandle i_TestClass2_2 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
InstanceHandle i_TestClass2_3 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
|
||||||
|
InstanceHandle[] TEST_VALUES = new InstanceHandle[] { i_TestClass2_2, i_TestClass2_3, i_TestClass2_1 };
|
||||||
|
Oms.AssignRelationship(i_TestClass, r_Test_Class__has_multiple__Test_Class_2, TEST_VALUES);
|
||||||
|
|
||||||
|
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||||
|
|
||||||
|
GetRelationshipMethod method = builder.CreateGetRelationshipMethod(c_TestClass, "take one from", "Test Class.has multiple Test Class 2", AccessModifier.Public, true, r_Test_Class__has_multiple__Test_Class_2, true);
|
||||||
|
ReturnInstanceSetMethodBinding rsmb = builder.CreateReturnInstanceSetMethodBinding(method);
|
||||||
|
|
||||||
|
OmsContext context = Oms.CreateContext();
|
||||||
|
context.SetWorkData(c_TestClass, i_TestClass); // set the `this` parm
|
||||||
|
|
||||||
|
InstanceHandle valueIH = Oms.Execute(context, rsmb);
|
||||||
|
|
||||||
|
object? value = context.GetWorkData(valueIH);
|
||||||
|
Assert.That(value, Is.EqualTo(TEST_VALUES[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NonsingularGetRelationshipTest()
|
||||||
|
{
|
||||||
|
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||||
|
InstanceHandle c_TestClass2 = Oms.GetInstance(TEST_CLASS2_GUID);
|
||||||
|
|
||||||
|
InstanceHandle i_TestClass = Oms.CreateInstanceOf(c_TestClass);
|
||||||
|
|
||||||
|
InstanceHandle i_TestClass2_1 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
InstanceHandle i_TestClass2_2 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
InstanceHandle i_TestClass2_3 = Oms.CreateInstanceOf(c_TestClass2);
|
||||||
|
|
||||||
|
InstanceHandle[] TEST_VALUES = new InstanceHandle[] { i_TestClass2_2, i_TestClass2_3, i_TestClass2_1 };
|
||||||
|
Oms.AssignRelationship(i_TestClass, r_Test_Class__has_multiple__Test_Class_2, TEST_VALUES);
|
||||||
|
|
||||||
|
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||||
|
|
||||||
|
GetRelationshipMethod method = builder.CreateGetRelationshipMethod(c_TestClass, "get", "Test Class.has multiple Test Class 2", AccessModifier.Public, true, r_Test_Class__has_multiple__Test_Class_2, false);
|
||||||
|
ReturnInstanceSetMethodBinding rsmb = builder.CreateReturnInstanceSetMethodBinding(method);
|
||||||
|
|
||||||
|
OmsContext context = Oms.CreateContext();
|
||||||
|
context.SetWorkData(c_TestClass, i_TestClass); // set the `this` parm
|
||||||
|
|
||||||
|
InstanceHandle valueIH = Oms.Execute(context, rsmb);
|
||||||
|
|
||||||
|
object? value_o = context.GetWorkData(valueIH);
|
||||||
|
InstanceHandle[] values = (InstanceHandle[])value_o;
|
||||||
|
for (int i = 0; i < TEST_VALUES.Length; i++)
|
||||||
|
{
|
||||||
|
Assert.That(values[i], Is.EqualTo(TEST_VALUES[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@ -47,17 +47,14 @@ public class MethodBindingTests : MethodTestsBase
|
|||||||
[Test]
|
[Test]
|
||||||
public void BRMBInheritsFromMethodBinding()
|
public void BRMBInheritsFromMethodBinding()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
OmsMethodBuilder mb = new OmsMethodBuilder(Oms);
|
OmsMethodBuilder mb = new OmsMethodBuilder(Oms);
|
||||||
InstanceHandle c_MethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.MethodBinding);
|
InstanceHandle c_MethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.MethodBinding);
|
||||||
InstanceHandle a_Text = Oms.GetInstance(KnownAttributeGuids.Text.Value);
|
InstanceHandle a_Text = Oms.GetInstance(KnownAttributeGuids.Text.Value);
|
||||||
|
|
||||||
MethodReturningAttribute dummy = mb.CreateGetAttributeMethod(c_TestClass, "get", "Test Attribute", a_Text);
|
MethodBuildingResponse dummy = mb.CreateBuildUIResponseMethod(c_TestClass, "get", "Test Attribute", AccessModifier.Public, false, InstanceHandle.Empty);
|
||||||
|
|
||||||
InstanceHandle handle = mb.CreateReturnAttributeMethodBinding(dummy).Handle;
|
InstanceHandle handle = mb.CreateBuildResponseMethodBinding(dummy).Handle;
|
||||||
Assert.That(Oms.IsInstanceOf(handle, c_MethodBinding));
|
Assert.That(Oms.IsInstanceOf(handle, c_MethodBinding));
|
||||||
*/
|
|
||||||
Assert.Ignore();
|
|
||||||
}
|
}
|
||||||
[Test]
|
[Test]
|
||||||
public void RWMBInheritsFromMethodBinding()
|
public void RWMBInheritsFromMethodBinding()
|
||||||
|
|||||||
@ -27,9 +27,12 @@ public abstract class MethodTestsBase : OmsTestsBase
|
|||||||
{
|
{
|
||||||
Guid gid_r_Test_Class__has__Test_Class_2 = new Guid("{a5b67aad-e46f-4673-b339-77417396b2fe}");
|
Guid gid_r_Test_Class__has__Test_Class_2 = new Guid("{a5b67aad-e46f-4673-b339-77417396b2fe}");
|
||||||
Guid gid_r_Test_Class_2__for__Test_Class = new Guid("{2864dfd9-0313-4801-96bf-b9be99ea172d}");
|
Guid gid_r_Test_Class_2__for__Test_Class = new Guid("{2864dfd9-0313-4801-96bf-b9be99ea172d}");
|
||||||
|
Guid gid_r_Test_Class__has_multiple__Test_Class_2 = new Guid("{a5b67aad-e46f-4673-b339-77417396b2fe}");
|
||||||
|
Guid gid_r_Test_Class_2__multiple_for__Test_Class = new Guid("{2864dfd9-0313-4801-96bf-b9be99ea172d}");
|
||||||
|
|
||||||
protected InstanceHandle c_TestClass, c_TestClass2;
|
protected InstanceHandle c_TestClass, c_TestClass2;
|
||||||
protected InstanceHandle r_Test_Class__has__Test_Class_2, r_Test_Class_2__for__Test_Class;
|
protected InstanceHandle r_Test_Class__has__Test_Class_2, r_Test_Class_2__for__Test_Class;
|
||||||
|
protected InstanceHandle r_Test_Class__has_multiple__Test_Class_2, r_Test_Class_2__multiple_for__Test_Class;
|
||||||
|
|
||||||
protected override void AfterSetup()
|
protected override void AfterSetup()
|
||||||
{
|
{
|
||||||
@ -39,5 +42,6 @@ public abstract class MethodTestsBase : OmsTestsBase
|
|||||||
c_TestClass2 = Oms.GetInstance(TEST_CLASS2_GUID);
|
c_TestClass2 = Oms.GetInstance(TEST_CLASS2_GUID);
|
||||||
|
|
||||||
r_Test_Class__has__Test_Class_2 = Oms.CreateRelationship(c_TestClass, "has", c_TestClass2, gid_r_Test_Class__has__Test_Class_2, true, "for", gid_r_Test_Class_2__for__Test_Class, out r_Test_Class_2__for__Test_Class);
|
r_Test_Class__has__Test_Class_2 = Oms.CreateRelationship(c_TestClass, "has", c_TestClass2, gid_r_Test_Class__has__Test_Class_2, true, "for", gid_r_Test_Class_2__for__Test_Class, out r_Test_Class_2__for__Test_Class);
|
||||||
|
r_Test_Class__has_multiple__Test_Class_2 = Oms.CreateRelationship(c_TestClass, "has multiple", c_TestClass2, gid_r_Test_Class__has_multiple__Test_Class_2, false, "multiple for", gid_r_Test_Class_2__multiple_for__Test_Class, out r_Test_Class_2__multiple_for__Test_Class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user