protected override void Context()
        {
            base.Context();
            _simulationToUpdate    = A.Fake <IMoBiSimulation>();
            _templateBuildingBlock = A.Fake <IBuildingBlock>();

            var rootContainer = createRootContainer();

            _simulationToUpdate.Model.Root = rootContainer;

            _originalParameterFixedNotBelongingToTemplate       = rootContainer.Parameter("P1");
            _originalParameterFixedNotBelongingToTemplate.Value = 5;

            _originalParameterFixedUpdatedByTemplate       = rootContainer.Parameter("P2");
            _originalParameterFixedUpdatedByTemplate.Value = 8;


            _buildingBlockInfoTemplate = A.Fake <IBuildingBlockInfo>();
            A.CallTo(() => _buildingBlockInfoTemplate.UntypedTemplateBuildingBlock).Returns(_templateBuildingBlock);

            //simulates the update command
            var container = createRootContainer();

            _updatedParameterFixedNotBelongingToTemplate = container.Parameter(_originalParameterFixedNotBelongingToTemplate.Name);
            _updatedParameterFixedUpdatedByTemplate      = container.Parameter(_originalParameterFixedUpdatedByTemplate.Name);

            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_updatedParameterFixedUpdatedByTemplate, _simulationToUpdate)).Returns(_buildingBlockInfoTemplate);
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_updatedParameterFixedNotBelongingToTemplate, _simulationToUpdate)).Returns(A.Fake <IBuildingBlockInfo>());

            A.CallTo(() => _simulationToUpdate.Update(A <IMoBiBuildConfiguration> ._, A <IModel> ._)).Invokes(x => { _simulationToUpdate.Model.Root = container; });
        }
 public void CheckForBuildingBlockChanges(IBuildingBlockInfo buildingBlockInfo, IBuildingBlock commitTargetBuildingBlock)
 {
     if (buildingBlockInfo.BuildingBlockChanged)
     {
         var typeName = _objectTypeResolver.TypeFor(commitTargetBuildingBlock);
         _dialogCreator.MessageBoxInfo(AppConstants.Dialog.PendingBuildingBlockChangesInfo(typeName, commitTargetBuildingBlock.Name));
     }
 }
 public void Edit(IBuildingBlockInfo <TBuildingBlock> buildingBlockInfo)
 {
     _buildingBlockInfo             = buildingBlockInfo;
     _editedBuildingBlock           = buildingBlockInfo.BuildingBlock;
     _originalTemplateBuildingBlock = buildingBlockInfo.TemplateBuildingBlock;
     _origialSimulationChanges      = buildingBlockInfo.SimulationChanges;
     updateSelectionWithBuildingBlock(_editedBuildingBlock ?? allAvailableTemplateBlocks.FirstOrDefault());
 }
Exemple #4
0
 private void checkTemplateBuildingBlock(IBuildingBlockInfo buildingBlockInfo)
 {
     if (!string.IsNullOrEmpty(buildingBlockInfo.TemplateBuildingBlockId))
     {
         return;
     }
     buildingBlockInfo.TemplateBuildingBlockId      = buildingBlockInfo.UntypedBuildingBlock.Id;
     buildingBlockInfo.UntypedTemplateBuildingBlock = buildingBlockInfo.UntypedBuildingBlock;
 }
 protected override void Context()
 {
     base.Context();
     _buildingBlockInfo              = A.Fake <IBuildingBlockInfo>();
     _classifiableSimulation         = new ClassifiableSimulation();
     _classifiableSimulation.Subject = new MoBiSimulation();
     _treeNode            = new BuildingBlockInfoNode(_buildingBlockInfo);
     _treeNode.ParentNode = new SimulationNode(_classifiableSimulation);
 }
 protected override void Context()
 {
     base.Context();
     _templateBuildingBlock      = A.Fake <IBuildingBlock>();
     _templateBuildingBlock.Name = "toto";
     _sim = A.Fake <IMoBiSimulation>();
     _buildingBlockInfo = A.Fake <IBuildingBlockInfo>();
     A.CallTo(() => _sim.MoBiBuildConfiguration.BuildingInfoForTemplate(_templateBuildingBlock)).Returns(_buildingBlockInfo);
     A.CallTo(() => _project.SimulationsCreatedUsing(_templateBuildingBlock)).Returns(new[] { _sim });
 }
