diff --git a/src/PKSim.Presentation/Services/WorkspaceLayoutUpdater.cs b/src/PKSim.Presentation/Services/WorkspaceLayoutUpdater.cs index 2fcdbc58f..f5d406290 100644 --- a/src/PKSim.Presentation/Services/WorkspaceLayoutUpdater.cs +++ b/src/PKSim.Presentation/Services/WorkspaceLayoutUpdater.cs @@ -67,7 +67,7 @@ private WorkspaceLayout createNewWorkspaceLayoutWithOpenPresenters() var workspaceLayout = new WorkspaceLayout(); foreach (var presenter in _applicationController.OpenedPresenters()) { - var withId = presenter.Subject.DowncastTo(); + var withId = presenter.Subject as IWithId; if (withId == null) continue; var workspaceLayoutItem = new WorkspaceLayoutItem {WasOpenOnSave = true, SubjectId = withId.Id, PresentationSettings = presenter.GetSettings()}; workspaceLayout.AddLayoutItem(workspaceLayoutItem); diff --git a/tests/PKSim.Tests/Presentation/WorkspaceLayoutCreatorSpecs.cs b/tests/PKSim.Tests/Presentation/WorkspaceLayoutCreatorSpecs.cs index 3f357cacc..804fe1b24 100644 --- a/tests/PKSim.Tests/Presentation/WorkspaceLayoutCreatorSpecs.cs +++ b/tests/PKSim.Tests/Presentation/WorkspaceLayoutCreatorSpecs.cs @@ -4,8 +4,10 @@ using OSPSuite.BDDHelper; using OSPSuite.BDDHelper.Extensions; using OSPSuite.Core.Domain; +using OSPSuite.Core.Domain.ParameterIdentifications; using OSPSuite.Presentation.Core; using OSPSuite.Presentation.Presenters; +using OSPSuite.Presentation.Presenters.ParameterIdentifications; using OSPSuite.Presentation.Services; using OSPSuite.Utility.Events; using OSPSuite.Utility.Extensions; @@ -88,4 +90,41 @@ public void should_mark_the_existing_layout_item_as_not_open() _workspace.WorkspaceLayout.LayoutItems.First(x => _existingWorkspaceLayout.LayoutItems.Contains(x)).WasOpenOnSave.ShouldBeFalse(); } } + + public class When_updating_workspace_layout_with_nonpersistent_subject_presenters : concern_for_WorkspaceLayoutCreator + { + private ISingleStartPresenter _presenter1; + private ISingleStartPresenter _presenter2; + private Individual _individual; + private ParameterIdentificationFeedback _feedback; + private IWorkspaceLayout _existingWorkspaceLayout; + + protected override void Context() + { + base.Context(); + _individual = new Individual().WithId("individual"); + _feedback = new ParameterIdentificationFeedback(new ParameterIdentification()); + + _presenter1 = A.Fake(); + A.CallTo(() => _presenter1.Subject).Returns(_individual); + _presenter2 = A.Fake(); + A.CallTo(() => _presenter2.Subject).Returns(_feedback); + A.CallTo(() => _applicationController.OpenedPresenters()).Returns(new[] { _presenter1, _presenter2 }); + + _existingWorkspaceLayout = A.Fake(); + _workspace.WorkspaceLayout = _existingWorkspaceLayout; + A.CallTo(() => _existingWorkspaceLayout.LayoutItems).Returns(new List { new WorkspaceLayoutItem() }); + } + + protected override void Because() + { + sut.SaveCurrentLayout(); + } + + [Observation] + public void should_ignore_non_persistent_subject_presenters() + { + _workspace.WorkspaceLayout.LayoutItems.Count().ShouldBeEqualTo(2); + } + } } \ No newline at end of file