Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #556 As a user i want to create a new EngineeringModel #568

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,21 @@ public async Task VerifyDeleteEngineeringModel()
}

[Test]
public async Task VerifyAddingOrEditingEngineeringModel()
public async Task VerifyAddEngineeringModel()
{
var addEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addEngineeringModelButton");
await this.renderer.InvokeAsync(addEngineeringModelButton.Instance.Click.InvokeAsync);
var grid = this.renderer.FindComponent<DxGrid>();
Assert.That(grid.Instance.IsEditing(), Is.EqualTo(true));

Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(true));
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(EngineeringModelSetup)));
});

var editEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "editEngineeringModelButton");
await this.renderer.InvokeAsync(editEngineeringModelButton.Instance.Click.InvokeAsync);
var cancelEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "cancelEngineeringModelButton");
await this.renderer.InvokeAsync(cancelEngineeringModelButton.Instance.Click.InvokeAsync);
Assert.That(grid.Instance.IsEditing(), Is.EqualTo(false));

Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(EngineeringModelSetup)));
});

var form = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(form.Instance.EditModelSaving.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditEngineeringModel(false), Times.Once);
await this.renderer.InvokeAsync(addEngineeringModelButton.Instance.Click.InvokeAsync);
var saveEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "saveEngineeringModelButton");
await this.renderer.InvokeAsync(saveEngineeringModelButton.Instance.Click.InvokeAsync);
this.viewModel.Verify(x => x.CreateEngineeringModel(), Times.Once);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="EngineeringModelValidatorTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023-2024 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The CDP4-COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Tests.Validators.EngineeringModel
{
using CDP4Common.SiteDirectoryData;
using CDP4Common.Validation;

using COMETwebapp.Validators.EngineeringModel;

using NUnit.Framework;

[TestFixture]
public class EngineeringModelValidatorTestFixture
{
private EngineeringModelValidator validator;

[SetUp]
public void SetUp()
{
var validationService = new ValidationService();
this.validator = new EngineeringModelValidator(validationService);
}

[Test]
public void VerifyValidationScenarios()
{
var model = new EngineeringModelSetup();
Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(false));

model = new EngineeringModelSetup()
{
Name = "name",
ShortName = "short"
};

Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(false));

model.SourceEngineeringModelSetupIid = Guid.NewGuid();
Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(true));

// Verifies the inputs for when the site rdl is set
model.SourceEngineeringModelSetupIid = null;
model.RequiredRdl.Add(new ModelReferenceDataLibrary());
Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(false));

model.ActiveDomain = [new DomainOfExpertise()];
Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(true));

// Verifies the organization input validation
model.OrganizationalParticipant.Add(new OrganizationalParticipant());
Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(false));

model.DefaultOrganizationalParticipant = model.OrganizationalParticipant.First();
Assert.That(this.validator.Validate(model).IsValid, Is.EqualTo(true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class EngineeringModelsTableViewModelTestFixture
private Mock<ILogger<EngineeringModelsTableViewModel>> loggerMock;
private CDPMessageBus messageBus;
private EngineeringModelSetup engineeringModel;
private SiteDirectory siteDirectory;

[SetUp]
public void Setup()
Expand All @@ -68,12 +69,15 @@ public void Setup()
Name = "model 1",
};

var siteDirectory = new SiteDirectory()
this.siteDirectory = new SiteDirectory()
{
ShortName = "siteDirectory"
ShortName = "siteDirectory",
SiteReferenceDataLibrary = { new SiteReferenceDataLibrary() },
Domain = { new DomainOfExpertise() },
Organization = { new Organization() }
};

siteDirectory.Model.Add(this.engineeringModel);
this.siteDirectory.Model.Add(this.engineeringModel);

this.assembler = new Assembler(new Uri("http://localhost:5000/"), this.messageBus);
var lazyModel = new Lazy<Thing>(this.engineeringModel);
Expand All @@ -83,9 +87,9 @@ public void Setup()
var session = new Mock<ISession>();
session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
session.Setup(x => x.Assembler).Returns(this.assembler);
session.Setup(x => x.RetrieveSiteDirectory()).Returns(siteDirectory);
session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDirectory);
this.sessionService.Setup(x => x.Session).Returns(session.Object);
this.sessionService.Setup(x => x.GetSiteDirectory()).Returns(siteDirectory);
this.sessionService.Setup(x => x.GetSiteDirectory()).Returns(this.siteDirectory);

