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

return null if subject not implementing IWithId #2094

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
2 changes: 1 addition & 1 deletion src/PKSim.Presentation/Services/WorkspaceLayoutUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private WorkspaceLayout createNewWorkspaceLayoutWithOpenPresenters()
var workspaceLayout = new WorkspaceLayout();
foreach (var presenter in _applicationController.OpenedPresenters())
{
var withId = presenter.Subject.DowncastTo<IWithId>();
var withId = presenter.Subject as IWithId;
if (withId == null) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this

var workspaceLayoutItem = new WorkspaceLayoutItem {WasOpenOnSave = true, SubjectId = withId.Id, PresentationSettings = presenter.GetSettings()};
workspaceLayout.AddLayoutItem(workspaceLayoutItem);
Expand Down
39 changes: 39 additions & 0 deletions tests/PKSim.Tests/Presentation/WorkspaceLayoutCreatorSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ISingleStartPresenter>();
A.CallTo(() => _presenter1.Subject).Returns(_individual);
_presenter2 = A.Fake<ISingleStartPresenter>();
A.CallTo(() => _presenter2.Subject).Returns(_feedback);
A.CallTo(() => _applicationController.OpenedPresenters()).Returns(new[] { _presenter1, _presenter2 });

_existingWorkspaceLayout = A.Fake<IWorkspaceLayout>();
_workspace.WorkspaceLayout = _existingWorkspaceLayout;
A.CallTo(() => _existingWorkspaceLayout.LayoutItems).Returns(new List<WorkspaceLayoutItem> { new WorkspaceLayoutItem() });
}

protected override void Because()
{
sut.SaveCurrentLayout();
}

[Observation]
public void should_ignore_non_persistent_subject_presenters()
{
_workspace.WorkspaceLayout.LayoutItems.Count().ShouldBeEqualTo(2);
}
}
}