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

Fixes #769 parameter should be global for interaction container #770

Merged
merged 1 commit into from
Oct 7, 2022
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
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>();
Copy link
Member Author

Choose a reason for hiding this comment

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

the fix


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)};
Copy link
Member Author

Choose a reason for hiding this comment

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

All the changes here are just a million typos in the file. Not related to actual change

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;
Copy link
Member Author

Choose a reason for hiding this comment

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

the test

Copy link
Member

Choose a reason for hiding this comment

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

Observations from the base test class are automatically executed when running the tests in the derived class?
I did not know it

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it's because it's derived and we try to find an Obervation in each class. Pretty neat (but potentially way over engineered in this case)

Copy link
Member

Choose a reason for hiding this comment

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

I think it's pretty usefull.
In the case like this I have always defined a function testXY() in the base class and the observation in each derived class which just called testXY() - which could be avoided with this feature :)

}
}

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();
}
}

}
}