Skip to content

Commit

Permalink
Fix #293: SingleEngineeringModel principle implemented (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatstariongroup authored Oct 10, 2023
1 parent da60c18 commit 7ecf6b7
Show file tree
Hide file tree
Showing 101 changed files with 3,027 additions and 1,268 deletions.
3 changes: 2 additions & 1 deletion COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand Down Expand Up @@ -65,6 +65,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Components\Selectors\" />
<Folder Include="WebAssembly\Services\StringTableService\" />
</ItemGroup>

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

namespace COMET.Web.Common.Tests.Components
namespace COMET.Web.Common.Tests.Components.Applications
{
using Bunit;

Expand All @@ -34,6 +34,7 @@ namespace COMET.Web.Common.Tests.Components
using CDP4Dal.Events;

using COMET.Web.Common.Components;
using COMET.Web.Common.Components.Applications;
using COMET.Web.Common.Components.Selectors;
using COMET.Web.Common.Extensions;
using COMET.Web.Common.Model.Configuration;
Expand All @@ -42,6 +43,7 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Services.StringTableService;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.Applications;
using COMET.Web.Common.ViewModels.Components.Selectors;

using DynamicData;
Expand Down Expand Up @@ -73,7 +75,7 @@ public void Setup()
var session = new Mock<ISession>();
session.Setup(x => x.DataSourceUri).Returns("http://localhost:5000");
sessionService.Setup(x => x.Session).Returns(session.Object);
sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny<Iteration>())).Returns(new DomainOfExpertise(){Iid = Guid.NewGuid()});
sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny<Iteration>())).Returns(new DomainOfExpertise { Iid = Guid.NewGuid() });
this.viewModel.Setup(x => x.SessionService).Returns(sessionService.Object);
var mockConfigurationService = new Mock<IConfigurationService>();
mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());
Expand All @@ -91,15 +93,59 @@ public void Teardown()
this.context.CleanContext();
}

[Test]
public void VerifyWithIterationIdParameter()
{
this.openIterations.Add(new Iteration
{
Iid = Guid.NewGuid(),
IterationSetup = new IterationSetup
{
Container = new EngineeringModelSetup
{
Iid = Guid.NewGuid()
}
}
});

var renderer = this.context.RenderComponent<SingleIterationApplicationTemplate>(parameters => { parameters.Add(p => p.IterationId, Guid.NewGuid()); });

Assert.That(renderer.Instance.IterationId, Is.EqualTo(Guid.Empty));

_ = this.context.RenderComponent<SingleIterationApplicationTemplate>(parameters => { parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid); });

this.viewModel.Verify(x => x.OnThingSelect(this.openIterations.Items.First()), Times.Once);

this.viewModel.Setup(x => x.SelectedThing).Returns(new Iteration
{
Iid = Guid.NewGuid(),
IterationSetup = new IterationSetup
{
Container = new EngineeringModelSetup
{
Iid = Guid.NewGuid()
}
}
});

renderer = this.context.RenderComponent<SingleIterationApplicationTemplate>(parameters => { parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid); });

Assert.Multiple(() =>
{
Assert.That(renderer.Instance.IterationId, Is.EqualTo(this.openIterations.Items.First().Iid));
this.viewModel.Verify(x => x.OnThingSelect(this.openIterations.Items.First()), Times.Once);
});
}

