155 lines
4.6 KiB
C#
155 lines
4.6 KiB
C#
// Copyright (C) 2024 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/>.
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
using Mocha.Core.OmsImplementations.Mini;
|
|
using Mocha.Core.Oop;
|
|
|
|
namespace Mocha.Core.Tests;
|
|
|
|
public class WorkSetTests : OmsTestsBase
|
|
{
|
|
|
|
[Test]
|
|
public void NoValidClassConstraints()
|
|
{
|
|
// no valid class constraints - we should be able to put anything in here
|
|
InstanceHandle c_Class = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
|
InstanceHandle c_Attribute = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
|
|
|
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set");
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, c_Class);
|
|
}, Throws.Nothing);
|
|
}
|
|
|
|
[Test]
|
|
public void SingleValidClassConstraint()
|
|
{
|
|
// no valid class constraints - we should be able to put anything in here
|
|
InstanceHandle c_Class = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
|
InstanceHandle c_TextAttribute = Oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute);
|
|
|
|
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set", true, new InstanceHandle[]
|
|
{
|
|
c_TextAttribute
|
|
});
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, c_Class);
|
|
}, Throws.ArgumentException);
|
|
}
|
|
|
|
[Test]
|
|
public void MultipleValidClassConstraintSingular()
|
|
{
|
|
// no valid class constraints - we should be able to put anything in here
|
|
InstanceHandle c_Class = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
|
InstanceHandle c_TextAttribute = Oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute);
|
|
InstanceHandle c_BooleanAttribute = Oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute);
|
|
|
|
InstanceHandle a_Value = Oms.GetInstance(KnownAttributeGuids.Text.Value);
|
|
InstanceHandle a_Singular = Oms.GetInstance(KnownAttributeGuids.Boolean.Singular);
|
|
|
|
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set", true, new InstanceHandle[]
|
|
{
|
|
c_TextAttribute,
|
|
c_BooleanAttribute
|
|
});
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, c_Class);
|
|
}, Throws.ArgumentException);
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, a_Value);
|
|
}, Throws.Nothing);
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, a_Singular);
|
|
}, Throws.Nothing);
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, new InstanceHandle[] { a_Value, a_Singular });
|
|
}, Throws.InvalidOperationException);
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void MultipleValidClassConstraintNonsingular()
|
|
{
|
|
// no valid class constraints - we should be able to put anything in here
|
|
InstanceHandle c_Class = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
|
InstanceHandle c_TextAttribute = Oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute);
|
|
InstanceHandle c_BooleanAttribute = Oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute);
|
|
|
|
InstanceHandle a_Value = Oms.GetInstance(KnownAttributeGuids.Text.Value);
|
|
InstanceHandle a_Singular = Oms.GetInstance(KnownAttributeGuids.Boolean.Singular);
|
|
|
|
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set", false, new InstanceHandle[]
|
|
{
|
|
c_TextAttribute,
|
|
c_BooleanAttribute
|
|
});
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, c_Class);
|
|
}, Throws.ArgumentException);
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, a_Value);
|
|
}, Throws.Nothing);
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, a_Singular);
|
|
}, Throws.Nothing);
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
context.SetWorkData(workSet, new InstanceHandle[] { a_Singular, a_Value });
|
|
}, Throws.Nothing);
|
|
}
|
|
|
|
[Test]
|
|
public void LiteralValueAssignedToWorkSet()
|
|
{
|
|
// no valid class constraints - we should be able to put anything in here
|
|
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set");
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
Assert.That(delegate ()
|
|
{
|
|
// cannot assign literal data to a work set
|
|
context.SetWorkData(workSet, true);
|
|
}, Throws.ArgumentException);
|
|
}
|
|
} |