Exemplo n.º 1
0
        protected override void Context()
        {
            _toolTipPartCreator      = A.Fake <IToolTipPartCreator>();
            _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
            sut = new BuildingBlockSelectionDisplayer(_buildingBlockRepository, _toolTipPartCreator);

            _templateCompound    = new Compound().WithName("A").WithId("A");
            _nonTemplateCompound = new Compound().WithName("B").WithId("B");

            A.CallTo(() => _buildingBlockRepository.ById(_templateCompound.Id)).Returns(_templateCompound);
            A.CallTo(() => _buildingBlockRepository.ById(_nonTemplateCompound.Id)).Returns(null);
        }
        public BuildingBlockStatus StatusFor(UsedBuildingBlock usedBuildingBlock)
        {
            if (usedBuildingBlock.Altered)
            {
                return(BuildingBlockStatus.Red);
            }

            //template does not exist. This could be a simple import
            var buildingBlock = _buildingBlockRepository.ById(usedBuildingBlock.TemplateId);

            if (buildingBlock == null)
            {
                return(BuildingBlockStatus.Red);
            }

            return(buildingBlock.Version == usedBuildingBlock.Version ? BuildingBlockStatus.Green : BuildingBlockStatus.Red);
        }
Exemplo n.º 3
0
 protected override void Context()
 {
     _eventPublisher          = A.Fake <IEventPublisher>();
     _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
     _simulation1             = new IndividualSimulation();
     _simulation2             = new IndividualSimulation();
     _simulation3             = new IndividualSimulation();
     A.CallTo(() => _buildingBlockRepository.All <Simulation>()).Returns(new[] { _simulation1, _simulation2, _simulation3 });
     _id = "tralala";
     _templateBuildingBlock = A.Fake <IPKSimBuildingBlock>().WithId(_id);
     _usedBuildingBlock     = new UsedBuildingBlock(_templateBuildingBlock.Id, _templateBuildingBlock.BuildingBlockType);
     A.CallTo(() => _buildingBlockRepository.ById(_templateBuildingBlock.Id)).Returns(_templateBuildingBlock);
     sut = new BuildingBlockInProjectManager(_buildingBlockRepository, _eventPublisher);
 }
        public override void Build(IEnumerable <UsedBuildingBlock> usedBuildingBlocks, OSPSuiteTracker buildTracker)
        {
            var table = new DataTable();

            table.AddColumn(PKSimConstants.UI.BuildingBlock);
            table.AddColumn <Text>(PKSimConstants.UI.Name);

            foreach (var usedBuildingBlock in usedBuildingBlocks)
            {
                var row         = table.NewRow();
                var defaultText = new Text(usedBuildingBlock.Name);
                row[PKSimConstants.UI.BuildingBlock] = usedBuildingBlock.BuildingBlockType.ToString();

                var templateBuildingBlock = _buildingBlockRepository.ById(usedBuildingBlock.TemplateId);
                //should never happen
                if (templateBuildingBlock == null)
                {
                    row[PKSimConstants.UI.Name] = defaultText;
                }

                else if (templateBuildingBlock.Version == usedBuildingBlock.Version)
                {
                    var reference = buildTracker.ReferenceFor(templateBuildingBlock);
                    if (reference == null)
                    {
                        row[PKSimConstants.UI.Name] = defaultText;
                    }
                    else
                    {
                        var partBuildingBlocks = getReferenceForPartBuildingBlocks(buildTracker);
                        row[PKSimConstants.UI.Name] = new Text("{0} (see {1} in {2})", defaultText,
                                                               reference, partBuildingBlocks)
                        {
                            Converter = NoConverter.Instance
                        };
                    }
                }

                else
                {
                    row[PKSimConstants.UI.Name] = defaultText;
                }

                table.Rows.Add(row);
            }

            _builderRepository.Report(new Table(table.DefaultView, PKSimConstants.UI.BuildingBlock), buildTracker);
        }
Exemplo n.º 5
0
        private Formulation retrieveFormulation(Simulation simulation, FormulationMapping formulationMapping, Func <UsedBuildingBlock, Formulation> formulationRetriever)
        {
            if (!isValid(formulationMapping))
            {
                return(null);
            }

            var templateFormulation = _buildingBlockRepository.ById <Formulation>(formulationMapping.TemplateFormulationId);
            var usedBuildingBlock   = simulation.UsedBuildingBlockByTemplateId(formulationMapping.TemplateFormulationId);

            //this forumation was not used in the simulation yet, return the template
            if (usedBuildingBlock == null)
            {
                return(templateFormulation);
            }

            //formulation was used in the simulation.
            var formulation = formulationRetriever(usedBuildingBlock);

            return(formulation ?? templateFormulation);
        }
        private string speciesNameFrom(UsedBuildingBlock usedBuildingBlock)
        {
            var individual = _buildingBlockRepository.ById(usedBuildingBlock.TemplateId) as Individual;

            return(individual == null?usedBuildingBlock.BuildingBlockType.ToString() : individual.Species.Name);
        }
Exemplo n.º 7
0
        private string individualIconFor(UsedBuildingBlock usedBuildingBlock)
        {
            var individual = _buildingBlockRepository.ById(usedBuildingBlock.TemplateId) as Individual;

            return(individual == null?usedBuildingBlock.BuildingBlockType.ToString() : individual.Icon);
        }
 private bool isTemplate(IPKSimBuildingBlock buildingBlock, IPKSimBuildingBlock emptySelection)
 {
     return(Equals(buildingBlock, emptySelection) ||
            _buildingBlockRepository.ById(buildingBlock.Id) != null);
 }