Portal signin via Control Instance

This commit is contained in:
Andy Howard
2024-10-29 08:40:47 +00:00
parent bf6bb966bc
commit c5ee285e27
467 changed files with 25771 additions and 3347 deletions
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Sarand.BusinessMgr.Test</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsCoreWeb\SacsCoreWeb.csproj" />
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardDbas\SacsStandardDbas.csproj" />
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardProc\SacsStandardProc.csproj" />
<ProjectReference Include="..\SaBusinessMgrCoreWebControl\SaBusinessMgrCoreWebControl.csproj" />
<ProjectReference Include="..\SaBusMgrCoreProcs\SaBusMgrCoreProcs.csproj" />
<ProjectReference Include="..\SaBusMgrCoreWeb\SaBusMgrCoreWeb.csproj" />
<ProjectReference Include="..\SaBusMgrStandardBase\SaBusMgrStandardBase.csproj" />
<ProjectReference Include="..\SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>
@@ -0,0 +1,19 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Sarand.BusinessMgr.Test.Web.Control.App
{
//=======================================================================
[TestClass]
class SbmApplication_Control_Tester : SbmControlApp_Tester_Base
{
//-------------------------------------------------------------------
[TestMethod]
public void Test_SbmApplication_Control_CTR()
{
Assert.IsNotNull(App);
}
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Moq;
using Sarand.BusinessMgr.Net.Core.Web.App;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
using Sarand.BusinessMgr.Web.Control.App;
using Sarand.Net.Standard.Base.Dbas;
namespace Sarand.BusinessMgr.Test.Web.Control.App
{
//=======================================================================
public class SbmControlApp_Tester_Base
{
//-------------------------------------------------------------------
// Application.
private class SbmApplication_Control_Test : SbmApplication_Control
{
public SbmApplication_Control_Test(IConfiguration configuration, IWebHostEnvironment env) :
base(configuration)
{
InitEnvironment(env);
}
}
//-------------------------------------------------------------------
// Data members.
//-------------------------------------------------------------------
// Construction.
protected SbmControlApp_Tester_Base()
{
// Application.
Mock<IConfiguration> mockConfiguration = new Mock<IConfiguration>();
Mock<IWebHostEnvironment> mockEnvironment = new Mock<IWebHostEnvironment>();
mockEnvironment.Setup(m => m.EnvironmentName).Returns(Environments.Development);
mockEnvironment.Setup(m => m.ContentRootPath).Returns(@"D:\Sarand\Projects\Users\AHoward\VS2022\BusinessMgr\Workspace\SaBusinessMgrCoreWebControl");
App = new SbmApplication_Control_Test(mockConfiguration.Object, mockEnvironment.Object);
// Session configuration.
SessionContextIdx = App.GetSessionContextIdxs()[0];
SessionContext = App.GetSessionContext(SessionContextIdx);
Internals = new SbmInternals(GetUserContext(SessionContext));
Internals_Control = new SbmInternals_Control();
UserContext = GetUserContext(SessionContext);
}
//-------------------------------------------------------------------
// Properties.
protected ushort SessionContextIdx { get; }
protected SbmApplication_Control App { get; }
protected SbmSessionContext SessionContext { get; }
protected ISacsDatabase BusMgrDatabase { get { return App.GetBusMgrDatabase(SessionContext); } }
protected SbmInternals Internals { get; }
protected SbmInternals_Control Internals_Control { get; }
protected SbmUserContext UserContext { get; }
//-------------------------------------------------------------------
// User Context.
public static SbmUserContext GetUserContext(SbmSessionContext sessionContext)
{
SbmUserContext userContext = new SbmUserContext_Web(sessionContext);
return userContext;
}
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -0,0 +1,89 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
using Sarand.BusinessMgr.Web.Control.App;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Security;
using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
namespace Sarand.BusinessMgr.Test.Web.Control.App
{
//=======================================================================
[TestClass]
public class SbmSessionData_Control_Test : SbmControlApp_Tester_Base
{
//-------------------------------------------------------------------
// Data members.
//-------------------------------------------------------------------
// Construction.
public SbmSessionData_Control_Test()
{
}
//-------------------------------------------------------------------
[TestMethod]
public void Test_SbmSessionData_Control_Serialization()
{
// Internals.
SaSecurityConsole securityConsole = App.CreateSecurityConsole(UserContext);
Assert.IsNotNull(securityConsole);
SbmcAccountMgr accountMgr = Internals_Control.ControlAccountMgr;
Assert.IsNotNull(accountMgr);
// User account.
SbmcUserAccount userAccount = accountMgr.GetUserAccountByEmailAddress("andy@sarand.com");
Assert.IsNotNull(userAccount);
// Populate User Session.
SbmSessionData_Control sessionData = new SbmSessionData_Control(SessionContext, userAccount);
Assert.IsNotNull(sessionData);
// Validate user session.
Assert.IsNotNull(sessionData.User);
// User details.
Assert.AreEqual(userAccount.Id, sessionData.User.UserAccountId);
Assert.AreEqual(userAccount.EmailAddress, sessionData.User.EmailAddress);
Assert.AreEqual(userAccount.FirstName, sessionData.User.FirstName);
Assert.AreEqual(userAccount.LastName, sessionData.User.LastName);
Assert.AreEqual(userAccount.GetDisplayName(), sessionData.User.DisplayName);
// Serialise data.
string sessionDataJson = JsonConvert.SerializeObject(sessionData);
Assert.IsNotNull(sessionDataJson);
// Deserialise data.
SbmSessionData_Control? sessionDataDeserialized = JsonConvert.DeserializeObject<SbmSessionData_Control>(sessionDataJson, SbmController_Web.SbmSessionDataJsonSerializerSettings);
Assert.IsNotNull(sessionDataDeserialized);
// Validate deserialised data.
Assert.IsTrue(!StringUtil.IsBlank(sessionData.Base64IV_ControlApp));
Assert.IsTrue(!StringUtil.IsBlank(sessionDataDeserialized.Base64IV_ControlApp));
Assert.AreEqual(sessionData.Base64IV_ControlApp, sessionDataDeserialized.Base64IV_ControlApp);
Assert.IsTrue(sessionData.SessionIdx >= 1000);
Assert.AreEqual(sessionData.SessionIdx, sessionDataDeserialized.SessionIdx);
Assert.IsTrue(sessionData.ItemIdx >= 1000);
Assert.AreEqual(sessionData.ItemIdx, sessionDataDeserialized.ItemIdx);
// User details.
Assert.IsNotNull(sessionDataDeserialized.User);
Assert.AreEqual(userAccount.Id, sessionDataDeserialized.User.UserAccountId);
Assert.AreEqual(userAccount.EmailAddress, sessionDataDeserialized.User.EmailAddress);
Assert.AreEqual(userAccount.FirstName, sessionDataDeserialized.User.FirstName);
Assert.AreEqual(userAccount.LastName, sessionDataDeserialized.User.LastName);
Assert.AreEqual(userAccount.GetDisplayName(), sessionDataDeserialized.User.DisplayName);
}
}
//=======================================================================
}