Exemple #7
0
        private bool shouldUseTemplateForUpdate <T>(IBuildingBlockInfo <T> templateBuildingBlockInfo, IBuildingBlock templateBuildingBlock) where T : class, IBuildingBlock
        {
            if (templateBuildingBlockInfo.TemplateBuildingBlock == null)
            {
                return(false);
            }

            //only use template building block if the one previously used was the template itself or if the building block is unchanged in the simulation
            return(templateBuildingBlockInfo.TemplateBuildingBlock == templateBuildingBlock || !templateBuildingBlockInfo.BuildingBlockChanged);
        }
        protected override void Context()
        {
            base.Context();
            _project = A.Fake <IMoBiProject>();
            var sim1 = A.Fake <IMoBiSimulation>();

            _templateBuildingBlock = A.Fake <IBuildingBlock>();
            _buildingBlockInfo     = A.Fake <IBuildingBlockInfo>();
            A.CallTo(() => _project.SimulationsCreatedUsing(_templateBuildingBlock)).Returns(new [] { sim1 });
            A.CallTo(() => sim1.MoBiBuildConfiguration.BuildingInfoForTemplate(_templateBuildingBlock)).Returns(_buildingBlockInfo);
        }
        protected void UpdateStartValueInfo <TBuildingBlock, TStartValue>(IBuildingBlockInfo <TBuildingBlock> info, TBuildingBlock selectedBuildingBlock)
            where TBuildingBlock : class, IStartValuesBuildingBlock <TStartValue>
            where TStartValue : class, IStartValue
        {
            info.SimulationChanges += (selectedBuildingBlock.Version - info.TemplateBuildingBlock.Version);
            if (changedDuringCreation(info.TemplateBuildingBlock, selectedBuildingBlock))
            {
                info.SimulationChanges++;
            }

            info.BuildingBlock = selectedBuildingBlock;
        }
Exemple #10
0
        protected void Refresh(IBuildingBlockInfo <TBuildingBlock> startValueBuildingBlockInfo)
        {
            if (startValueBuildingBlockInfo.TemplateBuildingBlock == null)
            {
                return;
            }
            _templateStartValues = startValueBuildingBlockInfo.TemplateBuildingBlock.ToCache();

            StartValues         = _startValuesTask.CreateStartValuesForSimulation(_buildConfiguration);
            StartValues.Version = startValueBuildingBlockInfo.TemplateBuildingBlock.Version;
            _view.Description   = AppConstants.Captions.TemporaryStartValuesBasedOn(_objectTypeResolver.TypeFor(StartValues), StartValues.Name);
        }
        private void addConfigurationNodeUnder(ITreeNode buildConfigNode, IBuildingBlockInfo buildingBlockInfo)
        {
            var buildingBlock = buildingBlockInfo.UntypedBuildingBlock;

            var statusIcon = buildingBlockInfo.BuildingBlockChanged
            ? ApplicationIcons.RedOverlayFor(buildingBlock.Icon)
            : ApplicationIcons.GreenOverlayFor(buildingBlock.Icon);

            CreateFor(buildingBlockInfo)
            .WithIcon(statusIcon)
            .Under(buildConfigNode);
        }
        protected override void Context()
        {
            base.Context();
            _simulation    = A.Fake <IMoBiSimulation>();
            _simulation.Id = "toto";
            _simulationStatusChangedEvent = new SimulationStatusChangedEvent(_simulation);
            _simulationNode = new Nodes.TextNode("Simulation");

            var buildConfiguration = A.Fake <IMoBiBuildConfiguration>();

            var spatialStructure = A.Fake <IMoBiSpatialStructure>().WithId("SpatialStructure");

            spatialStructure.Version = 5;
            var templateSpatialStructure = A.Fake <IMoBiSpatialStructure>().WithId("TemplateSpatialStructure");
            var spatialStructureInfo     = new SpatialStructureInfo();

            spatialStructureInfo.TemplateBuildingBlock = templateSpatialStructure;
            spatialStructureInfo.BuildingBlock         = spatialStructure;
            buildConfiguration.SpatialStructureInfo    = spatialStructureInfo;
            A.CallTo(() => buildConfiguration.BuildingInfoForTemplateById(spatialStructureInfo.TemplateBuildingBlockId)).Returns(spatialStructureInfo);

            var moleculesInfo         = new MoleculesInfo();
            var templateBuildingBlock = A.Fake <IMoleculeBuildingBlock>().WithId("TemplateMolecules");
            var moleculeBuildingBlock = A.Fake <IMoleculeBuildingBlock>().WithId("Molecules");

            moleculesInfo.TemplateBuildingBlock = templateBuildingBlock;
            moleculesInfo.BuildingBlock         = moleculeBuildingBlock;
            A.CallTo(() => buildConfiguration.BuildingInfoForTemplateById(moleculesInfo.TemplateBuildingBlockId)).Returns(moleculesInfo);

            buildConfiguration.MoleculesInfo = moleculesInfo;
            A.CallTo(() => buildConfiguration.AllBuildingBlockInfos()).Returns(new IBuildingBlockInfo[] { spatialStructureInfo, moleculesInfo });
            A.CallTo(() => buildConfiguration.HasChangedBuildingBlocks()).Returns(true);

            _buildingBlockInfoDTOChanged   = spatialStructureInfo;
            _buildingBlockInfoDTOUnchanged = moleculesInfo;

            _treeView = A.Fake <IUxTreeView>();
            var configNode = new BuildConfigurationNode(buildConfiguration).Under(_simulationNode);

            _nodeToChange = new BuildingBlockInfoNode(_buildingBlockInfoDTOChanged)
                            .WithIcon(ApplicationIcons.SpatialStructureGreen)
                            .Under(configNode);

            _nodeNotToChange = new BuildingBlockInfoNode(_buildingBlockInfoDTOUnchanged)
                               .WithIcon(ApplicationIcons.MoleculeGreen)
                               .Under(configNode);

            A.CallTo(() => _view.TreeView).Returns(_treeView);
            A.CallTo(() => _treeView.NodeById(_simulation.Id)).Returns(_simulationNode);
            A.CallTo(() => _simulation.MoBiBuildConfiguration).Returns(buildConfiguration);
        }
