Migrate BusinessMgr tests to NUnit

This commit is contained in:
Andy Howard
2026-09-15 10:29:35 +01:00
parent 3f2f8c16ef
commit de07f2120f
16 changed files with 333 additions and 411 deletions
+3 -3
View File
@@ -18,7 +18,7 @@ dotnet run --project SaBusinessMgrCoreWebControl
dotnet run --project SaBusinessMgrCoreWebPortal
```
For the standard repository validation, run `./eng/validate.ps1`. It selects Visual Studio MSBuild for the SSDT-dependent Portal test project, runs both test assemblies, and performs repository checks; see `eng/README.md`.
For the standard repository validation, run `./eng/validate.ps1`. It restores and builds the solution with the .NET CLI, runs both NUnit test projects, and performs repository checks; see `eng/README.md`.
When validation requirements, solution structure, target frameworks, test projects, package-audit scope, or required tooling change, update `eng/validate.ps1` and `eng/README.md` as part of the same change. Run the updated script before handoff. Do not bypass a failing validation stage without documenting the reason.
@@ -30,7 +30,7 @@ For changes to Common public APIs, target frameworks, packages, or shared behavi
Match existing C# conventions: tabs, braces on new lines, top-of-file `using` directives, PascalCase public members, and established `Sbm`/`Sacs` prefixes. Tests use descriptive names such as `Test_Application_ControlDatabase`. No repository-wide formatter is configured, so follow nearby code. Target the framework versions declared in project files. Do not upgrade frameworks or NuGet packages unless explicitly requested.
Across all code files that support `//` line comments, use meaningful section comments instead of solid decorative comment lines. Format a section delimiter as `// --- Caption ---`, where the caption describes the code that follows, such as `Data Members`, `Construction`, `Properties`, `Test Support`, or another context-specific description. Reserve `Utilities` for internal methods that provide relatively simple supporting functionality; use a more specific caption for complex or domain-significant behavior. A delimiter may be followed by explanatory comments when useful. Surround the complete comment block with a blank line so it is visually separate from the preceding and following code; omit only the outside blank line that would otherwise appear directly after an opening brace or directly before a closing brace. Finish the file's main outer class or type block with `// --- The End ---` immediately before its closing brace. Leave nested or internal classes/types comment-free unless the type is complex enough to warrant sections and is at least 32 lines long; `// --- The End ---` is not required for such nested types. Do not add other delimiters where they do not clarify a distinct section. Apply this convention to new files. When an existing file receives significant modification, bring its section comments into line throughout that file as part of the same edit; small, isolated changes do not require unrelated wholesale reformatting.
Across all code files that support `//` line comments, use meaningful section comments instead of solid decorative comment lines. Format a section delimiter as `// --- Caption ---`, where the caption describes the code that follows, such as `Data Members`, `Construction`, `Properties`, `Test Support`, or another context-specific description. `Definitions` is appropriate where the following code declares classes, structs, interfaces, enums, or similar types. Reserve `Utilities` for internal methods that provide relatively simple supporting functionality; use a more specific caption for complex or domain-significant behavior. A delimiter may be followed by explanatory comments when useful. Surround the complete comment block with a blank line so it is visually separate from the preceding and following code; omit only the outside blank line that would otherwise appear directly after an opening brace or directly before a closing brace. Finish the file's main outer class or type block with `// --- The End ---` immediately before its closing brace. Leave nested or internal classes/types comment-free unless the type is complex enough to warrant sections and is at least 32 lines long; `// --- The End ---` is not required for such nested types. Do not add other delimiters where they do not clarify a distinct section. Apply this convention to new files. When an existing file receives significant modification, bring its section comments into line throughout that file as part of the same edit; small, isolated changes do not require unrelated wholesale reformatting.
Processes derived from `SaProcess_Base` must actively poll `IsInterrupted` during long-running loops and before expensive or blocking stages, then exit promptly when cancellation is requested.
@@ -49,7 +49,7 @@ table td {
## Testing Guidelines
Tests use MSTest with Moq and coverlet. Add `[TestClass]` and `[TestMethod]` attributes and place tests in the project matching the affected application. Run the relevant test project after a change, and run the full solution tests when the change crosses project boundaries. Several tests access configured databases and are integration-oriented; verify machine configuration and test data before assuming failures are isolated unit-test regressions.
Tests use NUnit with Moq and coverlet. Add `[TestFixture]` and `[Test]` attributes, use the NUnit constraint model with `Assert.That` wherever possible, and place tests in the project matching the affected application. Run the relevant test project after a change, and run the full solution tests when the change crosses project boundaries. Several tests access configured databases and are integration-oriented; verify machine configuration and test data before assuming failures are isolated unit-test regressions.
## Change Discipline
@@ -6,7 +6,7 @@ using Sarand.Net.Standard.Base.Security;
namespace Sarand.BusinessMgr.Test.Base.Helpers
{
[TestClass]
[TestFixture]
public class PasswordHelper_Tester
{
// --- Test Data ---
@@ -18,33 +18,33 @@ namespace Sarand.BusinessMgr.Test.Base.Helpers
// --- Password Hashing ---
[TestMethod]
[Test]
public void SbmPasswordHash_RoundTripsAndRejectsWrongPassword()
{
TestSecurityItem securityItem = new TestSecurityItem();
string passwordHash = SbmPasswordHelper.GetPasswordHash(securityItem, Password);
securityItem.SetPasswordHash(passwordHash);
Assert.IsTrue(SbmPasswordHelper.VerifyHashedPassword(securityItem, Password));
Assert.IsTrue(SbmPasswordHelper.VerifyHashedPassword(securityItem, Password, passwordHash));
Assert.IsFalse(SbmPasswordHelper.VerifyHashedPassword(securityItem, WrongPassword, passwordHash));
Assert.IsFalse(SbmPasswordHelper.PasswordRequiresRehash(securityItem, Password));
Assert.That(SbmPasswordHelper.VerifyHashedPassword(securityItem, Password), Is.True);
Assert.That(SbmPasswordHelper.VerifyHashedPassword(securityItem, Password, passwordHash), Is.True);
Assert.That(SbmPasswordHelper.VerifyHashedPassword(securityItem, WrongPassword, passwordHash), Is.False);
Assert.That(SbmPasswordHelper.PasswordRequiresRehash(securityItem, Password), Is.False);
}
[TestMethod]
[Test]
public void SbmcPasswordHash_RoundTripsAndRejectsWrongPassword()
{
TestUserAccount userAccount = new TestUserAccount();
string passwordHash = SbmcPasswordHelper.GetPasswordHash(userAccount, Password);
userAccount.PasswordHashed = passwordHash;
Assert.IsTrue(SbmcPasswordHelper.VerifyHashedPassword(userAccount, Password));
Assert.IsTrue(SbmcPasswordHelper.VerifyHashedPassword(userAccount, Password, passwordHash));
Assert.IsFalse(SbmcPasswordHelper.VerifyHashedPassword(userAccount, WrongPassword, passwordHash));
Assert.IsFalse(SbmcPasswordHelper.PasswordRequiresRehash(userAccount, Password));
Assert.That(SbmcPasswordHelper.VerifyHashedPassword(userAccount, Password), Is.True);
Assert.That(SbmcPasswordHelper.VerifyHashedPassword(userAccount, Password, passwordHash), Is.True);
Assert.That(SbmcPasswordHelper.VerifyHashedPassword(userAccount, WrongPassword, passwordHash), Is.False);
Assert.That(SbmcPasswordHelper.PasswordRequiresRehash(userAccount, Password), Is.False);
}
[TestMethod]
[Test]
public void LegacyIdentityV3Hash_RemainsValidAndRequiresRehash()
{
TestSecurityItem securityItem = new TestSecurityItem();
@@ -52,13 +52,13 @@ namespace Sarand.BusinessMgr.Test.Base.Helpers
securityItem.SetPasswordHash(LegacyIdentityV3Hash);
userAccount.PasswordHashed = LegacyIdentityV3Hash;
Assert.IsTrue(SbmPasswordHelper.VerifyHashedPassword(securityItem, LegacyPassword, LegacyIdentityV3Hash));
Assert.IsTrue(SbmcPasswordHelper.VerifyHashedPassword(userAccount, LegacyPassword, LegacyIdentityV3Hash));
Assert.IsTrue(SbmPasswordHelper.PasswordRequiresRehash(securityItem, LegacyPassword));
Assert.IsTrue(SbmcPasswordHelper.PasswordRequiresRehash(userAccount, LegacyPassword));
Assert.That(SbmPasswordHelper.VerifyHashedPassword(securityItem, LegacyPassword, LegacyIdentityV3Hash), Is.True);
Assert.That(SbmcPasswordHelper.VerifyHashedPassword(userAccount, LegacyPassword, LegacyIdentityV3Hash), Is.True);
Assert.That(SbmPasswordHelper.PasswordRequiresRehash(securityItem, LegacyPassword), Is.True);
Assert.That(SbmcPasswordHelper.PasswordRequiresRehash(userAccount, LegacyPassword), Is.True);
}
// --- Test Support ---
// --- Definitions ---
private sealed class TestSecurityItem : SaSecurityItem
{
@@ -17,8 +17,15 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="4.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.4.0" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit.Analyzers" Version="4.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.Odbc" Version="6.0.2" />
</ItemGroup>
@@ -35,7 +42,7 @@
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>
@@ -1,5 +1,4 @@
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Newtonsoft.Json;
using Sarand.BusinessMgr.Net.Core.Web.Components;
using Sarand.BusinessMgr.Net.Standard.Base.App;
@@ -17,77 +16,78 @@ using System.Collections.Generic;
namespace Sarand.BusinessMgr.Test.Web.Control.App
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmApplication_SessionData_Tester : SbmApplication_Tester_Base
{
//-------------------------------------------------------------------
// Data members.
//-------------------------------------------------------------------
// Construction.
// --- Construction ---
public SbmApplication_SessionData_Tester()
{
}
//-------------------------------------------------------------------
[TestMethod]
// --- Tests ---
[Test]
public void Test_Application_SessionData_Serialization()
{
using (DisposableCollection<ISacsDisposable> disposables = new DisposableCollection<ISacsDisposable>())
{
// Internals.
SbmcAccountMgr accountMgr = Internals_Control.ControlAccountMgr;
Assert.IsNotNull(accountMgr);
Assert.That(accountMgr, Is.Not.Null);
// User account.
SbmcUserAccount userAccount = accountMgr.GetUserAccountByEmailAddress("andy@sarand.com");
Assert.IsNotNull(userAccount);
Assert.That(userAccount, Is.Not.Null);
// Session Context?
SbmSessionContext? sessionContext_Core = null;
// Populate User Session.
SbmSessionData_Control sessionData = new SbmSessionData_Control(sessionContext_Core, userAccount);
Assert.IsNotNull(sessionData);
Assert.IsTrue(!StringUtil.IsBlank(sessionData.Base64IV_ControlApp));
Assert.IsTrue(sessionData.SessionIdx >= 100000);
Assert.IsTrue(sessionData.DataIdx >= 1000000);
Assert.That(sessionData, Is.Not.Null);
Assert.That(!StringUtil.IsBlank(sessionData.Base64IV_ControlApp), Is.True);
Assert.That(sessionData.SessionIdx >= 100000, Is.True);
Assert.That(sessionData.DataIdx >= 1000000, Is.True);
// Validate user session.
Assert.IsNotNull(sessionData.User);
Assert.That(sessionData.User, Is.Not.Null);
// 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);
Assert.That(sessionData.User.UserAccountId, Is.EqualTo(userAccount.Id));
Assert.That(sessionData.User.EmailAddress, Is.EqualTo(userAccount.EmailAddress));
Assert.That(sessionData.User.FirstName, Is.EqualTo(userAccount.FirstName));
Assert.That(sessionData.User.LastName, Is.EqualTo(userAccount.LastName));
Assert.That(sessionData.User.DisplayName, Is.EqualTo(userAccount.GetDisplayName()));
// Serialise data.
string sessionDataJson = JsonConvert.SerializeObject(sessionData, SbmController_Web.SessionDataJsonSerializerSettings);
Assert.IsNotNull(sessionDataJson);
Assert.That(sessionDataJson, Is.Not.Null);
// Deserialise data.
SbmSessionData_Control? sessionDataDeserialized = JsonConvert.DeserializeObject<SbmSessionData_Control>(sessionDataJson, SbmController_Web.SessionDataJsonDeserializerSettings);
Assert.IsNotNull(sessionDataDeserialized);
Assert.That(sessionDataDeserialized, Is.Not.Null);
// Validate deserialised data.
Assert.IsTrue(!StringUtil.IsBlank(sessionDataDeserialized.Base64IV_ControlApp));
Assert.AreEqual(sessionData.Base64IV_ControlApp, sessionDataDeserialized.Base64IV_ControlApp);
Assert.AreEqual(sessionData.SessionIdx, sessionDataDeserialized.SessionIdx);
Assert.IsTrue(sessionDataDeserialized.DataIdx > sessionData.DataIdx);
Assert.That(!StringUtil.IsBlank(sessionDataDeserialized.Base64IV_ControlApp), Is.True);
Assert.That(sessionDataDeserialized.Base64IV_ControlApp, Is.EqualTo(sessionData.Base64IV_ControlApp));
Assert.That(sessionDataDeserialized.SessionIdx, Is.EqualTo(sessionData.SessionIdx));
Assert.That(sessionDataDeserialized.DataIdx > sessionData.DataIdx, Is.True);
// 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);
Assert.That(sessionDataDeserialized.User, Is.Not.Null);
Assert.That(sessionDataDeserialized.User.UserAccountId, Is.EqualTo(userAccount.Id));
Assert.That(sessionDataDeserialized.User.EmailAddress, Is.EqualTo(userAccount.EmailAddress));
Assert.That(sessionDataDeserialized.User.FirstName, Is.EqualTo(userAccount.FirstName));
Assert.That(sessionDataDeserialized.User.LastName, Is.EqualTo(userAccount.LastName));
Assert.That(sessionDataDeserialized.User.DisplayName, Is.EqualTo(userAccount.GetDisplayName()));
}
}
// --- The End ---
}
//=======================================================================
}
@@ -1,4 +1,4 @@
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
using Sarand.BusinessMgr.Web.Control.Consoles;
@@ -8,74 +8,72 @@ using Sarand.Net.Standard.Base.Security;
namespace Sarand.BusinessMgr.Test.Web.Control.App
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmApplication_Tester : SbmApplication_Tester_Base
{
//-------------------------------------------------------------------
[TestMethod]
// --- Tests ---
[Test]
public void Test_Application_Application()
{
// Application.
Assert.IsNotNull(App);
Assert.IsNotNull(App_Web);
Assert.IsNotNull(App_Control);
Assert.That(App, Is.Not.Null);
Assert.That(App_Web, Is.Not.Null);
Assert.That(App_Control, Is.Not.Null);
Assert.That(SessionData_Control, Is.Not.Null);
Assert.That(SessionData_Control.User, Is.Not.Null);
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_ControlDatabase()
{
// Control database.
ISacsDatabase db = App.GetControlDatabase();
Assert.IsNotNull(db);
Assert.That(db, Is.Not.Null);
// Tables.
Assert.IsTrue(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Owner)));
Assert.IsTrue(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Repository)));
Assert.That(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Owner)), Is.True);
Assert.That(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Repository)), Is.True);
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_TemplateDatabase()
{
// Template database.
ISacsDatabase db = App.GetTemplateDatabase();
Assert.IsNotNull(db);
Assert.That(db, Is.Not.Null);
// Tables.
Assert.IsTrue(db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Affiliate)));
Assert.IsTrue(db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity)));
Assert.IsTrue(db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction, false)));
Assert.IsTrue(db.TableExists(SaSecurityDbDfn.GetTableName(SaSecurityDbDfn.TableIdx.SaSecItem)));
Assert.That(db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Affiliate)), Is.True);
Assert.That(db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity)), Is.True);
Assert.That(db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction, false)), Is.True);
Assert.That(db.TableExists(SaSecurityDbDfn.GetTableName(SaSecurityDbDfn.TableIdx.SaSecItem)), Is.True);
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_Internals_Control()
{
// Record disposable items as they are created so all can be disposed when needed.
using (DisposableCollection<ISacsDisposable> disposables = new DisposableCollection<ISacsDisposable>())
{
// Control internals.
Assert.IsNotNull(Internals_Control);
Assert.That(Internals_Control, Is.Not.Null);
// Owners.
Assert.IsNotNull(Internals_Control.ControlInstanceMgr);
Assert.That(Internals_Control.ControlInstanceMgr, Is.Not.Null);
SbmcOwner.Params prmOwner = new SbmcOwner.Params();
prmOwner.StatusCat = SbmcOwner.StatusCat.ActiveOnly;
Assert.IsTrue(Internals_Control.ControlInstanceMgr.GetOwnerCount(prmOwner) > 0);
Assert.That(Internals_Control.ControlInstanceMgr.GetOwnerCount(prmOwner) > 0, Is.True);
// Repositories.
Assert.IsNotNull(Internals_Control.ControlInstanceMgr);
Assert.That(Internals_Control.ControlInstanceMgr, Is.Not.Null);
SbmcRepository.Params prmRepository = new SbmcRepository.Params();
prmRepository.StatusCat = SbmcRepository.StatusCat.ActiveOnly;
Assert.IsTrue(Internals_Control.ControlInstanceMgr.GetRepositoryCount(prmRepository) > 0);
Assert.That(Internals_Control.ControlInstanceMgr.GetRepositoryCount(prmRepository) > 0, Is.True);
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_CoreInstanceConsole()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -83,17 +81,16 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
{
// Repository.
SbmcRepository repository = GetRandomActiveRepository();
Assert.IsNotNull(repository);
Assert.That(repository, Is.Not.Null);
// Instance console.
SbmCoreInstanceConsole instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
disposables.Add(instanceConsole);
Assert.IsNotNull(instanceConsole);
Assert.That(instanceConsole, Is.Not.Null);
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_Internals_Core()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -101,17 +98,16 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
{
// Repository.
SbmcRepository repository = GetRandomActiveRepository();
Assert.IsNotNull(repository);
Assert.That(repository, Is.Not.Null);
// Instance console.
SbmCoreInstanceConsole instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
disposables.Add(instanceConsole);
Assert.IsNotNull(instanceConsole);
Assert.That(instanceConsole, Is.Not.Null);
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_SessionContexts()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -119,21 +115,20 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
{
// Repository.
SbmcRepository repository = GetRandomActiveRepository();
Assert.IsNotNull(repository);
Assert.That(repository, Is.Not.Null);
SbmCoreInstanceConsole instanceConsole = new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
disposables.Add(instanceConsole);
Assert.IsNotNull(instanceConsole);
Assert.That(instanceConsole, Is.Not.Null);
// Session Context.
ushort sessionIdx = App_Control.GetCoreSessionIndexForControlRepository(repository.Id);
SbmSessionContext sessionContext = App_Control.GetSessionContextByIndex(sessionIdx);
Assert.IsNotNull(sessionContext);
Assert.AreEqual(sessionIdx, sessionContext.Index);
Assert.That(sessionContext, Is.Not.Null);
Assert.That(sessionContext.Index, Is.EqualTo(sessionIdx));
}
}
//-------------------------------------------------------------------
// --- The End ---
}
//=======================================================================
}
@@ -1,4 +1,3 @@
using DocumentFormat.OpenXml.EMMA;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
@@ -17,11 +16,10 @@ using System;
namespace Sarand.BusinessMgr.Test.Web.Control.App
{
//=======================================================================
public class SbmApplication_Tester_Base : SacsDisposable
{
//-------------------------------------------------------------------
// Application.
// --- Definitions ---
private class SbmApplication_Control_Test : SbmApplication_Control
{
public SbmApplication_Control_Test(IConfiguration configuration, IWebHostEnvironment env) :
@@ -31,11 +29,8 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
}
}
//-------------------------------------------------------------------
// Data members.
// --- Construction ---
//-------------------------------------------------------------------
// Construction.
protected SbmApplication_Tester_Base()
{
// Application.
@@ -46,8 +41,10 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
App_Control = new SbmApplication_Control_Test(mockConfiguration.Object, mockEnvironment.Object);
Internals_Control = new SbmInternals_Control();
// Control session data.
//SessionData_Control = new SbmSessionData_Control();
// Control session data, matching the minimal session used by the serialization tests.
SbmcAccountMgr accountMgr = Internals_Control.ControlAccountMgr;
SbmcUserAccount userAccount = accountMgr.GetUserAccountByEmailAddress("andy@sarand.com");
SessionData_Control = new SbmSessionData_Control(null, userAccount);
}
protected override void Dispose(bool disposing)
@@ -58,27 +55,27 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
}
}
//-------------------------------------------------------------------
// Properties.
// --- Properties ---
protected SbmApplication App { get { return App_Control; } }
protected SbmApplication_Web App_Web { get { return App_Control; } }
protected SbmApplication_Control App_Control { get; }
protected SbmSessionData_Control SessionData_Control { get; private set; }
protected SbmInternals_Control Internals_Control { get; private set; }
// Utilities.
// --- Utilities ---
protected SbmInternals_Control CreateInternalsControl() { return new SbmInternals_Control(); }
//-------------------------------------------------------------------
// Core Instance Console.
// --- Core Instance Console ---
protected SbmCoreInstanceConsole_Control CreateCoreInstanceConsole(String repositoryContext)
{
SbmcRepository repository = Internals_Control.ControlInstanceMgr.GetRepositoryByContext(repositoryContext);
return new SbmCoreInstanceConsole_Control(SessionData_Control, repository);
}
//-------------------------------------------------------------------
// Repositories.
// --- Repositories ---
/// <summary>
/// Retrieve an active repository, randomly selected.
@@ -106,7 +103,6 @@ namespace Sarand.BusinessMgr.Test.Web.Control.App
return Internals_Control.ControlInstanceMgr.GetRepositoryList(prmRepository).First();
}
//-------------------------------------------------------------------
// --- The End ---
}
//=======================================================================
}
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Sarand.BusinessMgr.Net.Standard.Base.Helpers;
using System;
using System.Collections.Generic;
@@ -8,50 +8,49 @@ using System.Threading.Tasks;
namespace Sarand.BusinessMgr.Test.Base.Helpers
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmResourceHelper_Tester
{
//-------------------------------------------------------------------
// Text resources.
[TestMethod]
// --- Tests ---
[Test]
public void Test_GetResourceText_Email()
{
// Email resources.
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Header_Html));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Header_Html).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Footer_Html));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Footer_Html).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Main_Css));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Main_Css).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_DemoAccountRequest_Html));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_DemoAccountRequest_Html).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_RequestPassword_Html));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_RequestPassword_Html).Length > 0);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Header_Html), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Header_Html).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Footer_Html), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Footer_Html).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Main_Css), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_Main_Css).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_DemoAccountRequest_Html), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_DemoAccountRequest_Html).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_RequestPassword_Html), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.Email_RequestPassword_Html).Length > 0, Is.True);
}
[TestMethod]
[Test]
public void Test_GetResourceText_Html()
{
// Email resources.
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SaBaseCss));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SaBaseCss).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseCss));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseCss).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryJs));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryJs).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiCss));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiCss).Length > 0);
Assert.IsNotNull(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiJs));
Assert.IsTrue(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiJs).Length > 0);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SaBaseCss), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SaBaseCss).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseCss), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseCss).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.SbmBaseJs).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryJs), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryJs).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiCss), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiCss).Length > 0, Is.True);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiJs), Is.Not.Null);
Assert.That(SbmResourceHelper.GetResourceText(SbmResourceHelper.TextResource.JQueryUiJs).Length > 0, Is.True);
}
//-------------------------------------------------------------------
// --- The End ---
}
//=======================================================================
}
+10 -30
View File
@@ -1,43 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<SSDTUnitTestPath Condition="'$(SSDTUnitTestPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB</SSDTUnitTestPath>
</PropertyGroup>
<PropertyGroup>
<SSDTPath Condition="'$(SSDTPath)' == ''">$(VsInstallRoot)\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130</SSDTPath>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Sarand.BusinessMgr.Test</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="4.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.4.0" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit.Analyzers" Version="4.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.Odbc" Version="6.0.2" />
</ItemGroup>
<ItemGroup Condition="$(VisualStudioVersion) == '16.0'">
<Reference Include="Microsoft.Data.Tools.Schema.Sql, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>$(SSDTPath)\Microsoft.Data.Tools.Schema.Sql.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Data.Tools.Schema.Sql.UnitTesting, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>$(SSDTUnitTestPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Data.Tools.Schema.Sql.UnitTestingAdapter, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>$(SSDTUnitTestPath)\Microsoft.Data.Tools.Schema.Sql.UnitTestingAdapter.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsCoreWeb\SacsCoreWeb.csproj" />
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
@@ -49,9 +34,4 @@
<ProjectReference Include="..\SaBusMgrStandardBase\SaBusMgrStandardBase.csproj" />
<ProjectReference Include="..\SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj" />
</ItemGroup>
<PropertyGroup>
<SsdtUnitTestVersion>3.1</SsdtUnitTestVersion>
</PropertyGroup>
<Import Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets" Condition="$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' == ''" />
</Project>
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Sarand.BusinessMgr.Net.Core.Web.Consoles;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.App;
@@ -12,15 +12,16 @@ using System.Text.RegularExpressions;
namespace Sarand.BusinessMgr.Test.Web.Portal.App
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmApplication_Database_Tester : SbmApplication_Tester_Base
{
//-------------------------------------------------------------------
// --- Data Members ---
private static Regex reHex = new Regex("^(?:[A-F0-9]{2})+$", RegexOptions.IgnoreCase);
//-------------------------------------------------------------------
[TestMethod]
// --- Tests ---
[Test]
public void Test_PasswordEncoding()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -29,23 +30,22 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Session configuration.
string repositoryContext = "Mimo";
SbmSessionContext sessionContext = GetCoreSessionContext(repositoryContext);
Assert.IsNotNull(sessionContext);
Assert.That(sessionContext, Is.Not.Null);
SbmInternals internals = new SbmInternals(GetSessionData(sessionContext, repositoryContext));
disposables.Add(internals);
SaSecurityConsole securityConsole = internals.SecurityConsole;
StringAssert.Matches(securityConsole.EncodePassword_Hex(""), reHex);
Assert.That(securityConsole.EncodePassword_Hex(""), Does.Match(reHex));
// Iterate using random filename (8.3).
for (int i = 0; i < 1000; i++)
StringAssert.Matches(securityConsole.EncodePassword_Hex(Path.GetRandomFileName()), reHex);
Assert.That(securityConsole.EncodePassword_Hex(Path.GetRandomFileName()), Does.Match(reHex));
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_PasswordCompare()
{
Dictionary<string, string> passwordHashes = new Dictionary<string, string>();
@@ -56,7 +56,7 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Session configuration.
string repositoryContext = "Mimo";
SbmSessionContext sessionContext = GetCoreSessionContext(repositoryContext);
Assert.IsNotNull(sessionContext);
Assert.That(sessionContext, Is.Not.Null);
SbmInternals internals = new SbmInternals(GetSessionData(sessionContext, repositoryContext));
disposables.Add(internals);
@@ -67,19 +67,18 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
{
string password = Path.GetRandomFileName();
string passwordHash = securityConsole.EncodePassword_Hex(password);
StringAssert.Matches(passwordHash, reHex);
Assert.That(passwordHash, Does.Match(reHex));
passwordHashes.Add(password, passwordHash);
}
foreach (string password in passwordHashes.Keys)
{
string passwordHash = passwordHashes.GetValueOrDefault(password);
StringAssert.Matches(passwordHash, reHex);
Assert.IsTrue(securityConsole.ComparePassword_Hex(password, passwordHash));
Assert.That(passwordHash, Does.Match(reHex));
Assert.That(securityConsole.ComparePassword_Hex(password, passwordHash), Is.True);
}
}
}
//-------------------------------------------------------------------
// --- The End ---
}
//=======================================================================
}
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Newtonsoft.Json;
using Sarand.BusinessMgr.Net.Core.Web.Components;
using Sarand.BusinessMgr.Net.Standard.Base.App;
@@ -12,12 +12,12 @@ using Sarand.Net.Standard.Dbas.Base;
namespace Sarand.BusinessMgr.Test.Web.Portal.App
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmApplication_DemoRepository_Tester : SbmApplication_Tester_Base
{
//-------------------------------------------------------------------
[TestMethod]
// --- Tests ---
[Test]
public void Test_SessionData_Demo()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -26,26 +26,25 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Demo Session configuration.
string repositoryContext = Sbm.RepositoryContext_Demo;
SbmSessionContext sessionContext = GetCoreSessionContext(repositoryContext);
Assert.IsNotNull(sessionContext);
Assert.That(sessionContext, Is.Not.Null);
// Session data.
SbmSessionData_Portal sessionData = new SbmSessionData_Portal(sessionContext, repositoryContext, null, null, null, null);
Assert.IsNotNull(sessionData);
Assert.IsTrue(sessionData.SessionContext.IsDemoRepository());
Assert.That(sessionData, Is.Not.Null);
Assert.That(sessionData.SessionContext.IsDemoRepository(), Is.True);
// Serialise data.
string sessionDataJson = JsonConvert.SerializeObject(sessionData, SbmController_Web.SessionDataJsonSerializerSettings);
Assert.IsNotNull(sessionDataJson);
Assert.That(sessionDataJson, Is.Not.Null);
// Deserialise data.
SbmSessionData_Portal sessionDataDeserialized = JsonConvert.DeserializeObject<SbmSessionData_Portal>(sessionDataJson, SbmController_Web.SessionDataJsonDeserializerSettings);
Assert.IsNotNull(sessionDataDeserialized);
Assert.IsTrue(sessionDataDeserialized.SessionContext.IsDemoRepository());
Assert.That(sessionDataDeserialized, Is.Not.Null);
Assert.That(sessionDataDeserialized.SessionContext.IsDemoRepository(), Is.True);
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_SessionData_NonDemo()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -54,25 +53,24 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Non-Demo Session configuration.
string repositoryContext = "Mimo";
SbmSessionContext sessionContext = GetCoreSessionContext(repositoryContext);
Assert.IsNotNull(sessionContext);
Assert.That(sessionContext, Is.Not.Null);
// Session data.
SbmSessionData_Portal sessionData = new SbmSessionData_Portal(sessionContext, repositoryContext, null, null, null, null);
Assert.IsNotNull(sessionData);
Assert.IsFalse(sessionData.SessionContext.IsDemoRepository());
Assert.That(sessionData, Is.Not.Null);
Assert.That(sessionData.SessionContext.IsDemoRepository(), Is.False);
// Serialise data.
string sessionDataJson = JsonConvert.SerializeObject(sessionData, SbmController_Web.SessionDataJsonSerializerSettings);
Assert.IsNotNull(sessionDataJson);
Assert.That(sessionDataJson, Is.Not.Null);
// Deserialise data.
SbmSessionData_Portal sessionDataDeserialized = JsonConvert.DeserializeObject<SbmSessionData_Portal>(sessionDataJson, SbmController_Web.SessionDataJsonDeserializerSettings);
Assert.IsNotNull(sessionDataDeserialized);
Assert.IsFalse(sessionDataDeserialized.SessionContext.IsDemoRepository());
Assert.That(sessionDataDeserialized, Is.Not.Null);
Assert.That(sessionDataDeserialized.SessionContext.IsDemoRepository(), Is.False);
}
}
//-------------------------------------------------------------------
// --- The End ---
}
//=======================================================================
}
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
@@ -9,44 +9,41 @@ using Sarand.Net.Standard.Dbas.Base;
namespace Sarand.BusinessMgr.Test.Web.Portal.App
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmApplication_Portal_Tester : SbmApplication_Tester_Base
{
//-------------------------------------------------------------------
[TestMethod]
// --- Tests ---
[Test]
public void Test_Application_Application()
{
// Application.
Assert.IsNotNull(App);
Assert.IsNotNull(AppWeb);
Assert.IsNotNull(AppPortal);
Assert.That(App, Is.Not.Null);
Assert.That(AppWeb, Is.Not.Null);
Assert.That(AppPortal, Is.Not.Null);
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_ControlDatabase()
{
// Control database.
ISacsDatabase db = App.GetControlDatabase();
Assert.IsNotNull(db);
Assert.That(db, Is.Not.Null);
// Tables.
Assert.IsTrue(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Owner)));
Assert.IsTrue(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Repository)));
Assert.That(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Owner)), Is.True);
Assert.That(db.TableExists(SbmDbDfn_Control.GetTableName(SbmDbDfn_Control.TableIdx.Repository)), Is.True);
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_TemplateDatabase()
{
// Template database.
ISacsDatabase db = App.GetTemplateDatabase();
Assert.IsNull(db);
Assert.That(db, Is.Null);
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_ControlInternals()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -55,32 +52,30 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Control database.
SbmInternals_Control internalsControl = new SbmInternals_Control();
disposables.Add(internalsControl);
Assert.IsNotNull(internalsControl);
Assert.That(internalsControl, Is.Not.Null);
// Owners.
Assert.IsNotNull(internalsControl.ControlInstanceMgr);
Assert.That(internalsControl.ControlInstanceMgr, Is.Not.Null);
SbmcOwner.Params prmOwner = new SbmcOwner.Params();
Assert.IsTrue(internalsControl.ControlInstanceMgr.GetOwnerCount(prmOwner) > 0);
Assert.That(internalsControl.ControlInstanceMgr.GetOwnerCount(prmOwner) > 0, Is.True);
// Repositories.
Assert.IsNotNull(internalsControl.ControlInstanceMgr);
Assert.That(internalsControl.ControlInstanceMgr, Is.Not.Null);
SbmcRepository.Params prmRepository = new SbmcRepository.Params();
Assert.IsTrue(internalsControl.ControlInstanceMgr.GetRepositoryCount(prmRepository) > 0);
Assert.That(internalsControl.ControlInstanceMgr.GetRepositoryCount(prmRepository) > 0, Is.True);
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_SessionContexts()
{
SbmSessionContext sesionContext = AppPortal.GetControlSessionContextByRepositoryContext("Unknown");
Assert.IsNull(sesionContext);
Assert.That(sesionContext, Is.Null);
sesionContext = AppPortal.GetControlSessionContextByRepositoryContext("Mimo");
Assert.IsNotNull(sesionContext);
Assert.That(sesionContext, Is.Not.Null);
}
//-------------------------------------------------------------------
// --- The End ---
}
//=======================================================================
}
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using Newtonsoft.Json;
using Sarand.BusinessMgr.Net.Core.Web.Components;
using Sarand.BusinessMgr.Net.Standard.Base.App;
@@ -16,21 +16,21 @@ using System.Collections.Generic;
namespace Sarand.BusinessMgr.Test.Web.Portal.App
{
//=======================================================================
[TestClass]
[TestFixture]
public class SbmApplication_SessionData_Tester : SbmApplication_Tester_Base
{
//-------------------------------------------------------------------
// Data members.
//-------------------------------------------------------------------
// Construction.
// --- Construction ---
public SbmApplication_SessionData_Tester()
{
}
//-------------------------------------------------------------------
[TestMethod]
// --- Tests ---
[Test]
public void Test_Application_SessionData_Serialization()
{
// Record disposable items as they are created so all can be disposed when needed.
@@ -39,70 +39,70 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Session configuration.
string repositoryContext = "Mimo";
SbmSessionContext sessionContext = GetCoreSessionContext(repositoryContext);
Assert.IsNotNull(sessionContext);
Assert.That(sessionContext, Is.Not.Null);
ISacsDatabase busMgrDatabase = AppPortal.CreateBusMgrDatabase(sessionContext);
// Session data.
SbmSessionData_Portal sessionData = new SbmSessionData_Portal(sessionContext, repositoryContext, null, null, null, null);
Assert.IsNotNull(sessionData);
Assert.That(sessionData, Is.Not.Null);
// Internals.
SbmInternals internals = new SbmInternals(sessionData);
disposables.Add(internals);
SaSecurityConsole securityConsole = internals.SecurityConsole;
Assert.IsNotNull(securityConsole);
Assert.That(securityConsole, Is.Not.Null);
securityConsole.RegisterSecurityRights();
SbmAccountMgr accountMgr = internals.AccountMgr;
Assert.IsNotNull(accountMgr);
Assert.That(accountMgr, Is.Not.Null);
// Session Console.
SbmSessionConsole sessionConsole = SbmSessionConsole.CreateConsole(internals);
// Security item.
SaSecurityItem securityItemUser = securityConsole.GetUserByEmail("andy@sarand.com");
Assert.IsNotNull(securityItemUser);
Assert.That(securityItemUser, Is.Not.Null);
// Security profile.
// User account.
SbmAffiliate affiliateUser = accountMgr.GetAffiliateByUserId(securityItemUser.Id);
Assert.IsNotNull(affiliateUser);
Assert.That(affiliateUser, Is.Not.Null);
// Organisations.
List<SysIdString> supervisedOrganisations = accountMgr.GetAffiliatesSupervisedBy(affiliateUser.Id);
Assert.IsNotNull(supervisedOrganisations);
Assert.IsTrue(supervisedOrganisations.Count > 0);
Assert.That(supervisedOrganisations, Is.Not.Null);
Assert.That(supervisedOrganisations.Count > 0, Is.True);
SysId affiliateIdOrganisation = supervisedOrganisations[0].Id;
SbmAssociation associationOrganisation = accountMgr.GetInternalAssociation(affiliateIdOrganisation);
Assert.IsNotNull(associationOrganisation);
Assert.That(associationOrganisation, Is.Not.Null);
SbmAffiliate affiliateOrganisation = accountMgr.GetAffiliateById(affiliateIdOrganisation);
Assert.IsNotNull(affiliateOrganisation);
Assert.That(affiliateOrganisation, Is.Not.Null);
// Populate Session data.
sessionData.Refresh(securityItemUser, affiliateUser, associationOrganisation, affiliateOrganisation);
// Validate user session.
Assert.IsNotNull(sessionData.User);
Assert.That(sessionData.User, Is.Not.Null);
// Security item.
Assert.AreEqual(securityItemUser.Id, sessionData.User.SecurityItemId);
Assert.AreEqual(securityItemUser.EmailAddress, sessionData.User.EmailAddress);
Assert.That(sessionData.User.SecurityItemId, Is.EqualTo(securityItemUser.Id));
Assert.That(sessionData.User.EmailAddress, Is.EqualTo(securityItemUser.EmailAddress));
// Security profile.
sessionData.SecurityProfile.RefreshProfile(sessionConsole, securityConsole, securityItemUser.Id, securityConsole.GetRegisteredRights());
Assert.IsTrue(sessionData.SecurityProfile.UserCanCreateContacts());
Assert.IsTrue(sessionData.SecurityProfile.UserCanViewFinancials());
Assert.That(sessionData.SecurityProfile.UserCanCreateContacts(), Is.True);
Assert.That(sessionData.SecurityProfile.UserCanViewFinancials(), Is.True);
// User details.
Assert.AreEqual(affiliateUser.Id, sessionData.User.AffiliateId);
Assert.AreEqual(affiliateUser.FirstName, sessionData.User.FirstName);
Assert.AreEqual(affiliateUser.LastName, sessionData.User.LastName);
Assert.AreEqual(affiliateUser.GetDisplayName(), sessionData.User.DisplayName);
Assert.That(sessionData.User.AffiliateId, Is.EqualTo(affiliateUser.Id));
Assert.That(sessionData.User.FirstName, Is.EqualTo(affiliateUser.FirstName));
Assert.That(sessionData.User.LastName, Is.EqualTo(affiliateUser.LastName));
Assert.That(sessionData.User.DisplayName, Is.EqualTo(affiliateUser.GetDisplayName()));
// Organisation details.
Assert.AreEqual(affiliateOrganisation.Id, sessionData.OrganisationAffiliateId);
Assert.AreEqual(associationOrganisation.Id, sessionData.OrganisationAssociationId);
Assert.That(sessionData.OrganisationAffiliateId, Is.EqualTo(affiliateOrganisation.Id));
Assert.That(sessionData.OrganisationAssociationId, Is.EqualTo(associationOrganisation.Id));
// User profile.
sessionData.Profile.Filter.AssociationId = new SysId(SacsRandomHelper.GetInt32(1000, 1999));
@@ -110,187 +110,181 @@ namespace Sarand.BusinessMgr.Test.Web.Portal.App
// Serialise data.
string sessionDataJson = JsonConvert.SerializeObject(sessionData, SbmController_Web.SessionDataJsonSerializerSettings);
Assert.IsNotNull(sessionDataJson);
Assert.That(sessionDataJson, Is.Not.Null);
// Deserialise data.
SbmSessionData_Portal sessionDataDeserialized = JsonConvert.DeserializeObject<SbmSessionData_Portal>(sessionDataJson, SbmController_Web.SessionDataJsonDeserializerSettings);
Assert.IsNotNull(sessionDataDeserialized);
Assert.That(sessionDataDeserialized, Is.Not.Null);
string sessionDataJsonDeserialized = JsonConvert.SerializeObject(sessionDataDeserialized);
// Validate deserialised data.
Assert.IsTrue(!StringUtil.IsBlank(sessionData.Base64IV_PortalApp));
Assert.IsTrue(!StringUtil.IsBlank(sessionDataDeserialized.Base64IV_PortalApp));
Assert.AreEqual(sessionData.Base64IV_PortalApp, sessionDataDeserialized.Base64IV_PortalApp);
Assert.IsTrue(sessionData.SessionIdx >= 1000);
Assert.AreEqual(sessionData.SessionIdx, sessionDataDeserialized.SessionIdx);
Assert.IsTrue(sessionData.DataIdx >= 1000000);
Assert.IsTrue(sessionDataDeserialized.DataIdx > sessionData.DataIdx);
Assert.AreEqual(repositoryContext, sessionDataDeserialized.RepositoryContext);
Assert.That(!StringUtil.IsBlank(sessionData.Base64IV_PortalApp), Is.True);
Assert.That(!StringUtil.IsBlank(sessionDataDeserialized.Base64IV_PortalApp), Is.True);
Assert.That(sessionDataDeserialized.Base64IV_PortalApp, Is.EqualTo(sessionData.Base64IV_PortalApp));
Assert.That(sessionData.SessionIdx >= 1000, Is.True);
Assert.That(sessionDataDeserialized.SessionIdx, Is.EqualTo(sessionData.SessionIdx));
Assert.That(sessionData.DataIdx >= 1000000, Is.True);
Assert.That(sessionDataDeserialized.DataIdx > sessionData.DataIdx, Is.True);
Assert.That(sessionDataDeserialized.RepositoryContext, Is.EqualTo(repositoryContext));
// Security item.
Assert.IsNotNull(sessionDataDeserialized.User);
Assert.AreEqual(securityItemUser.Id, sessionDataDeserialized.User.SecurityItemId);
Assert.AreEqual(securityItemUser.EmailAddress, sessionDataDeserialized.User.EmailAddress);
Assert.That(sessionDataDeserialized.User, Is.Not.Null);
Assert.That(sessionDataDeserialized.User.SecurityItemId, Is.EqualTo(securityItemUser.Id));
Assert.That(sessionDataDeserialized.User.EmailAddress, Is.EqualTo(securityItemUser.EmailAddress));
// Security profile.
Assert.IsNotNull(sessionDataDeserialized.SecurityProfile);
Assert.AreEqual(sessionData.SecurityProfile.UserCanCreateContacts(), sessionDataDeserialized.SecurityProfile.UserCanCreateContacts());
Assert.IsTrue(sessionDataDeserialized.SecurityProfile.UserCanCreateContacts());
Assert.AreEqual(sessionData.SecurityProfile.UserCanViewFinancials(), sessionDataDeserialized.SecurityProfile.UserCanViewFinancials());
Assert.IsTrue(sessionDataDeserialized.SecurityProfile.UserCanViewFinancials());
Assert.That(sessionDataDeserialized.SecurityProfile, Is.Not.Null);
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanCreateContacts(), Is.EqualTo(sessionData.SecurityProfile.UserCanCreateContacts()));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanCreateContacts(), Is.True);
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanViewFinancials(), Is.EqualTo(sessionData.SecurityProfile.UserCanViewFinancials()));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanViewFinancials(), Is.True);
// User details.
Assert.AreEqual(affiliateUser.Id, sessionDataDeserialized.User.AffiliateId);
Assert.AreEqual(affiliateUser.FirstName, sessionDataDeserialized.User.FirstName);
Assert.AreEqual(affiliateUser.LastName, sessionDataDeserialized.User.LastName);
Assert.AreEqual(affiliateUser.GetDisplayName(), sessionDataDeserialized.User.DisplayName);
Assert.That(sessionDataDeserialized.User.AffiliateId, Is.EqualTo(affiliateUser.Id));
Assert.That(sessionDataDeserialized.User.FirstName, Is.EqualTo(affiliateUser.FirstName));
Assert.That(sessionDataDeserialized.User.LastName, Is.EqualTo(affiliateUser.LastName));
Assert.That(sessionDataDeserialized.User.DisplayName, Is.EqualTo(affiliateUser.GetDisplayName()));
// Organisation details.
Assert.AreEqual(affiliateOrganisation.Id, sessionDataDeserialized.Organisation.AffiliateId);
Assert.AreEqual(associationOrganisation.Id, sessionDataDeserialized.Organisation.AssociationId);
Assert.AreEqual(affiliateOrganisation.Name, sessionDataDeserialized.Organisation.DisplayName);
Assert.That(sessionDataDeserialized.Organisation.AffiliateId, Is.EqualTo(affiliateOrganisation.Id));
Assert.That(sessionDataDeserialized.Organisation.AssociationId, Is.EqualTo(associationOrganisation.Id));
Assert.That(sessionDataDeserialized.Organisation.DisplayName, Is.EqualTo(affiliateOrganisation.Name));
// User profile.
Assert.IsTrue(SysId.ToLong(sessionData.Profile.Filter.AssociationId) >= 1000);
Assert.AreEqual(sessionData.Profile.Filter.AssociationId, sessionDataDeserialized.Profile.Filter.AssociationId);
Assert.That(SysId.ToLong(sessionData.Profile.Filter.AssociationId) >= 1000, Is.True);
Assert.That(sessionDataDeserialized.Profile.Filter.AssociationId, Is.EqualTo(sessionData.Profile.Filter.AssociationId));
}
}
//-------------------------------------------------------------------
[TestMethod]
[Test]
public void Test_Application_SessionData_SecurityProfile()
{
// Record disposable items as they are created so all can be disposed when needed.
using (DisposableCollection<ISacsDisposable> disposables = new DisposableCollection<ISacsDisposable>())
{
//-----------------------------------------------------------
// Initialisation.
// Session configuration.
string repositoryContext = "Mimo";
SbmSessionContext sessionContext = GetCoreSessionContext(repositoryContext);
Assert.IsNotNull(sessionContext);
Assert.That(sessionContext, Is.Not.Null);
ISacsDatabase busMgrDatabase = AppPortal.CreateBusMgrDatabase(sessionContext);
// User Session.
SbmSessionData_Portal sessionData = new SbmSessionData_Portal(sessionContext, repositoryContext, null, null, null, null);
Assert.IsNotNull(sessionData);
Assert.That(sessionData, Is.Not.Null);
// Internals.
SbmInternals internals = new SbmInternals(GetSessionData(sessionContext, repositoryContext));
disposables.Add(internals);
SaSecurityConsole securityConsole = internals.SecurityConsole;
Assert.IsNotNull(securityConsole);
Assert.That(securityConsole, Is.Not.Null);
securityConsole.RegisterSecurityRights();
SbmAccountMgr accountMgr = internals.AccountMgr;
Assert.IsNotNull(accountMgr);
Assert.That(accountMgr, Is.Not.Null);
// Session Console.
SbmSessionConsole sessionConsole = SbmSessionConsole.CreateConsole(internals);
//-----------------------------------------------------------
// Quering.
// Security item.
SaSecurityItem securityItemUser = securityConsole.GetUserByEmail("andy@sarand.com");
Assert.IsNotNull(securityItemUser);
Assert.That(securityItemUser, Is.Not.Null);
// User account.
SbmAffiliate affiliateUser = accountMgr.GetAffiliateByUserId(securityItemUser.Id);
Assert.IsNotNull(affiliateUser);
Assert.That(affiliateUser, Is.Not.Null);
// Organisations.
List<SysIdString> supervisedOrganisations = accountMgr.GetAffiliatesSupervisedBy(affiliateUser.Id);
Assert.IsNotNull(supervisedOrganisations);
Assert.IsTrue(supervisedOrganisations.Count > 0);
Assert.That(supervisedOrganisations, Is.Not.Null);
Assert.That(supervisedOrganisations.Count > 0, Is.True);
SysId affiliateIdOrganisation = supervisedOrganisations[0].Id;
SbmAssociation associationOrganisation = accountMgr.GetInternalAssociation(affiliateIdOrganisation);
Assert.IsNotNull(associationOrganisation);
Assert.That(associationOrganisation, Is.Not.Null);
SbmAffiliate affiliateOrganisation = accountMgr.GetAffiliateById(affiliateIdOrganisation);
Assert.IsNotNull(affiliateOrganisation);
Assert.That(affiliateOrganisation, Is.Not.Null);
//-----------------------------------------------------------
// Population.
// Populate User Session.
sessionData.Refresh(securityItemUser, affiliateUser, associationOrganisation, affiliateOrganisation);
Assert.AreEqual(securityItemUser.Id, sessionData.UserSecurityItemId);
Assert.AreEqual(affiliateUser.Id, sessionData.UserAffiliateId);
Assert.That(sessionData.UserSecurityItemId, Is.EqualTo(securityItemUser.Id));
Assert.That(sessionData.UserAffiliateId, Is.EqualTo(affiliateUser.Id));
// Validate user session.
Assert.IsNotNull(sessionData.User);
Assert.That(sessionData.User, Is.Not.Null);
// Security item.
Assert.AreEqual(securityItemUser.Id, sessionData.User.SecurityItemId);
Assert.AreEqual(securityItemUser.EmailAddress, sessionData.User.EmailAddress);
Assert.That(sessionData.User.SecurityItemId, Is.EqualTo(securityItemUser.Id));
Assert.That(sessionData.User.EmailAddress, Is.EqualTo(securityItemUser.EmailAddress));
// Security profile.
sessionData.SecurityProfile.RefreshProfile(sessionConsole, securityConsole, securityItemUser.Id, securityConsole.GetRegisteredRights());
Assert.IsTrue(sessionData.SecurityProfile.UserCanManageDatabase());
Assert.IsTrue(sessionData.SecurityProfile.UserCanManageInterfaces());
Assert.IsTrue(sessionData.SecurityProfile.UserCanCreateContacts());
Assert.IsTrue(sessionData.SecurityProfile.UserCanViewFinancials());
Assert.IsTrue(sessionData.SecurityProfile.UserCanUpdateItemType(Sbm.ItemType.Asset));
Assert.That(sessionData.SecurityProfile.UserCanManageDatabase(), Is.True);
Assert.That(sessionData.SecurityProfile.UserCanManageInterfaces(), Is.True);
Assert.That(sessionData.SecurityProfile.UserCanCreateContacts(), Is.True);
Assert.That(sessionData.SecurityProfile.UserCanViewFinancials(), Is.True);
Assert.That(sessionData.SecurityProfile.UserCanUpdateItemType(Sbm.ItemType.Asset), Is.True);
//-----------------------------------------------------------
// Storing and Retrieving.
// Serialise data.
string sessionDataJson = JsonConvert.SerializeObject(sessionData, SbmController_Web.SessionDataJsonSerializerSettings);
Assert.IsNotNull(sessionDataJson);
Assert.That(sessionDataJson, Is.Not.Null);
// Deserialise data.
SbmSessionData_Portal sessionDataDeserialized = JsonConvert.DeserializeObject<SbmSessionData_Portal>(sessionDataJson, SbmController_Web.SessionDataJsonDeserializerSettings);
Assert.IsNotNull(sessionDataDeserialized);
Assert.That(sessionDataDeserialized, Is.Not.Null);
string sessionDataJsonDeserialized = JsonConvert.SerializeObject(sessionDataDeserialized);
//-----------------------------------------------------------
// Verifing.
// User.
Assert.AreEqual(securityItemUser.Id, sessionDataDeserialized.UserSecurityItemId);
Assert.AreEqual(affiliateUser.Id, sessionDataDeserialized.UserAffiliateId);
Assert.That(sessionDataDeserialized.UserSecurityItemId, Is.EqualTo(securityItemUser.Id));
Assert.That(sessionDataDeserialized.UserAffiliateId, Is.EqualTo(affiliateUser.Id));
// Security profile.
Assert.IsNotNull(sessionDataDeserialized.SecurityProfile);
Assert.IsTrue(sessionData.SecurityProfile.CompareProfiles(sessionDataDeserialized.SecurityProfile));
Assert.That(sessionDataDeserialized.SecurityProfile, Is.Not.Null);
Assert.That(sessionData.SecurityProfile.CompareProfiles(sessionDataDeserialized.SecurityProfile), Is.True);
// User.
Assert.AreEqual(sessionData.SecurityProfile.UserId, sessionDataDeserialized.SecurityProfile.UserId);
Assert.AreEqual(sessionData.SecurityProfile.UserDisplayName, sessionDataDeserialized.SecurityProfile.UserDisplayName);
Assert.AreEqual(sessionData.SecurityProfile.UserLocation, sessionDataDeserialized.SecurityProfile.UserLocation);
Assert.AreEqual(sessionData.SecurityProfile.UserLastLogin, sessionDataDeserialized.SecurityProfile.UserLastLogin);
Assert.That(sessionDataDeserialized.SecurityProfile.UserId, Is.EqualTo(sessionData.SecurityProfile.UserId));
Assert.That(sessionDataDeserialized.SecurityProfile.UserDisplayName, Is.EqualTo(sessionData.SecurityProfile.UserDisplayName));
Assert.That(sessionDataDeserialized.SecurityProfile.UserLocation, Is.EqualTo(sessionData.SecurityProfile.UserLocation));
Assert.That(sessionDataDeserialized.SecurityProfile.UserLastLogin, Is.EqualTo(sessionData.SecurityProfile.UserLastLogin));
// Security groups.
// Admin.
Assert.AreEqual(sessionData.SecurityProfile.UserCanManageSecurity(), sessionDataDeserialized.SecurityProfile.UserCanManageSecurity());
Assert.AreEqual(sessionData.SecurityProfile.UserCanManageDatabase(), sessionDataDeserialized.SecurityProfile.UserCanManageDatabase());
Assert.AreEqual(sessionData.SecurityProfile.UserCanManageReferenceData(), sessionDataDeserialized.SecurityProfile.UserCanManageReferenceData());
Assert.AreEqual(sessionData.SecurityProfile.UserCanManageInterfaces(), sessionDataDeserialized.SecurityProfile.UserCanManageInterfaces());
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanManageSecurity(), Is.EqualTo(sessionData.SecurityProfile.UserCanManageSecurity()));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanManageDatabase(), Is.EqualTo(sessionData.SecurityProfile.UserCanManageDatabase()));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanManageReferenceData(), Is.EqualTo(sessionData.SecurityProfile.UserCanManageReferenceData()));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanManageInterfaces(), Is.EqualTo(sessionData.SecurityProfile.UserCanManageInterfaces()));
// Manage.
Assert.AreEqual(sessionData.SecurityProfile.UserCanManageTasks(), sessionDataDeserialized.SecurityProfile.UserCanManageTasks());
Assert.AreEqual(sessionData.SecurityProfile.UserCanManageTimesheets(), sessionDataDeserialized.SecurityProfile.UserCanManageTimesheets());
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanManageTasks(), Is.EqualTo(sessionData.SecurityProfile.UserCanManageTasks()));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanManageTimesheets(), Is.EqualTo(sessionData.SecurityProfile.UserCanManageTimesheets()));
// Hard-coded rules.
// Create Contacts.
Assert.AreEqual(sessionData.SecurityProfile.UserCanCreateContacts(), sessionDataDeserialized.SecurityProfile.UserCanCreateContacts());
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanCreateContacts(), Is.EqualTo(sessionData.SecurityProfile.UserCanCreateContacts()));
// View Financials.
Assert.AreEqual(sessionData.SecurityProfile.UserCanViewFinancials(), sessionDataDeserialized.SecurityProfile.UserCanViewFinancials());
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanViewFinancials(), Is.EqualTo(sessionData.SecurityProfile.UserCanViewFinancials()));
// Rules determined by security groups and rights.
// Item types.
Assert.AreEqual(sessionData.SecurityProfile.UserCanCreateItemType(Sbm.ItemType.Asset), sessionDataDeserialized.SecurityProfile.UserCanCreateItemType(Sbm.ItemType.Asset));
Assert.AreEqual(sessionData.SecurityProfile.UserCanUpdateItemType(Sbm.ItemType.Asset), sessionDataDeserialized.SecurityProfile.UserCanUpdateItemType(Sbm.ItemType.Asset));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanCreateItemType(Sbm.ItemType.Asset), Is.EqualTo(sessionData.SecurityProfile.UserCanCreateItemType(Sbm.ItemType.Asset)));
Assert.That(sessionDataDeserialized.SecurityProfile.UserCanUpdateItemType(Sbm.ItemType.Asset), Is.EqualTo(sessionData.SecurityProfile.UserCanUpdateItemType(Sbm.ItemType.Asset)));
//-----------------------------------------------------------
}
}
// --- The End ---
}
//=======================================================================
}
+3 -3
View File
@@ -11,7 +11,7 @@ Last updated: 2026-09-14
| Component | Scope | Status | Date reviewed | Next steps | Notes |
|---|---|---|---|---|---|
| `BusinessMgr.sln` | .NET 10 restore, Debug build, and tests | Migrated; passing with warnings and toolchain requirement | 2026-09-13 | Review remaining framework-specific packages, perform application smoke tests, then release-validate. | All eight projects target `net10.0`. The complete solution builds with Visual Studio 18 MSBuild; the .NET CLI cannot build `SaBusMgrTest_Portal` because its SSDT SQL unit-testing targets are Visual Studio-specific (`MSB4278`). Control tests pass 11 of 11 and Portal tests pass 13 of 13. The Identity-related `NU1903` warnings have been removed. |
| `BusinessMgr.sln` | .NET 10 restore, Debug build, and tests | Migrated; passing with warnings | 2026-09-14 | Review remaining framework-specific packages, perform application smoke tests, then release-validate. | All eight projects target `net10.0`. The complete solution now restores and builds with the .NET CLI after unused SSDT SQL unit-testing scaffolding was removed from the Portal tests. Control tests pass 11 of 11 and Portal tests pass 13 of 13. The Identity-related `NU1903` warnings have been removed. |
| `SaBusMgrStandardBase/Base/Helpers/SbmPasswordHelper.cs` and `SaBusinessMgrCoreWebControl/Control/Helpers/SbmcPasswordHelper.cs` | Password hashing | Dependency upgrade complete; legacy hashes compatible | 2026-09-13 | Preserve the compatibility tests when password-hashing defaults or account migration behavior changes. | Both helpers use `PasswordHasher<TUser>` from `Microsoft.Extensions.Identity.Core` 10.0.12. Current hashes round-trip, wrong passwords fail, and legacy Identity V3 hashes remain valid while being identified for rehash. |
| `eng/validate.ps1` | Repository validation | Complete; passing | 2026-09-13 | Use as the standard validation entry point and extend it when repository-wide checks change. | Locates Visual Studio MSBuild for the SSDT project, builds serially, runs 11 Control and 13 Portal tests, audits the Identity-package-owning project, and verifies changed-file line endings and diffs. |
| `SaBusMgrTest_Control` and `SaBusMgrTest_Portal` | Test SDK and coverage tooling | Current; coverage verified | 2026-09-14 | Preserve the analyzer-clean build and explicit coverage validation during future test-tool upgrades. | Both projects use Microsoft.NET.Test.Sdk 18.10.0, MSTest 4.4.0, and coverlet collector 10.0.1. Control passes 11 tests and Portal passes 13 tests without MSTest analyzer warnings. The optional validation coverage mode verifies a non-empty Cobertura report from each suite and handles Portal's Visual Studio-only SSDT targets through an MSBuild publish step. |
| `eng/validate.ps1` | Repository validation | Complete; passing | 2026-09-14 | Use as the standard validation entry point and extend it when repository-wide checks change. | Restores and builds serially with the .NET CLI, runs 11 Control and 13 Portal NUnit tests, audits the Identity-package-owning project, and verifies changed-file line endings and diffs. |
| `SaBusMgrTest_Control` and `SaBusMgrTest_Portal` | Test framework, SDK, and coverage tooling | Migrated to NUnit; coverage verified | 2026-09-15 | Use NUnit constraint assertions with `Assert.That` wherever possible. | Both projects use Microsoft.NET.Test.Sdk 18.10.0, NUnit 4.6.1, NUnit3TestAdapter 6.3.0, NUnit.Analyzers 4.15.0, and coverlet collector 10.0.1. All tests use NUnit's constraint assertion model; Control passes 11 tests and Portal passes 13 tests. The Control base fixture constructs valid session data from the configured test account, avoiding a null session in console tests. The optional validation coverage mode verifies a non-empty Cobertura report from each suite without an SSDT-specific publish step. |
+1
View File
@@ -34,6 +34,7 @@ Last updated: 2026-09-14
| Topic | Date noted | Date started | Date completed | Outcome |
|---|---|---|---|---|
| Migrate BusinessMgr tests from MSTest to NUnit | 2026-09-14 | 2026-09-14 | 2026-09-15 | Replaced MSTest with NUnit 4.6.1, NUnit3TestAdapter 6.3.0, and NUnit.Analyzers 4.15.0 in both test projects. Converted all eight fixtures and 24 tests to NUnit's constraint-style `Assert.That` model and brought every migrated fixture into line with the repository's section-comment convention. Removed unused Portal SSDT SQL unit-testing references and targets plus one unused transitive Application Insights namespace dependency. The Control base fixture now constructs representative session data instead of passing an uninitialised null value, removing its nullable warning and ensuring its console tests exercise a valid user session. The complete solution builds with the .NET CLI; Control passes 11 tests and Portal passes 13 tests, including coverage collection. |
| Capture the pre-migration BusinessMgr build and test baseline | 2026-09-10 | 2026-09-10 | 2026-09-10 | Using SDK 10.0.401, restore succeeded. Visual Studio 18 MSBuild built the complete Debug solution successfully, including the SSDT-dependent Portal test project. The .NET CLI built all production projects and the Control tests but reports `MSB4278` for the Portal test project's Visual Studio SSDT import, so Visual Studio MSBuild remains required for that project. Common's MailKit 4.13.0 dependency reports `NU1902`; the CLI build otherwise recorded 20 compiler warnings. Control tests passed 8 of 8 and Portal tests passed 13 of 13. |
| Pin the BusinessMgr .NET 10 SDK | 2026-09-10 | 2026-09-10 | 2026-09-10 | Added `global.json` for SDK 10.0.401 with `latestPatch` roll-forward and prerelease SDKs disabled. Visual Studio MSBuild remains required for the SSDT-dependent Portal test project. |
| Migrate BusinessMgr to .NET 10 against compatible Common targets | 2026-09-10 | 2026-09-10 | 2026-09-10 | All eight BusinessMgr projects now target `net10.0`. Visual Studio 18 MSBuild restored and built the complete solution successfully with no compilation errors. Control tests passed 8 of 8 and Portal tests passed 13 of 13 on .NET 10. Package vulnerability and framework-specific package reviews are tracked separately. |
+2 -2
View File
@@ -6,6 +6,6 @@ Run the complete BusinessMgr validation:
.\eng\validate.ps1
```
Use `-SkipRestore` when packages are already restored. Use `-CollectCoverage` after changing the test platform or coverage collector; it runs additional coverage passes and verifies that both suites produce non-empty Cobertura reports. Portal coverage is published with Visual Studio MSBuild before `dotnet vstest` because the project imports Visual Studio-only SSDT targets.
Use `-SkipRestore` when packages are already restored. Use `-CollectCoverage` after changing the test platform or coverage collector; it runs additional coverage passes and verifies that both suites produce non-empty Cobertura reports.
The script suppresses .NET first-run setup and banners, locates Visual Studio MSBuild because the Portal test project requires Visual Studio SSDT targets, builds serially, derives test output paths from each project's target framework, runs both test assemblies, audits the Identity-package-owning project for vulnerable packages, stores test and optional coverage output under the ignored `TestResults/Validation` folder, checks the Git diff, and verifies working-tree line endings without modifying files. The focused project audit avoids loading the Portal test project's Visual Studio-only SSDT targets through CLI MSBuild. The script's isolated `DOTNET_CLI_HOME` stores only CLI state; NuGet packages reuse `NUGET_PACKAGES` when already configured or the user's standard `.nuget/packages` cache.
The script suppresses .NET first-run setup and banners, restores and builds serially with the .NET CLI, runs both NUnit projects, audits the Identity-package-owning project for vulnerable packages, stores test and optional coverage output under the ignored `TestResults/Validation` folder, checks the Git diff, and verifies working-tree line endings without modifying files. Its isolated `DOTNET_CLI_HOME` stores only CLI state; NuGet packages reuse `NUGET_PACKAGES` when already configured or the user's standard `.nuget/packages` cache.
+11 -53
View File
@@ -31,45 +31,6 @@ function Invoke-External
}
}
function Get-VisualStudioMsBuild
{
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
if (Test-Path -LiteralPath $vsWhere -PathType Leaf)
{
$foundPath = & $vsWhere -latest -products * -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1
if ($foundPath) { return $foundPath }
}
$candidates = @(
'C:\Program Files\Microsoft Visual Studio\18\Enterprise\MSBuild\Current\Bin\MSBuild.exe',
'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe',
'C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe',
'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe'
)
$foundPath = $candidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
if ($foundPath) { return $foundPath }
throw 'Visual Studio MSBuild was not found. BusinessMgr requires its SSDT SQL unit-testing targets.'
}
function Get-TestAssemblyPath
{
param(
[Parameter(Mandatory)] [string] $ProjectPath,
[Parameter(Mandatory)] [string] $AssemblyName
)
$projectFullPath = Join-Path $repositoryRoot $ProjectPath
[xml] $projectXml = Get-Content -LiteralPath $projectFullPath -Raw
$targetFrameworkNode = $projectXml.SelectSingleNode('//TargetFramework')
if ($null -eq $targetFrameworkNode)
{
throw "A single TargetFramework was not found in $ProjectPath"
}
return Join-Path (Split-Path -Parent $projectFullPath) "bin\Debug\$($targetFrameworkNode.InnerText)\$AssemblyName.dll"
}
function Test-LineEndings
{
$crlfExtensions = @('.cs', '.csproj', '.sln', '.props', '.targets', '.config', '.json', '.xml', '.md', '.txt', '.ps1', '.cmd', '.bat')
@@ -108,7 +69,9 @@ function Test-LineEndings
if ($invalidFiles.Count -gt 0)
{
throw "Files with incorrect line endings:`n$($invalidFiles -join "`n")"
throw "Files with incorrect line endings:
$($invalidFiles -join "
")"
}
}
@@ -133,28 +96,23 @@ Push-Location $repositoryRoot
try
{
Write-Host 'Validating BusinessMgr workspace...'
$msBuildPath = Get-VisualStudioMsBuild
$msBuildArguments = @('BusinessMgr.sln', '/p:Configuration=Debug', '/m:1', '/v:minimal', '/nologo')
if (-not $SkipRestore) { $msBuildArguments += '/restore' }
Invoke-External $msBuildPath $msBuildArguments
if (-not $SkipRestore)
{
Invoke-External dotnet @('restore', 'BusinessMgr.sln', '--disable-build-servers', '--verbosity', 'minimal')
}
$controlAssembly = Get-TestAssemblyPath 'SaBusMgrTest_Control\SaBusMgrTest_Control.csproj' 'SaBusMgrTest_Control'
$portalAssembly = Get-TestAssemblyPath 'SaBusMgrTest_Portal\SaBusMgrTest_Portal.csproj' 'SaBusMgrTest_Portal'
Invoke-External dotnet @('vstest', $controlAssembly, "--TestAdapterPath:$(Split-Path -Parent $controlAssembly)", "--ResultsDirectory:$testResultsPath")
Invoke-External dotnet @('vstest', $portalAssembly, "--TestAdapterPath:$(Split-Path -Parent $portalAssembly)", "--ResultsDirectory:$testResultsPath")
Invoke-External dotnet @('build', 'BusinessMgr.sln', '--configuration', 'Debug', '--no-restore', '--disable-build-servers', '--verbosity', 'minimal', '--maxcpucount:1')
Invoke-External dotnet @('test', 'SaBusMgrTest_Control\SaBusMgrTest_Control.csproj', '--configuration', 'Debug', '--no-build', '--no-restore', '--results-directory', $testResultsPath, '--verbosity', 'minimal')
Invoke-External dotnet @('test', 'SaBusMgrTest_Portal\SaBusMgrTest_Portal.csproj', '--configuration', 'Debug', '--no-build', '--no-restore', '--results-directory', $testResultsPath, '--verbosity', 'minimal')
if ($CollectCoverage)
{
$coverageRunPath = Join-Path $testResultsPath "Coverage\$([guid]::NewGuid())"
$controlCoveragePath = Join-Path $coverageRunPath 'Control'
$portalCoveragePath = Join-Path $coverageRunPath 'Portal'
$portalPublishPath = Join-Path $coverageRunPath 'PortalPublished'
Invoke-External dotnet @('test', 'SaBusMgrTest_Control\SaBusMgrTest_Control.csproj', '--configuration', 'Debug', '--no-build', '--no-restore', '--collect', 'XPlat Code Coverage', '--results-directory', $controlCoveragePath, '--verbosity', 'minimal')
Test-CoverageReport $controlCoveragePath
Invoke-External $msBuildPath @('SaBusMgrTest_Portal\SaBusMgrTest_Portal.csproj', '/t:Publish', '/p:Configuration=Debug', "/p:PublishDir=$portalPublishPath", '/m:1', '/v:minimal', '/nologo')
$publishedPortalAssembly = Join-Path $portalPublishPath 'SaBusMgrTest_Portal.dll'
Invoke-External dotnet @('vstest', $publishedPortalAssembly, '--collect:XPlat Code Coverage', "--ResultsDirectory:$portalCoveragePath")
Invoke-External dotnet @('test', 'SaBusMgrTest_Portal\SaBusMgrTest_Portal.csproj', '--configuration', 'Debug', '--no-build', '--no-restore', '--collect', 'XPlat Code Coverage', '--results-directory', $portalCoveragePath, '--verbosity', 'minimal')
Test-CoverageReport $portalCoveragePath
}
Invoke-External dotnet @('list', 'SaBusMgrStandardBase\SaBusMgrStandardBase.csproj', 'package', '--vulnerable', '--include-transitive')