Skip to content

Commit

Permalink
site directory renamed to server administration + user managment refa…
Browse files Browse the repository at this point in the history
…ctored and moved to server administration page
  • Loading branch information
joao4all committed Apr 17, 2024
1 parent 702f5c3 commit 1847095
Show file tree
Hide file tree
Showing 19 changed files with 426 additions and 849 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace COMETwebapp.Tests.Components.ReferenceData

using COMETwebapp.Components.ReferenceData;
using COMETwebapp.Services.ShowHideDeprecatedThingsService;
using COMETwebapp.ViewModels.Components.ReferenceData;
using COMETwebapp.ViewModels.Components.ReferenceData.MeasurementScales;
using COMETwebapp.ViewModels.Components.ReferenceData.Rows;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

#pragma warning disable BL0005
namespace COMETwebapp.Tests.Components.UserManagement
namespace COMETwebapp.Tests.Components.SiteDirectory
{
using System.Collections.Concurrent;

Expand All @@ -32,6 +31,7 @@ namespace COMETwebapp.Tests.Components.UserManagement
using CDP4Common.CommonData;
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;
using CDP4Common.Types;

using CDP4Dal;
using CDP4Dal.DAL;
Expand All @@ -44,13 +44,14 @@ namespace COMETwebapp.Tests.Components.UserManagement
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Test.Helpers;

using COMETwebapp.Components.UserManagement;
using COMETwebapp.Components.SiteDirectory;
using COMETwebapp.Services.ShowHideDeprecatedThingsService;
using COMETwebapp.ViewModels.Components.UserManagement;
using COMETwebapp.ViewModels.Components.SiteDirectory.UserManagement;

using DevExpress.Blazor;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using Moq;

Expand All @@ -62,8 +63,9 @@ namespace COMETwebapp.Tests.Components.UserManagement
public class UserManagementTableTestFixture
{
private TestContext context;
private IUserManagementTableViewModel viewModel;
private UserManagementTableViewModel viewModel;
private Mock<ISession> session;
private Mock<ILogger<UserManagementTableViewModel>> logger;
private Mock<IPermissionService> permissionService;
private Mock<ISessionService> sessionService;
private Mock<IShowHideDeprecatedThingsService> showHideDeprecatedThingsService;
Expand All @@ -88,30 +90,23 @@ public void SetUp()

this.session = new Mock<ISession>();
this.sessionService = new Mock<ISessionService>();
this.logger = new Mock<ILogger<UserManagementTableViewModel>>();
this.showHideDeprecatedThingsService = new Mock<IShowHideDeprecatedThingsService>();
this.sessionService.Setup(x => x.Session).Returns(this.session.Object);

this.sessionService.Setup(x => x.Session).Returns(this.session.Object);
this.permissionService = new Mock<IPermissionService>();
this.permissionService.Setup(x => x.CanWrite(It.IsAny<Thing>())).Returns(true);
this.permissionService.Setup(x => x.CanWrite(It.IsAny<ClassKind>(), It.IsAny<Thing>())).Returns(true);

this.showHideDeprecatedThingsService.Setup(x => x.ShowDeprecatedThings).Returns(true);

this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
this.showHideDeprecatedThingsService.Setup(x => x.ShowDeprecatedThings).Returns(true);

this.context.Services.AddSingleton(this.sessionService);
this.context.ConfigureDevExpressBlazor();
var configuration = new Mock<IConfigurationService>();
configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());
this.context.Services.AddSingleton(configuration.Object);
this.messageBus = new CDPMessageBus();

this.assembler = new Assembler(this.uri, this.messageBus);
this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri);

this.viewModel = new UserManagementTableViewModel(this.sessionService.Object, this.showHideDeprecatedThingsService.Object, this.messageBus);

this.context.Services.AddSingleton(this.viewModel);
this.viewModel = new UserManagementTableViewModel(this.sessionService.Object, this.showHideDeprecatedThingsService.Object, this.messageBus, this.logger.Object);

this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Expand Down Expand Up @@ -239,6 +234,9 @@ public void SetUp()
Model = { this.engineeringSetup }
};

this.assembler.Cache.TryAdd(new CacheKey(Guid.NewGuid(), null), new Lazy<Thing>(this.person));
this.assembler.Cache.TryAdd(new CacheKey(Guid.NewGuid(), null), new Lazy<Thing>(this.person1));