Exemple #13
0
        protected override void Context()
        {
            _affectedBuildingBlockRetriever = A.Fake <IAffectedBuildingBlockRetriever>();
            _entityPathResolver             = A.Fake <IEntityPathResolver>();
            _context = A.Fake <IMoBiContext>();
            sut      = new QuantitySynchronizer(_affectedBuildingBlockRetriever, _entityPathResolver, _context);

            _simulation        = A.Fake <IMoBiSimulation>();
            _buildingBlockInfo = A.Fake <IBuildingBlockInfo>();
            _objectPath        = new ObjectPath("P");
            A.CallTo(() => _entityPathResolver.ObjectPathFor(_parameter, false)).Returns(_objectPath);
            A.CallTo(() => _entityPathResolver.PathFor(_parameter)).Returns("P");
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_quantity, _simulation)).Returns(_buildingBlockInfo);
        }
Exemple #14
0
        private void updateFrom <T>(IBuildingBlockInfo <T> buildingBlockInfo, IBuildingBlockInfo <T> templateBuildingBlockInfo, IBuildingBlock templateBuildingBlock) where T : class, IBuildingBlock
        {
            var shouldUseTemplate = shouldUseTemplateForUpdate(templateBuildingBlockInfo, templateBuildingBlock);

            var buildingBlockToUse = shouldUseTemplate ? templateBuildingBlockInfo.TemplateBuildingBlock : templateBuildingBlockInfo.BuildingBlock;

            update(buildingBlockInfo, templateBuildingBlockInfo, buildingBlockToUse);

            //since we are using the template building block, we reset the simulation change counter
            if (shouldUseTemplate)
            {
                buildingBlockInfo.SimulationChanges = 0;
            }
        }
        protected override void Context()
        {
            base.Context();
            var buildConfiguration          = A.Fake <IMoBiBuildConfiguration>();
            var affectedBuildingBlock       = new EventGroupBuildingBlock();
            var eventGroupBuildingBlockInfo = new EventGroupBuildingBlockInfo()
            {
                BuildingBlock = affectedBuildingBlock
            };

            _buildingBlockInfo = eventGroupBuildingBlockInfo;
            _simulation        = new MoBiSimulation {
                BuildConfiguration = buildConfiguration, Model = A.Fake <IModel>()
            };
            _changedQuantity = A.Fake <IQuantity>();
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(A <IQuantity> ._, _simulation)).Returns(eventGroupBuildingBlockInfo);
        }
Exemple #16
0
        private void cloneTo <T>(IBuildingBlockInfo <T> buildingBlockInfo, IBuildingBlockInfo <T> templateBuildingBlockInfo) where T : class, IBuildingBlock
        {
            var buildingBlockToUse = templateBuildingBlockInfo.BuildingBlock;

            //this is a template building block, we need to clone it. Otherwise use as is
            if (templateBuildingBlockInfo.BuildingBlockIsTemplate)
            {
                buildingBlockToUse = clone(templateBuildingBlockInfo.TemplateBuildingBlock);
            }

            update(buildingBlockInfo, templateBuildingBlockInfo, buildingBlockToUse);

            //since we are using the template building block, we reset the simulation change counter
            if (templateBuildingBlockInfo.BuildingBlockIsTemplate)
            {
                buildingBlockInfo.SimulationChanges = 0;
            }

            _registerTask.RegisterAllIn(buildingBlockInfo.BuildingBlock);
        }