this.viewModel = new EngineeringModelsTableViewModel(this.sessionService.Object, this.messageBus, this.loggerMock.Object);
}
Expand All @@ -106,6 +110,12 @@ public void VerifyInitializeViewModel()
{
Assert.That(this.viewModel.Rows.Count, Is.EqualTo(1));
Assert.That(this.viewModel.Rows.Items.First().Thing, Is.EqualTo(this.engineeringModel));
Assert.That(this.viewModel.DomainsOfExpertise, Is.EqualTo(this.siteDirectory.Domain));
Assert.That(this.viewModel.EngineeringModels, Is.EqualTo(this.siteDirectory.Model));
Assert.That(this.viewModel.Organizations, Is.EqualTo(this.siteDirectory.Organization));
Assert.That(this.viewModel.SiteRdls, Is.EqualTo(this.siteDirectory.SiteReferenceDataLibrary));
Assert.That(this.viewModel.ModelKinds, Is.Not.Empty);
Assert.That(this.viewModel.StudyPhases, Is.Not.Empty);
});
}

Expand Down Expand Up @@ -133,15 +143,10 @@ public void VerifySessionRefresh()
this.messageBus.SendMessage(SessionStateKind.RefreshEnded);
Assert.That(this.viewModel.Rows, Has.Count.EqualTo(1));

var siteDirectory = new SiteDirectory()
{
ShortName = "newShortname"
};

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

this.messageBus.SendObjectChangeEvent(engineeringModelTest, EventKind.Added);
Expand All @@ -155,13 +160,13 @@ public void VerifySessionRefresh()

Assert.That(this.viewModel.Rows, Has.Count.EqualTo(1));

this.messageBus.SendObjectChangeEvent(siteDirectory, EventKind.Updated);
this.messageBus.SendObjectChangeEvent(this.siteDirectory, EventKind.Updated);
this.messageBus.SendObjectChangeEvent(new PersonRole(), EventKind.Updated);
this.messageBus.SendMessage(SessionStateKind.RefreshEnded);

Assert.Multiple(() =>
{
Assert.That(this.viewModel.Rows.Items.First().ContainerName, Is.EqualTo(siteDirectory.ShortName));
Assert.That(this.viewModel.Rows.Items.First().ContainerName, Is.EqualTo(this.siteDirectory.ShortName));
this.permissionService.Verify(x => x.CanWrite(engineeringModelTest.ClassKind, It.IsAny<Thing>()), Times.AtLeast(this.viewModel.Rows.Count));
});
}
Expand Down Expand Up @@ -199,15 +204,33 @@ public async Task VerifyRowOperations()
}

[Test]
public async Task VerifyModelCreateOrEdit()
public async Task VerifyModelCreation()
{
this.viewModel.InitializeViewModel();

await this.viewModel.CreateOrEditEngineeringModel(false);
this.sessionService.Verify(x => x.UpdateThings(It.IsAny<SiteDirectory>(), It.Is<List<Thing>>(c => c.Count == 1)), Times.Once);
var testOrganization = this.siteDirectory.Organization.First();
this.viewModel.SelectedOrganizations = [testOrganization];
this.viewModel.SelectedModelAdminOrganization = testOrganization;

this.viewModel.SelectedActiveDomains = [this.siteDirectory.Domain.First()];
this.viewModel.SelectedSiteRdl = this.siteDirectory.SiteReferenceDataLibrary.First();
this.viewModel.SelectedSourceModel = this.siteDirectory.Model.First();

this.viewModel.SetupEngineeringModelWithSelectedValues();
await this.viewModel.CreateEngineeringModel();

await this.viewModel.CreateOrEditEngineeringModel(true);
this.sessionService.Verify(x => x.UpdateThings(It.IsAny<SiteDirectory>(), It.Is<List<Thing>>(c => c.Count == 2)), Times.Once);
this.sessionService.Verify(x => x.UpdateThings(It.IsAny<SiteDirectory>(), It.Is<List<Thing>>(c => c.Count == 4)), Times.Once);

this.viewModel.ResetSelectedValues();

Assert.Multiple(() =>
{
Assert.That(this.viewModel.SelectedActiveDomains, Has.Count.EqualTo(0));
Assert.That(this.viewModel.SelectedOrganizations, Has.Count.EqualTo(0));
Assert.That(this.viewModel.SelectedModelAdminOrganization, Is.Null);
Assert.That(this.viewModel.SelectedSiteRdl, Is.Null);
Assert.That(this.viewModel.SelectedSourceModel, Is.Null);
});
}
}
}
Loading
Loading