migrate all tests to use MCX3 embedded Mini OMS
This commit is contained in:
parent
1b531ef5fc
commit
ba6ee8e5ae
@ -22,6 +22,14 @@ namespace Mocha.Core;
|
||||
|
||||
public abstract class LibraryPlugin : Plugin
|
||||
{
|
||||
protected virtual void LoadInternal(Stream stream, Library library)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public void Load(Stream stream, Library library)
|
||||
{
|
||||
LoadInternal(stream, library);
|
||||
}
|
||||
protected abstract void LoadInternal(string filename, Library library);
|
||||
public void Load(string filename, Library library)
|
||||
{
|
||||
|
||||
@ -1060,6 +1060,61 @@ public abstract class Oms
|
||||
return LibraryHandle.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the specified library file into memory. To add it to the tenant,
|
||||
/// first <see cref="SelectTenant" /> the desired tenant, and then call
|
||||
/// <see cref="AddLibraryReference" />.
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public LibraryHandle LoadLibrary(Stream stream)
|
||||
{
|
||||
// some examples:
|
||||
// .mcl compiled binary library file (fastest?)
|
||||
// /path/to/directory containing a bunch of XML / JSON / YAML files
|
||||
// .mcz ZIP archive of XML / JSON / YAML files (slowest?)
|
||||
LibraryHandle lh = LibraryHandle.Create();
|
||||
|
||||
Library lib = new Library();
|
||||
// _libraries[name] = lh;
|
||||
|
||||
// get a list of all library loaders we have implemented
|
||||
LibraryPlugin[] plugins = Plugin.Get<LibraryPlugin>();
|
||||
foreach (LibraryPlugin plugin in plugins)
|
||||
{
|
||||
Console.WriteLine("found plugin: {0}", plugin.GetType().FullName);
|
||||
|
||||
try
|
||||
{
|
||||
// if passed a directory, will enumerate all the
|
||||
// .xml / .json / .yaml files in the directory and
|
||||
// subdirectories
|
||||
plugin.Load(stream, lib);
|
||||
break;
|
||||
}
|
||||
catch (NotSupportedException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// if the files have not already been compiled, we need to do two passes.
|
||||
// - the first pass loads all instances into our tenant
|
||||
// - the second pass applies the attributes and relationships, which depend on the
|
||||
// presence of the instances
|
||||
|
||||
// compiling to .mcl binary library format does this all ahead of time and should
|
||||
// be faster.
|
||||
// let's be lazy and just look at the file extension to determine how to parse
|
||||
|
||||
// once all the instances have been loaded, tell the in-memory library manager
|
||||
// to do its second pass "linking" the objects
|
||||
lib.Link();
|
||||
|
||||
InitializeLibraryInternal(lh, lib);
|
||||
|
||||
return lh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the specified library file into memory. To add it to the tenant,
|
||||
/// first <see cref="SelectTenant" /> the desired tenant, and then call
|
||||
|
||||
@ -24,9 +24,9 @@ using MBS.Core;
|
||||
/// Implements <see cref="Oms" /> completely in-memory with a bare minimum schema definition which
|
||||
/// includes Class, Attribute and subclasses, Relationship, and File for attachments.
|
||||
/// </summary>
|
||||
public class MiniOms : MemoryOms
|
||||
public class HardcodedMiniOms : MemoryOms
|
||||
{
|
||||
private MiniOms()
|
||||
private HardcodedMiniOms()
|
||||
{
|
||||
|
||||
}
|
||||
@ -42,7 +42,7 @@ public class MiniOms : MemoryOms
|
||||
|
||||
public List<MiniOmsModule> Modules { get; } = new List<MiniOmsModule>();
|
||||
|
||||
private MiniOms(MiniOmsModule[] modules = null)
|
||||
private HardcodedMiniOms(MiniOmsModule[] modules = null)
|
||||
{
|
||||
if (modules == null)
|
||||
{
|
||||
@ -34,10 +34,11 @@ public class McxMiniLibraryPlugin : LibraryPlugin
|
||||
return ext.Equals(".mcx") || ext.Equals(".mcl");
|
||||
}
|
||||
|
||||
protected override void LoadInternal(string filename, Library library)
|
||||
protected override void LoadInternal(Stream stream, Library library)
|
||||
{
|
||||
FileStream fs = File.Open(filename, FileMode.Open);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
base.LoadInternal(stream, library);
|
||||
|
||||
BinaryReader r = new BinaryReader(stream);
|
||||
|
||||
string signature = r.ReadFixedString(4);
|
||||
if (!signature.Equals("MCX!"))
|
||||
@ -170,4 +171,10 @@ public class McxMiniLibraryPlugin : LibraryPlugin
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadInternal(string filename, Library library)
|
||||
{
|
||||
FileStream fs = File.Open(filename, FileMode.Open);
|
||||
LoadInternal(fs, library);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,11 +24,6 @@ namespace Mocha.Core.Tests;
|
||||
[TestFixture]
|
||||
public class BasicTests : OmsTestsBase
|
||||
{
|
||||
protected override Oms CreateOms()
|
||||
{
|
||||
return new MiniOms();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void PrerequisitesDefined()
|
||||
|
||||
26
mocha-dotnet/tests/Mocha.Core.Tests/EmbeddedMiniOms.cs
Normal file
26
mocha-dotnet/tests/Mocha.Core.Tests/EmbeddedMiniOms.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Mocha.Core.OmsImplementations;
|
||||
|
||||
namespace Mocha.Core.Tests;
|
||||
|
||||
public class EmbeddedMiniOms : MemoryOms
|
||||
{
|
||||
protected override void InitializeInternal()
|
||||
{
|
||||
base.InitializeInternal();
|
||||
|
||||
TenantHandle th = CreateTenant("super");
|
||||
SelectTenant(th);
|
||||
|
||||
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
Stream? stream = asm.GetManifestResourceStream("Mocha.Core.Tests.Resources.net.alcetech.Mocha.System.mcl");
|
||||
if (stream != null)
|
||||
{
|
||||
LibraryHandle lh = LoadLibrary(stream);
|
||||
this.AddLibraryReference(lh);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Manifest resource stream not found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,12 @@ public abstract class OmsTestsBase
|
||||
{
|
||||
public Oms Oms { get; private set; }
|
||||
|
||||
protected virtual Oms CreateOms() { return new MiniOms(); }
|
||||
protected Oms CreateOms()
|
||||
{
|
||||
EmbeddedMiniOms oms = new EmbeddedMiniOms();
|
||||
oms.Initialize();
|
||||
return oms;
|
||||
}
|
||||
|
||||
protected readonly Guid TEST_CLASS_GUID = new Guid("{5821fc28-6411-4339-a7d2-56dc05591501}");
|
||||
protected readonly Guid TEST_CLASS2_GUID = new Guid("{6351ecb7-da5d-4029-ba3a-196a6dc980e9}");
|
||||
|
||||
@ -22,11 +22,6 @@ namespace Mocha.Core.Tests;
|
||||
|
||||
public class RelationshipTests : OmsTestsBase
|
||||
{
|
||||
protected override Oms CreateOms()
|
||||
{
|
||||
return new MiniOms();
|
||||
}
|
||||
|
||||
protected readonly Guid TEST_REL3_GUID = new Guid("{e1cacab7-c8a9-480d-b2b6-5b25c6c549e0}");
|
||||
protected readonly Guid TEST_REL4_GUID = new Guid("{82b8f531-fe32-4c36-ad3a-9e0f79bc95b4}");
|
||||
protected readonly Guid TEST_REL5_GUID = new Guid("{b80995cf-6a2d-44c2-9c93-ebb80c9be802}");
|
||||
|
||||
@ -25,11 +25,6 @@ namespace Mocha.Core.Tests;
|
||||
public class WorkSetTests : OmsTestsBase
|
||||
{
|
||||
|
||||
protected override Oms CreateOms()
|
||||
{
|
||||
return new MiniOms();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoValidClassConstraints()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user