Skip to content

Commit

Permalink
Fixes #769 parameter should be global for interaction container
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre committed Oct 6, 2022
1 parent 3e61941 commit 1a77639
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
5 changes: 3 additions & 2 deletions src/MoBi.Core/Domain/Extensions/ContainerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Utility.Extensions;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Utility.Extensions;

namespace MoBi.Core.Domain.Extensions
{
Expand All @@ -27,7 +27,8 @@ public static IEnumerable<ParameterBuildMode> AvailableBuildModeForParameters(th
public static ParameterBuildMode DefaultParameterBuildMode(this IContainer container)
{
var needsGlobalParameter = container.IsAnImplementationOf<TransporterMoleculeContainer>() ||
container.IsAnImplementationOf<IReactionBuilder>();
container.IsAnImplementationOf<IReactionBuilder>() ||
container.IsAnImplementationOf<InteractionContainer>();

return needsGlobalParameter ? ParameterBuildMode.Global : ParameterBuildMode.Local;
}
Expand Down
44 changes: 22 additions & 22 deletions src/MoBi.Presentation/Mappers/MoleculeBuilderDTOToTreeNodeMapper.cs
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
using System.Linq;
using OSPSuite.Utility;
using OSPSuite.Utility.Extensions;
using MoBi.Presentation.DTO;
using MoBi.Presentation.Nodes;
using OSPSuite.Assets;
using OSPSuite.Utility;
using OSPSuite.Utility.Extensions;

namespace MoBi.Presentation.Mappers
{
public interface IMoleculeBuilderDTOToTreeNodeMapper : IMapper<MoleculeBuilderDTO, IMoleculeTreeNode>
{
}


internal class MoleculeBuilderDTOToTreeNodeMapper : IMoleculeBuilderDTOToTreeNodeMapper
{
private readonly ITransporterMoleculeContainerDTOToMoleculeTreeNodeMapper _activeTransportBuilderContaienrToMolceculeTreeNodeMapper;
private readonly ITransporterMoleculeContainerDTOToMoleculeTreeNodeMapper _activeTransportBuilderContainerToMoleculeTreeNodeMapper;
private readonly IInteractionContainerDTOToMoleculeTreeMapper _interactionContainerMapper;

public MoleculeBuilderDTOToTreeNodeMapper(ITransporterMoleculeContainerDTOToMoleculeTreeNodeMapper activeTransportBuilderContaienrToMolceculeTreeNodeMapper, IInteractionContainerDTOToMoleculeTreeMapper interactionContainerMapper)
public MoleculeBuilderDTOToTreeNodeMapper(ITransporterMoleculeContainerDTOToMoleculeTreeNodeMapper activeTransportBuilderContainerToMoleculeTreeNodeMapper, IInteractionContainerDTOToMoleculeTreeMapper interactionContainerMapper)
{
_activeTransportBuilderContaienrToMolceculeTreeNodeMapper = activeTransportBuilderContaienrToMolceculeTreeNodeMapper;
_activeTransportBuilderContainerToMoleculeTreeNodeMapper = activeTransportBuilderContainerToMoleculeTreeNodeMapper;
_interactionContainerMapper = interactionContainerMapper;
}

public IMoleculeTreeNode MapFrom(MoleculeBuilderDTO input)
public IMoleculeTreeNode MapFrom(MoleculeBuilderDTO moleculeBuilderDTO)
{
var node = new MoleculeTreeNode(input) {Text = input.Name, Icon = ApplicationIcons.IconByName(input.Icon)};
var children = input.TransporterMolecules.MapAllUsing(_activeTransportBuilderContaienrToMolceculeTreeNodeMapper).ToList();
children = children.Union(input.InteractionContainerCollection.MapAllUsing(_interactionContainerMapper)).ToList();
var node = new MoleculeTreeNode(moleculeBuilderDTO) {Text = moleculeBuilderDTO.Name, Icon = ApplicationIcons.IconByName(moleculeBuilderDTO.Icon)};
var children = moleculeBuilderDTO.TransporterMolecules.MapAllUsing(_activeTransportBuilderContainerToMoleculeTreeNodeMapper).ToList();
children = children.Union(moleculeBuilderDTO.InteractionContainerCollection.MapAllUsing(_interactionContainerMapper)).ToList();
children.Each(node.AddChild);
return node;
}
}


public interface ITransporterMoleculeContainerDTOToMoleculeTreeNodeMapper : IMapper<TransporterMoleculeContainerDTO, IMoleculeTreeNode>
{
}

internal class TransporterMoleculeContainerDTOToMoleculeTreeNodeMapper : ITransporterMoleculeContainerDTOToMoleculeTreeNodeMapper
{
private readonly ITranpsortBuilderDTOToMoleculeTreeNodeMapper _activeTransportRealizationsBuilderToMolceculeTreeNodeMapper;
private readonly ITransportBuilderDTOToMoleculeTreeNodeMapper _activeTransportRealizationsBuilderToMoleculeTreeNodeMapper;

public TransporterMoleculeContainerDTOToMoleculeTreeNodeMapper(ITranpsortBuilderDTOToMoleculeTreeNodeMapper activeTransportRealizationsBuilderToMolceculeTreeNodeMapper)
public TransporterMoleculeContainerDTOToMoleculeTreeNodeMapper(ITransportBuilderDTOToMoleculeTreeNodeMapper activeTransportRealizationsBuilderToMoleculeTreeNodeMapper)
{
_activeTransportRealizationsBuilderToMolceculeTreeNodeMapper = activeTransportRealizationsBuilderToMolceculeTreeNodeMapper;
_activeTransportRealizationsBuilderToMoleculeTreeNodeMapper = activeTransportRealizationsBuilderToMoleculeTreeNodeMapper;
}

public IMoleculeTreeNode MapFrom(TransporterMoleculeContainerDTO input)
{
var node = new MoleculeTreeNode(input) {Text = input.Name, Icon = ApplicationIcons.IconByName(input.Icon)};
var children = input.Realizations.MapAllUsing(_activeTransportRealizationsBuilderToMolceculeTreeNodeMapper);
var children = input.Realizations.MapAllUsing(_activeTransportRealizationsBuilderToMoleculeTreeNodeMapper);
children.Each(node.AddChild);
return node;
}
}

internal interface ITranpsortBuilderDTOToMoleculeTreeNodeMapper : IMapper<TransportBuilderDTO, IMoleculeTreeNode>
internal interface ITransportBuilderDTOToMoleculeTreeNodeMapper : IMapper<TransportBuilderDTO, IMoleculeTreeNode>
{
}

internal class TranpsortBuilderDTOToMoleculeTreeNodeMapper : ITranpsortBuilderDTOToMoleculeTreeNodeMapper
internal class TransportBuilderDTOToMoleculeTreeNodeMapper : ITransportBuilderDTOToMoleculeTreeNodeMapper
{
public IMoleculeTreeNode MapFrom(TransportBuilderDTO input)
{
return new MoleculeTreeNode(input) {Text = input.Name, Icon = ApplicationIcons.IconByName(input.Icon)};
}
}

public interface IInteractionContainerDTOToMoleculeTreeMapper:IMapper<InteractionContainerDTO,IMoleculeTreeNode>
public interface IInteractionContainerDTOToMoleculeTreeMapper : IMapper<InteractionContainerDTO, IMoleculeTreeNode>
{

}

class InteractionContainerDTOToMoleculeTreeMapper : IInteractionContainerDTOToMoleculeTreeMapper
public class InteractionContainerDTOToMoleculeTreeMapper : IInteractionContainerDTOToMoleculeTreeMapper
{
public IMoleculeTreeNode MapFrom(InteractionContainerDTO input)
public IMoleculeTreeNode MapFrom(InteractionContainerDTO interactionContainerDTO)
{
return new MoleculeTreeNode(input) {Text = input.Name, Icon = ApplicationIcons.IconByName(input.Icon)};
return new MoleculeTreeNode(interactionContainerDTO)
{
Text = interactionContainerDTO.Name, Icon = ApplicationIcons.IconByName(interactionContainerDTO.Icon)
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
using MoBi.Assets;
using OSPSuite.Presentation.MenuAndBars;
using OSPSuite.Utility.Container;
using OSPSuite.Utility.Extensions;
using MoBi.Core;
using MoBi.Core.Domain.Model;
using MoBi.Core.Helper;
using MoBi.Presentation.DTO;
using MoBi.Presentation.UICommand;
using OSPSuite.Assets;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Presentation.Core;
using OSPSuite.Presentation.MenuAndBars;
using OSPSuite.Presentation.Presenters;
using OSPSuite.Presentation.Presenters.ContextMenus;
using OSPSuite.Assets;
using OSPSuite.Utility.Container;
using OSPSuite.Utility.Extensions;

namespace MoBi.Presentation.MenusAndBars.ContextMenus
{
internal class ContextMenuSpecificationFactoryForInteractionContainer : IContextMenuSpecificationFactory<IViewItem>
{
public IContextMenu CreateFor(IViewItem viewItem, IPresenterWithContextMenu<IViewItem> presenter)
{
//As long as Interaction Container is "just" a "container" we can reuse the container in event group here.(allows no subcontainer)
//As long as Interaction Container is "just" a "container" we can reuse the container in event group here.(allows no sub-container)
return IoC.Resolve<IContextMenuForContainerInMoleculeBuildingBlock>().InitializeWith(viewItem as ContainerDTO, presenter);
}

public bool IsSatisfiedBy(IViewItem objectRequestingContextMenu, IPresenterWithContextMenu<IViewItem> presenter)
{
{
return objectRequestingContextMenu.IsAnImplementationOf<InteractionContainerDTO>();
}
}

internal interface IContextMenuForContainerInMoleculeBuildingBlock:IContextMenuFor<InteractionContainer>
internal interface IContextMenuForContainerInMoleculeBuildingBlock : IContextMenuFor<InteractionContainer>
{
}

class ContextMenuForContainerInMoleculeBuildingBlock :ContextMenuForContainerBase<InteractionContainer>, IContextMenuForContainerInMoleculeBuildingBlock
class ContextMenuForContainerInMoleculeBuildingBlock : ContextMenuForContainerBase<InteractionContainer>, IContextMenuForContainerInMoleculeBuildingBlock
{
public ContextMenuForContainerInMoleculeBuildingBlock(IMoBiContext context, IObjectTypeResolver objectTypeResolver) : base(context, objectTypeResolver)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using FakeItEasy;
using FakeItEasy;
using MoBi.Core.Domain.Model;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;

Expand Down Expand Up @@ -62,6 +62,19 @@ protected override ParameterBuildMode GetBuildModeType()
}
}

public class When_adding_a_new_parameter_to_interaction_container : When_testing_for_appropriate_parameter_build_modes
{
protected override IContainer GetContainer()
{
return new InteractionContainer();
}

protected override ParameterBuildMode GetBuildModeType()
{
return ParameterBuildMode.Global;
}
}

public class When_adding_a_new_parameter_to_a_generic_container : When_testing_for_appropriate_parameter_build_modes
{
protected override IContainer GetContainer()
Expand All @@ -75,7 +88,7 @@ protected override ParameterBuildMode GetBuildModeType()
}
}

public class When_executing_inverse_of_add_a_new_paramter_to_container : concern_for_AddParameterToContainerCommand
public class When_executing_inverse_of_add_a_new_parameter_to_container : concern_for_AddParameterToContainerCommand
{
protected override void Context()
{
Expand All @@ -101,5 +114,4 @@ public void the_parameter_should_be_removed_from_the_container()
_container.ShouldBeEmpty();
}
}

}
}

0 comments on commit 1a77639

Please sign in to comment.