Steps to reproduce:
- Add the following test for an XPO-based XAF application:
C#[Test]
public void Load_user_object_using_CurrentUserId_custom_function() {
using var scope = Host.Services.GetRequiredService<IServiceScopeFactory>().CreateScope();
scope.ServiceProvider.Authenticate("Admin", "");
var security = scope.ServiceProvider.GetRequiredService<ISecurityProvider>().GetSecurity();
var user_1 = (ApplicationUser)security.User;
using var os_Secured = scope.ServiceProvider.GetRequiredService<IObjectSpaceFactory>().CreateObjectSpace<ApplicationUser>();
var user_2 = os_Secured.FindObject<ApplicationUser>(CriteriaOperator.Parse("Oid=CurrentUserId()"));
using var os_NonSecured = scope.ServiceProvider.GetRequiredService<INonSecuredObjectSpaceFactory>().CreateNonSecuredObjectSpace<ApplicationUser>();
var user_3 = os_NonSecured.FindObject<ApplicationUser>(CriteriaOperator.Parse("Oid=CurrentUserId()"));
Assert.That(user_1.Oid, Is.EqualTo(user_2.Oid));
Assert.That(user_1.Oid, Is.EqualTo(user_3.Oid));
}
- The same test works correctly for an EFCore-based XAF application:
C#[Test]
public void Load_user_object_using_CurrentUserId_custom_function() {
using var scope = Host.Services.GetRequiredService<IServiceScopeFactory>().CreateScope();
scope.ServiceProvider.Authenticate("Admin", "");
var security = scope.ServiceProvider.GetRequiredService<ISecurityProvider>().GetSecurity();
var user_1 = (ApplicationUser)security.User;
using var os_Secured = scope.ServiceProvider.GetRequiredService<IObjectSpaceFactory>().CreateObjectSpace<ApplicationUser>();
var user_2 = os_Secured.FindObject<ApplicationUser>(CriteriaOperator.Parse("Id=CurrentUserId()"));
using var os_NonSecured = scope.ServiceProvider.GetRequiredService<INonSecuredObjectSpaceFactory>().CreateNonSecuredObjectSpace<ApplicationUser>();
var user_3 = os_NonSecured.FindObject<ApplicationUser>(CriteriaOperator.Parse("Id=CurrentUserId()"));
Assert.That(user_1.ID, Is.EqualTo(user_2.ID));
Assert.That(user_1.ID, Is.EqualTo(user_3.ID));
}
Expected result
The non-secured XPObjectSpace uses the SecurityFunctionPatcher instance and allows customizing custom function criteria operators.
any news on this?