[Test]
public void VerifyWithoutIterationIdParameter()
{
this.openIterations.Add(new Iteration()
this.openIterations.Add(new Iteration
{
Iid = Guid.NewGuid(),
IterationSetup = new IterationSetup()
IterationSetup = new IterationSetup
{
Container = new EngineeringModelSetup()
Container = new EngineeringModelSetup
{
Iid = Guid.NewGuid()
}
Expand All @@ -121,12 +167,12 @@ public void VerifyWithoutIterationIdParameter()
Assert.Multiple(() =>
{
Assert.That(navigationManager.Uri, Is.EqualTo("http://localhost/"));
this.viewModel.Verify(x => x.SelectIteration(this.openIterations.Items.First()), Times.Once);
this.viewModel.Verify(x => x.OnThingSelect(this.openIterations.Items.First()), Times.Once);
});

this.viewModel.Setup(x => x.SelectedIteration).Returns(this.openIterations.Items.First());
this.viewModel.Setup(x => x.SelectedThing).Returns(this.openIterations.Items.First());
renderer.Instance.SetCorrectUrl();
var iteration = this.viewModel.Object.SelectedIteration;
var iteration = this.viewModel.Object.SelectedThing;

Assert.Multiple(() =>
{
Expand Down Expand Up @@ -154,13 +200,13 @@ public void VerifyWithoutIterationIdParameter()
});

Assert.That(() => renderer.FindComponent<IterationSelector>(), Throws.Exception);
this.viewModel.Verify(x => x.AskToSelectIteration(), Times.Once);
this.viewModel.Setup(x => x.IsOnIterationSelectionMode).Returns(true);
this.viewModel.Verify(x => x.AskToSelectThing(), Times.Once);
this.viewModel.Setup(x => x.IsOnSelectionMode).Returns(true);
this.viewModel.Setup(x => x.IterationSelectorViewModel).Returns(new IterationSelectorViewModel());
renderer.Render();
Assert.That(() => renderer.FindComponent<IterationSelector>(), Throws.Nothing);
this.openIterations.Clear();
this.viewModel.Setup(x => x.SelectedIteration).Returns((Iteration)null);
this.viewModel.Setup(x => x.SelectedThing).Returns((Iteration)null);
renderer.Instance.SetCorrectUrl();

Assert.Multiple(() =>
Expand All @@ -170,58 +216,5 @@ public void VerifyWithoutIterationIdParameter()
Assert.That(() => CDPMessageBus.Current.SendMessage(new DomainChangedEvent(null, null)), Throws.Nothing);
});
}

[Test]
public void VerifyWithIterationIdParameter()
{
this.openIterations.Add(new Iteration()
{
Iid = Guid.NewGuid(),
IterationSetup = new IterationSetup()
{
Container = new EngineeringModelSetup()
{
Iid = Guid.NewGuid()
}
}
});

var renderer = this.context.RenderComponent<SingleIterationApplicationTemplate>(parameters =>
{
parameters.Add(p => p.IterationId, Guid.NewGuid());
});

Assert.That(renderer.Instance.IterationId, Is.EqualTo(Guid.Empty));

_ = this.context.RenderComponent<SingleIterationApplicationTemplate>(parameters =>
{
parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid);
});

this.viewModel.Verify(x => x.SelectIteration(this.openIterations.Items.First()), Times.Once);

this.viewModel.Setup(x => x.SelectedIteration).Returns(new Iteration()
{
Iid = Guid.NewGuid(),
IterationSetup = new IterationSetup()
{
Container = new EngineeringModelSetup()
{
Iid = Guid.NewGuid()
}
}
});

renderer = this.context.RenderComponent<SingleIterationApplicationTemplate>(parameters =>
{
parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid);
});

Assert.Multiple(() =>
{
Assert.That(renderer.Instance.IterationId, Is.EqualTo(this.openIterations.Items.First().Iid));
this.viewModel.Verify(x => x.SelectIteration(this.openIterations.Items.First()), Times.Once);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="EngineeringModelSelectorTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25
// Annex A and Annex C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Tests.Components.Selectors
{
using Bunit;

using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Components.Selectors;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components.Selectors;

using DevExpress.Blazor;

using Moq;

using NUnit.Framework;

using TestContext = Bunit.TestContext;

[TestFixture]
public class EngineeringModelSelectorTestFixture
{
private TestContext context;
private Mock<IEngineeringModelSelectorViewModel> viewModel;
private List<EngineeringModelSetup> setups;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();

this.setups = new List<EngineeringModelSetup>();
this.viewModel = new Mock<IEngineeringModelSelectorViewModel>();
this.viewModel.Setup(x => x.AvailableEngineeringModelSetups).Returns(this.setups);
this.setups.Add(new EngineeringModelSetup(){Name = "model A"});
this.setups.Add(new EngineeringModelSetup(){Name = "model B"});
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
}

[Test]
public async Task VerifyEngineeringModelSelectorComponent()
{
var renderer = this.context.RenderComponent<EngineeringModelSelector>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewModel.Object);
});

Assert.That(renderer.Instance.ViewModel, Is.EqualTo(this.viewModel.Object));

var listBox = renderer.FindComponent<DxListBox<EngineeringModelSetup, EngineeringModelSetup>>();
var submitButton = renderer.FindComponent<DxButton>();

Assert.Multiple(() =>
{
Assert.That(listBox.Instance.Data.Count(), Is.EqualTo(2));
Assert.That(submitButton.Instance.Enabled, Is.False);
});

this.viewModel.Setup(x => x.SelectedEngineeringModelSetup).Returns(this.setups[^1]);
renderer.Render();

Assert.That(submitButton.Instance.Enabled, Is.True);

await renderer.InvokeAsync(submitButton.Instance.Click.InvokeAsync);
this.viewModel.Verify(x => x.Submit(), Times.Once);
}
}
}
Loading

0 comments on commit 7ecf6b7

Please sign in to comment.