Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CometServer.Tests/SideEffects/OptionSideEffectTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,31 @@ public void Verify_that_DefaultOption_is_not_set_and_not_saved_when_DefaultOptio
this.engineeringModel), Times.Never);
}

[Test]
public void Verify_that_when_container_engineeringmodeletup_is_not_found_an_exception_is_thrown()
{
this.engineeringModelSetup.Kind = CDP4Common.SiteDirectoryData.EngineeringModelKind.STUDY_MODEL;
this.options.Add(this.option1);
this.options.Add(this.option2);

this.SetupMethodCallsForDeleteOptionTest();

this.engineeringModelSetupService
.Setup(x => x.GetShallow(this.npgsqlTransaction, CDP4Orm.Dao.Utils.SiteDirectoryPartition,
null, this.securityContext.Object))
.Returns(Array.Empty<EngineeringModelSetup>());

Assert.That(() =>
{
this.optionSideEffect.BeforeCreate(
this.option1,
this.iteration,
this.npgsqlTransaction,
this.iterationPartition,
this.securityContext.Object);
}, Throws.TypeOf<InvalidOperationException>());
}

/// <summary>
/// Sets up fake method calls on mocked classes specifically for the unit tests that check
/// <see cref="Iteration.DefaultOption" /> handling when an <see cref="Option" /> is deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace CometServer.Services.Operations.SideEffects

using CDP4Orm.Dao;

using CometServer.Exceptions;
using CometServer.Services.Authorization;

using Npgsql;
Expand Down Expand Up @@ -320,6 +321,11 @@ public override bool BeforeCreate(Option thing, Thing container, NpgsqlTransacti
.Cast<EngineeringModelSetup>()
.SingleOrDefault(ms => ms.IterationSetup.Contains(iterationSetup.Iid));

if (engineeringModelSetup == null)
{
throw new InvalidOperationException($"The corresponding EngineeringModelSetup of Option {thing.Iid} could not be found. It is impossible to verify whether the new Option can be created");
}

if (engineeringModelSetup.Kind == CDP4Common.SiteDirectoryData.EngineeringModelKind.MODEL_CATALOGUE)
{
throw new InvalidOperationException("The container EngineeringModel is a Catalogue, a Catalogue may not contain more than one Option");
Expand Down

0 comments on commit 8157018

Please sign in to comment.