this.siteDirectory.Person.Add(this.person);
this.siteDirectory.Person.Add(this.person1);
this.siteDirectory.Domain.Add(this.domain);
Expand All @@ -249,13 +247,19 @@ public void SetUp()
this.session.Setup(x => x.Credentials).Returns(new Credentials("admin", "pass", this.uri));
this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDirectory);
this.session.Setup(x => x.ActivePerson).Returns(this.person);

this.context.Services.AddSingleton<IUserManagementTableViewModel>(this.viewModel);
this.context.Services.AddSingleton(this.sessionService);
this.context.Services.AddSingleton(configuration.Object);
this.context.ConfigureDevExpressBlazor();
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
this.messageBus.ClearSubscriptions();
this.viewModel.Dispose();
}

[Test]
Expand All @@ -279,19 +283,19 @@ public async Task VerifyComponent()

Assert.Multiple(() =>
{
Assert.That(this.viewModel.Person.Name?.Trim(), Is.Empty);
Assert.That(this.viewModel.ShouldCreatePerson, Is.EqualTo(true));
Assert.That(this.viewModel.Thing.Name?.Trim(), Is.Empty);
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(true));
});

await renderer.InvokeAsync(grid.Instance.EditModelSaving.InvokeAsync);
this.sessionService.Verify(x => x.UpdateThings(It.IsAny<SiteDirectory>(), It.Is<List<Thing>>(c => c.Contains(this.viewModel.Person))), Times.Once);
this.sessionService.Verify(x => x.UpdateThings(It.IsAny<SiteDirectory>(), It.Is<List<Thing>>(c => c.Contains(this.viewModel.Thing))), Times.Once);

await grid.InvokeAsync(editPersonButton.Instance.Click.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(this.viewModel.Person.Name, Is.EqualTo(this.viewModel.Rows.Items.First().PersonName));
Assert.That(this.viewModel.ShouldCreatePerson, Is.EqualTo(false));
Assert.That(this.viewModel.Thing.Name, Is.EqualTo(this.viewModel.Rows.Items.First().Name));
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
});

await renderer.InvokeAsync(grid.Instance.EditModelSaving.InvokeAsync);
Expand All @@ -315,14 +319,12 @@ public async Task VerifyActivatingPerson()

Assert.Multiple(() =>
{
Assert.That(checkBox.Instance.Checked, Is.True);
Assert.That(renderer.Markup, Does.Contain(this.person.Name));
Assert.That(renderer.Markup, Does.Contain(this.person1.Name));
});

await renderer.InvokeAsync(() => checkBox.Instance.Checked = false);

Assert.Multiple(() => { Assert.That(checkBox.Instance.Checked, Is.False); });
await renderer.InvokeAsync(() => checkBox.Instance.CheckedChanged.InvokeAsync(false));
this.sessionService.Verify(x => x.UpdateThings(It.IsAny<SiteDirectory>(), It.IsAny<Person>()), Times.Once);
}

[Test]
Expand All @@ -341,7 +343,7 @@ public async Task VerifyAddingOrEditingPerson()
Assert.That(renderer.Markup, Does.Contain(this.person1.Name));
});

this.viewModel.Person = new Person
this.viewModel.Thing = new Person
{
GivenName = "Test",
Surname = "Test",
Expand All @@ -352,8 +354,8 @@ public async Task VerifyAddingOrEditingPerson()
TelephoneNumber = { new TelephoneNumber() }
};

await this.viewModel.CreateOrEditPerson();
this.messageBus.SendMessage(new ObjectChangedEvent(this.viewModel.Person, EventKind.Added));
await this.viewModel.CreateOrEditPerson(true);
this.messageBus.SendMessage(new ObjectChangedEvent(this.viewModel.Thing, EventKind.Added));