Exemple #17
0
        protected override void Context()
        {
            _context = A.Fake <IMoBiContext>();
            _view    = A.Fake <IBuildingBlockSelectionView>();
            _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
            _interactionTask         = A.Fake <IInteractionTasksForBuildingBlock <IMoBiReactionBuildingBlock> >();
            sut = new BuildingBlockSelectionPresenter <IMoBiReactionBuildingBlock>(_view, _buildingBlockRepository, _interactionTask, _context);

            _buildingBlockInfo       = new ReactionBuildingBlockInfo();
            _templateBuildingBlock1  = A.Fake <IMoBiReactionBuildingBlock>().WithName("BB1");
            _templateBuildingBlock2  = A.Fake <IMoBiReactionBuildingBlock>().WithName("BB2");
            _simulationBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithName("BBSIM");
            _allBuildingBlocks       = new List <IMoBiReactionBuildingBlock> {
                _templateBuildingBlock1, _templateBuildingBlock2
            };
            A.CallTo(() => _buildingBlockRepository.All <IMoBiReactionBuildingBlock>()).Returns(_allBuildingBlocks);

            A.CallTo(() => _view.BindTo(A <BuildingBlockSelectionDTO> ._))
            .Invokes(x => _buildingBlockSelectionDTO = x.GetArgument <BuildingBlockSelectionDTO>(0));
        }
 protected override void Context()
 {
     _simulation = A.Fake <IMoBiSimulation>();
     _buildingBlockInfoUpdater                                 = A.Fake <IBuilingBlockReferenceUpdater>();
     _oldTemplateBuildingBlock                                 = A.Fake <IParameterStartValuesBuildingBlock>().WithName("OLD TEMPLATE");
     _clonedSimulationBuildingBlock                            = A.Fake <IParameterStartValuesBuildingBlock>().WithName("CLONE SIMULATION");
     _oldTemplateBuildingBlock.Version                         = 7;
     _clonedSimulationBuildingBlock.Version                    = 4;
     _simulationBuildingBlockInfo                              = A.Fake <IBuildingBlockInfo>();
     _simulationBuildingBlockInfo.SimulationChanges            = 5;
     _simulationBuildingBlockInfo.UntypedTemplateBuildingBlock = _oldTemplateBuildingBlock;
     _simulationBuildingBlock = A.Fake <IBuildingBlock>();
     _simulationBuildingBlockInfo.UntypedBuildingBlock = _simulationBuildingBlock;
     _simulationBuildingBlock.Version = _clonedSimulationBuildingBlock.Version;
     _simulationBuildingBlock.Name    = "TRALALA";
     A.CallTo(_simulation.MoBiBuildConfiguration).WithReturnType <IBuildingBlockInfo>().Returns(_simulationBuildingBlockInfo);
     _context = A.Fake <IMoBiContext>();
     A.CallTo(() => _context.Resolve <IBuilingBlockReferenceUpdater>()).Returns(_buildingBlockInfoUpdater);
     sut = new UpdateTemplateBuildingBlockFromSimulationBuildingBlockCommand <IParameterStartValuesBuildingBlock>(_oldTemplateBuildingBlock, _clonedSimulationBuildingBlock, _simulation);
 }
        protected override void Context()
        {
            base.Context();
            _project = A.Fake <IMoBiProject>();
            var sim1 = A.Fake <IMoBiSimulation>();
            var sim2 = A.Fake <IMoBiSimulation>();

            _template1     = A.Fake <IBuildingBlock>().WithName("Template1");
            _template2     = A.Fake <IBuildingBlock>().WithName("Template2");
            _buildInfoSim1 = A.Fake <IBuildingBlockInfo>();
            _buildInfoSim1.TemplateBuildingBlockId = "T1";

            _buildInfoSim2 = A.Fake <IBuildingBlockInfo>();
            _buildInfoSim2.TemplateBuildingBlockId = "T2";

            A.CallTo(() => sim1.MoBiBuildConfiguration.AllBuildingBlockInfos()).Returns(new[] { _buildInfoSim1 });
            A.CallTo(() => sim2.MoBiBuildConfiguration.AllBuildingBlockInfos()).Returns(new[] { _buildInfoSim2 });
            A.CallTo(() => _project.Simulations).Returns(new[] { sim1, sim2 });
            A.CallTo(() => _project.TemplateById(_buildInfoSim1.TemplateBuildingBlockId)).Returns(_template1);
            A.CallTo(() => _project.TemplateById(_buildInfoSim2.TemplateBuildingBlockId)).Returns(_template2);
        }
 protected override void Because()
 {
     _result = sut.RetrieveFor(_passiveTransportParameter, _simulation);
 }
 public ITreeNode CreateFor(IBuildingBlockInfo buildingBlockInfo)
 {
     return(new BuildingBlockInfoNode(buildingBlockInfo));
 }
