tenanted routes work now
This commit is contained in:
parent
ecf3c1be1d
commit
8b41f14365
@ -119,8 +119,23 @@ public abstract class MochaWebApplication : WebApplication
|
||||
}
|
||||
}
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
Oms.SelectTenant(Oms.GetTenantByName(parts[1]));
|
||||
InstanceHandle c_Tenant = Oms.GetInstance(KnownInstanceGuids.Classes.Tenant);
|
||||
InstanceHandle i_Tenant = Oms.GetInstancesOf(c_Tenant).First();
|
||||
|
||||
InstanceHandle r_Tenant__has_initiating__Route = Oms.GetInstance(KnownRelationshipGuids.Tenant__has_initiating__Route);
|
||||
|
||||
InstanceHandle i_Route = Oms.GetRelatedInstance(i_Tenant, r_Tenant__has_initiating__Route);
|
||||
if (i_Route != InstanceHandle.Empty)
|
||||
{
|
||||
string targetUrl = Oms.GetAttributeValue<string>(i_Route, Oms.GetInstance(KnownAttributeGuids.Text.TargetURL));
|
||||
e.Context.Response.Redirect(targetUrl.Replace("{tenant}", parts[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Context.Response.Redirect("~/" + parts[1] + "/d/home.htmld");
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,6 +146,9 @@ public class Program : MochaWebApplication
|
||||
oms.SetAttributeValue(route, a_TargetURL, "/{tenant}/d/welcome.htmld");
|
||||
|
||||
oms.AssignRelationship(route, r_Route__processed_by__Control_Transaction_Method, ct.Handle);
|
||||
|
||||
InstanceHandle r_Tenant__has_initiating__Route = oms.GetInstance(KnownRelationshipGuids.Tenant__has_initiating__Route);
|
||||
oms.AssignRelationship(i_Tenant, r_Tenant__has_initiating__Route, route);
|
||||
}
|
||||
return oms;
|
||||
}
|
||||
|
||||
@ -379,5 +379,7 @@ namespace Mocha.Core
|
||||
public static Guid Route__processed_by__Control_Transaction_Method { get; } = new Guid("{6b9ad17e-69a2-42bf-8197-5ab266c76cd1}");
|
||||
public static Guid Control_Transaction_Method__processes__Route { get; } = new Guid("{d1c3aa8a-0928-4c46-9aba-9a368b3dea5a}");
|
||||
|
||||
public static Guid Tenant__has_initiating__Route { get; } = new Guid("{41dc15a8-c748-4d90-ae4e-104e45d15f2b}");
|
||||
public static Guid Route__initiates_for__Tenant { get; } = new Guid("{6682949b-f8d7-49a8-b7c3-a66a304a7fdb}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,17 +12,20 @@ public class WebModule : MiniOmsModule
|
||||
return rt;
|
||||
}
|
||||
|
||||
private InstanceHandle c_Tenant;
|
||||
|
||||
protected override void BuildInternal(Oms oms)
|
||||
{
|
||||
a_TargetURL = oms.CreateInstanceOf(c_Attribute, KnownAttributeGuids.Text.TargetURL);
|
||||
|
||||
c_Route = oms.CreateClass("Route", KnownInstanceGuids.Classes.Route);
|
||||
c_Tenant = oms.GetInstance(KnownInstanceGuids.Classes.Tenant);
|
||||
oms.AddAttribute(c_Route, a_TargetURL);
|
||||
|
||||
c_ControlTransactionMethod = oms.GetInstance(KnownInstanceGuids.MethodClasses.ControlTransactionMethod);
|
||||
|
||||
oms.CreateRelationship(c_Route, "processed by", c_ControlTransactionMethod, KnownRelationshipGuids.Route__processed_by__Control_Transaction_Method, true, "processes", KnownRelationshipGuids.Control_Transaction_Method__processes__Route);
|
||||
|
||||
oms.CreateRelationship(c_Tenant, "has initiating", c_Route, KnownRelationshipGuids.Tenant__has_initiating__Route, true, "initiates for", KnownRelationshipGuids.Route__initiates_for__Tenant);
|
||||
// Route.processed by CT - Control Transaction Method
|
||||
// CT - Control Transaction Method.uses Build Response Method Binding
|
||||
// Build Response Method Binding.executes Method -- Build UI Response Method
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
// 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 Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core.Tests.MethodTests;
|
||||
|
||||
public class ControlTransactionMethodTests : MethodTestsBase
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void AssignAttributeMethodTest()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
|
||||
InstanceHandle a_Name = Oms.GetInstance(KnownAttributeGuids.Text.Name);
|
||||
Oms.AddAttribute(irTestClass, a_Name);
|
||||
|
||||
string test_value = "Jackdaws love my big sphinx of quartz.";
|
||||
|
||||
string value = Oms.GetAttributeValue<string>(irTestClassInstance, a_Name);
|
||||
Assert.That(value, Is.Not.EqualTo(test_value));
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
BuildAttributeMethod ih_BA = builder.CreateBuildAttributeMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, a_Name, test_value);
|
||||
ReturnAttributeMethodBinding ramb1 = builder.CreateReturnAttributeMethodBinding(ih_BA);
|
||||
|
||||
AssignAttributeMethod ih_AA = builder.CreateAssignAttributeMethod(irTestClass, "set", "Test Attribute Value to `Jackdaws...`", AccessModifier.Public, true, ramb1, a_Name);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
Oms.Execute(context, ih_AA, irTestClassInstance);
|
||||
|
||||
value = Oms.GetAttributeValue<string>(irTestClassInstance, a_Name);
|
||||
Assert.That(value, Is.EqualTo(test_value));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user