Assert.Multiple(() =>
{
Expand All @@ -364,7 +366,7 @@ public async Task VerifyAddingOrEditingPerson()

[Test]
public async Task VerifyDeprecatingPerson()
{
{
var renderer = this.context.RenderComponent<UserManagementTable>();

Assert.Multiple(() =>
Expand All @@ -375,7 +377,7 @@ public async Task VerifyDeprecatingPerson()
});

var deprecateButton = renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "deprecateButton");
var currentPerson = this.viewModel.Person;
var currentPerson = this.viewModel.Thing;

Assert.That(this.viewModel.IsOnDeprecationMode, Is.False);

Expand All @@ -384,12 +386,12 @@ public async Task VerifyDeprecatingPerson()
Assert.Multiple(() =>
{
Assert.That(this.viewModel.IsOnDeprecationMode, Is.True);
Assert.That(this.viewModel.Person, Is.Not.EqualTo(currentPerson));
Assert.That(this.viewModel.Thing, Is.Not.EqualTo(currentPerson));
});

this.viewModel.Person = this.person;
this.viewModel.Thing = this.person;

await this.viewModel.OnConfirmButtonClick();
await this.viewModel.OnConfirmPopupButtonClick();

Assert.That(this.viewModel.IsOnDeprecationMode, Is.False);
}
Expand Down Expand Up @@ -420,7 +422,7 @@ public async Task VerifyUnDeprecatingPerson()
});

var undeprecateButton = renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "undeprecateButton");
var currentPerson = this.viewModel.Person;
var currentPerson = this.viewModel.Thing;

Assert.That(this.viewModel.IsOnDeprecationMode, Is.False);

Expand All @@ -429,12 +431,12 @@ public async Task VerifyUnDeprecatingPerson()
Assert.Multiple(() =>
{
Assert.That(this.viewModel.IsOnDeprecationMode, Is.True);
Assert.That(this.viewModel.Person, Is.Not.EqualTo(currentPerson));
Assert.That(this.viewModel.Thing, Is.Not.EqualTo(currentPerson));
});

this.viewModel.Person = this.person1;
this.viewModel.Thing = this.person1;

await this.viewModel.OnConfirmButtonClick();
await this.viewModel.OnConfirmPopupButtonClick();

Assert.That(this.viewModel.IsOnDeprecationMode, Is.False);
}
Expand All @@ -449,16 +451,17 @@ public void VerifyRecordChange()

var personTest = new Person()
{
Iid = Guid.NewGuid()
Iid = Guid.NewGuid(),
Container = this.siteDirectory
};

this.messageBus.SendObjectChangeEvent(personTest, EventKind.Added);
this.messageBus.SendMessage(SessionStateKind.RefreshEnded);

this.messageBus.SendObjectChangeEvent(this.viewModel.Rows.Items.First().Person, EventKind.Removed);
this.messageBus.SendObjectChangeEvent(this.viewModel.Rows.Items.First().Thing, EventKind.Removed);
this.messageBus.SendMessage(SessionStateKind.RefreshEnded);

this.messageBus.SendObjectChangeEvent(this.viewModel.Rows.Items.First().Person, EventKind.Updated);
this.messageBus.SendObjectChangeEvent(this.viewModel.Rows.Items.First().Thing, EventKind.Updated);
this.messageBus.SendMessage(SessionStateKind.RefreshEnded);

Assert.That(this.viewModel.Rows, Has.Count.EqualTo(2));
Expand Down
2 changes: 1 addition & 1 deletion COMETwebapp.Tests/Model/ApplicationsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void VerifyApplications()
{
var applications = Applications.ExistingApplications;

Assert.That(applications, Has.Count.EqualTo(13));
Assert.That(applications, Has.Count.EqualTo(12));

foreach (var application in applications)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace COMETwebapp.Components.SiteDirectory
using CDP4Common.SiteDirectoryData;

using COMETwebapp.Components.Common;
using COMETwebapp.ViewModels.Components.SiteDirectory.DomainsOfExpertise;
using COMETwebapp.ViewModels.Components.SiteDirectory.Organizations;
using COMETwebapp.ViewModels.Components.SiteDirectory.Rows;

Expand All @@ -41,7 +40,7 @@ namespace COMETwebapp.Components.SiteDirectory
public partial class OrganizationsTable : SelectedDeprecatableDataItemBase<Organization, OrganizationRowViewModel>
{
/// <summary>
/// The <see cref="IDomainsOfExpertiseTableViewModel" /> for this component
/// The <see cref="IOrganizationsTableViewModel" /> for this component
/// </summary>
[Inject]
public IOrganizationsTableViewModel ViewModel { get; set; }
Expand Down
Loading

0 comments on commit 1847095

Please sign in to comment.