Exemple #22
0
 public BuildingBlockInfoViewItem(IBuildingBlockInfo buildingBlockInfoInfo, IMoBiSimulation simulation)
 {
     BuildingBlockInfo = buildingBlockInfoInfo;
     Simulation        = simulation;
 }
 protected override void Because()
 {
     _result = sut.RetrieveFor(new Parameter(), _simulation);
 }
Exemple #24
0
        /// <summary>
        ///    Updates the start values defined in <paramref name="startValuesToUpdate" /> with the values defined in
        ///    <paramref name="startValueInfo" />. Returns a template cache containg all values defined in the template
        /// </summary>
        public ICache <string, TStartValue> UpdateValuesFromTemplate(TBuildingBlock startValuesToUpdate, IBuildingBlockInfo <TBuildingBlock> startValueInfo)
        {
            var templateStartValues = startValueInfo.BuildingBlock;

            if (startValueInfo.BuildingBlockIsTemplate)
            {
                templateStartValues = startValueInfo.TemplateBuildingBlock;
            }

            var startValueCache = startValuesToUpdate.ToCache();
            var templateCache   = templateStartValues.ToCache();

            _cloneManagerForBuildingBlock.FormulaCache = startValuesToUpdate.FormulaCache;

            try
            {
                foreach (var templateKeyValue in templateCache.KeyValues)
                {
                    var startValue = startValueCache[templateKeyValue.Key];

                    if (startValue == null)
                    {
                        addStartValueToCache(startValuesToUpdate, templateKeyValue.Value);
                    }
                    else
                    {
                        startValue.UpdatePropertiesFrom(templateKeyValue.Value, _cloneManagerForBuildingBlock);
                    }
                }
                startValuesToUpdate.Version = templateStartValues.Version;
            }
            finally
            {
                _cloneManagerForBuildingBlock.FormulaCache = null;
            }
            return(templateCache);
        }
 protected override void Because()
 {
     _result = sut.RetrieveFor(A.Fake <IMoleculeAmount>(), _simulation);
 }
 private IBuildingBlockInfo modeDependentInfo(IParameter parameter, IBuildingBlockInfo defautBuildingBlockInfo, IBuildingBlockInfo parameterStartValuesInfo)
 {
     return(parameter.BuildMode == ParameterBuildMode.Local ? parameterStartValuesInfo : defautBuildingBlockInfo);
 }
 protected override void Because()
 {
     _result = sut.RetrieveFor(A.Fake <IObserver>(), _simulation);
 }
Exemple #28
0
        private T createForProject <T>(IReadOnlyCollection <T> projectBuildingBlocks, IBuildingBlockInfo <T> buildingBlockInfo) where T : class, IBuildingBlock
        {
            //this was already added to the project
            var templateBuildingBlock = projectBuildingBlocks.FindById(buildingBlockInfo.TemplateBuildingBlockId);

            if (templateBuildingBlock != null)
            {
                buildingBlockInfo.TemplateBuildingBlock = templateBuildingBlock;
                return(null);
            }

            templateBuildingBlock = buildingBlockInfo.BuildingBlock;
            if (!_nameCorrector.CorrectName(projectBuildingBlocks, templateBuildingBlock))
            {
                return(null);
            }

            buildingBlockInfo.TemplateBuildingBlock = templateBuildingBlock;
            buildingBlockInfo.BuildingBlock         = _cloneManager.CloneBuidingBlock(templateBuildingBlock);
            return(templateBuildingBlock);
        }
Exemple #29
0
 private void update <T>(IBuildingBlockInfo <T> buildingBlockInfo, IBuildingBlockInfo <T> templateBuildingBlockInfo, T usedBuildingBlock) where T : class, IBuildingBlock
 {
     buildingBlockInfo.BuildingBlock         = usedBuildingBlock;
     buildingBlockInfo.TemplateBuildingBlock = templateBuildingBlockInfo.TemplateBuildingBlock;
     buildingBlockInfo.SimulationChanges     = templateBuildingBlockInfo.SimulationChanges;
 }