Control - Repository initialisation.
This commit is contained in:
@@ -1,71 +1,78 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
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.Bus.Control;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.BusinessMgr.Web.Control.App;
|
||||
using Sarand.BusinessMgr.Web.Control.Consoles;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using System;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
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.
|
||||
//-------------------------------------------------------------------
|
||||
// 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.GetSessionContextByIndex(SessionContextIdx);
|
||||
Internals = new SbmInternals(GetUserContext(SessionContext));
|
||||
//-------------------------------------------------------------------
|
||||
// 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);
|
||||
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; }
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected SbmApplication_Control App { 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);
|
||||
//-------------------------------------------------------------------
|
||||
// User Context.
|
||||
public static SbmUserContext GetUserContext(SbmSessionContext sessionContext)
|
||||
{
|
||||
SbmUserContext userContext = new SbmUserContext_Web(sessionContext);
|
||||
|
||||
return userContext;
|
||||
}
|
||||
return userContext;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
//-------------------------------------------------------------------
|
||||
// Core Instance Console.
|
||||
protected SbmCoreInstanceConsole_Control CreateCoreInstanceConsole(String instanceContext)
|
||||
{
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposables = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
SbmcRepository repository = Internals_Control.ControlInstanceMgr.GetRepositoryByContext(instanceContext);
|
||||
disposables.Add(repository);
|
||||
return new SbmCoreInstanceConsole_Control(repository);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.ApplicationInsights.Extensibility.Implementation;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Controllers;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
@@ -34,8 +35,6 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
|
||||
{
|
||||
|
||||
// Internals.
|
||||
SaSecurityConsole securityConsole = App.CreateSecurityConsole(UserContext);
|
||||
Assert.IsNotNull(securityConsole);
|
||||
SbmcAccountMgr accountMgr = Internals_Control.ControlAccountMgr;
|
||||
Assert.IsNotNull(accountMgr);
|
||||
|
||||
@@ -43,10 +42,15 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
|
||||
SbmcUserAccount userAccount = accountMgr.GetUserAccountByEmailAddress("andy@sarand.com");
|
||||
Assert.IsNotNull(userAccount);
|
||||
|
||||
// Session Context?
|
||||
SbmSessionContext sessionContext_Core = null;
|
||||
|
||||
// Populate User Session.
|
||||
SbmSessionData_Control sessionData = new SbmSessionData_Control(SessionContext, userAccount);
|
||||
SbmSessionData_Control sessionData = new SbmSessionData_Control(sessionContext_Core, userAccount);
|
||||
Assert.IsNotNull(sessionData);
|
||||
Assert.IsTrue(!StringUtil.IsBlank(sessionData.Base64IV_ControlApp));
|
||||
Assert.IsTrue(sessionData.SessionIdx >= 1000);
|
||||
Assert.IsTrue(sessionData.ItemIdx >= 1000);
|
||||
|
||||
// Validate user session.
|
||||
Assert.IsNotNull(sessionData.User);
|
||||
@@ -68,12 +72,9 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user