Skip to content

Commit 8a0b19c

Browse files
committed
Fixes #2436 Prepend the Events container to event-group parameter value paths
Selecting a parameter from an event group building block via "New parameter value" produced a path rooted at the top EventGroupBuilder, missing the leading "Events" model container. The resulting parameter value did not resolve. Prepend Constants.EVENTS when the selected entity is rooted in an EventGroupBuilder.
1 parent 9fe080b commit 8a0b19c

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/MoBi.Presentation/Presenter/SelectReferenceAtParameterValuePresenter.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,22 @@ private ObjectPath getObjectPath(IEntity item, DummyParameterDTO matchingDto)
130130
return returnPath;
131131
}
132132

133-
return CreatePathFor(item);
133+
var itemPath = CreatePathFor(item);
134+
prependEventsContainerIfMissing(item, itemPath);
135+
return itemPath;
136+
}
137+
138+
private static void prependEventsContainerIfMissing(IEntity item, ObjectPath objectPath)
139+
{
140+
// Entities selected from an event group building block are rooted at their top
141+
// EventGroupBuilder, but in the built model these live under the "Events" top container.
142+
if (isAbsolutePathRootedAtEventGroup(item, objectPath))
143+
objectPath.AddAtFront(Constants.EVENTS);
144+
}
145+
146+
private static bool isAbsolutePathRootedAtEventGroup(IEntity item, ObjectPath objectPath)
147+
{
148+
return item.RootContainer is EventGroupBuilder eventGroupRoot && string.Equals(objectPath.FirstOrDefault(), eventGroupRoot.Name);
134149
}
135150

136151
private bool shouldUseParameterPath(IEntity item, DummyParameterDTO matchingDto)

tests/MoBi.Tests/Presentation/SelectReferenceAtParameterValuePresenterSpecs.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,43 @@ public void the_selected_local_parameters_should_have_correct_path()
248248
}
249249
}
250250

251+
internal class When_selecting_an_event_group_parameter : concern_for_SelectReferenceAtParameterValuePresenter
252+
{
253+
private ObjectBaseDTO _doseDTO;
254+
private Parameter _dose;
255+
private IReadOnlyList<ObjectPath> _selectedSections;
256+
257+
protected override void Context()
258+
{
259+
base.Context();
260+
var eventGroup = new EventGroupBuilder().WithName("200mg iv");
261+
var application = new EventGroupBuilder().WithName("Application_1");
262+
var protocolSchemaItem = new Container().WithName("ProtocolSchemaItem");
263+
_dose = new Parameter().WithName("Dose").WithId("doseId");
264+
protocolSchemaItem.Add(_dose);
265+
application.Add(protocolSchemaItem);
266+
eventGroup.Add(application);
267+
268+
_doseDTO = new ObjectBaseDTO(_dose);
269+
270+
A.CallTo(() => _context.Get<IEntity>(_dose.Id)).Returns(_dose);
271+
A.CallTo(() => _view.AllSelectedDTOs).Returns(new[] { _doseDTO });
272+
A.CallTo(() => _objectPathFactory.CreateAbsoluteObjectPath(_dose))
273+
.Returns(new ObjectPath("200mg iv", "Application_1", "ProtocolSchemaItem", "Dose"));
274+
}
275+
276+
protected override void Because()
277+
{
278+
_selectedSections = sut.GetAllSelections();
279+
}
280+
281+
[Observation]
282+
public void the_path_should_be_prefixed_with_the_events_top_container()
283+
{
284+
_selectedSections.Single().PathAsString.ShouldBeEqualTo($"{Constants.EVENTS}|200mg iv|Application_1|ProtocolSchemaItem|Dose");
285+
}
286+
}
287+
251288
internal class When_selecting_multiple_references_and_not_all_are_parameters : concern_for_SelectReferenceAtParameterValuePresenter
252289
{
253290
private ObjectBaseDTO _parameterDTO2;

0 commit comments

Comments
 (0)