From fddffe0bbcbfaea48fbf5d25d0f7de81ba4feb71 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Tue, 12 Apr 2022 13:02:43 -0400 Subject: [PATCH 1/2] Add one test to get a fail --- .../v11/Converter10to11Specs.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs b/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs index 1c6ddc2f5..ada225fc4 100644 --- a/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs +++ b/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs @@ -147,6 +147,7 @@ public override void GlobalContext() LoadProject("expression_v10"); _allPopulations = All(); _allIndividuals = All(); + _allPopulations.Each(Load); _allIndividuals.Each(Load); } @@ -188,4 +189,37 @@ public void should_have_set_the_initial_concentration_parameter_to_not_variable_ allInitialConcentrationParameters.Each(x => x.CanBeVariedInPopulation.ShouldBeFalse()); } } + + public class When_converting_the_expression_v10_project_to_11_and_an_expression_profile_is_added_with_the_name_that_would_be_created_from_conversion : ContextWithLoadedProject + { + private Individual _ind; + private ExpressionProfile _existingExpressionProfile; + + public override void GlobalContext() + { + base.GlobalContext(); + LoadProject("expression_v10"); + var individuals = All(); + _ind = individuals.FindByName("Ind"); + } + + protected override void Because() + { + //add an expression profile with the name + _existingExpressionProfile = DomainHelperForSpecs.CreateExpressionProfile(_ind.Species.Name, "CYP3A4", _ind.Name); + _project.AddBuildingBlock(_existingExpressionProfile); + + //now load to trigger conversion + Load(_ind); + } + + [Observation] + public void should_have_created_an_expression_profile_named_differently() + { + _ind.Uses(_existingExpressionProfile).ShouldBeFalse(); + var expressionProfile = FindByName($"{_existingExpressionProfile.Name}_1"); + expressionProfile.ShouldNotBeNull(); + _ind.Uses(expressionProfile).ShouldBeTrue(); + } + } } \ No newline at end of file From c06e5ac450cd1aa1faca3878aced9d204ceedd7b Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Tue, 12 Apr 2022 13:33:48 -0400 Subject: [PATCH 2/2] Fixes #2190 project conversion issue --- .../ProjectConverter/v11/Converter10to11.cs | 10 +++++++--- .../ProjectConverter/v11/Converter10to11Specs.cs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PKSim.Infrastructure/ProjectConverter/v11/Converter10to11.cs b/src/PKSim.Infrastructure/ProjectConverter/v11/Converter10to11.cs index fd41d4ae6..322d22a6f 100644 --- a/src/PKSim.Infrastructure/ProjectConverter/v11/Converter10to11.cs +++ b/src/PKSim.Infrastructure/ProjectConverter/v11/Converter10to11.cs @@ -178,12 +178,16 @@ private void addEstimatedGFRParameterTo(Individual individual) private void addExpressionProfilesUsedBySimulationSubjectToProject(ISimulationSubject simulationSubject) { + var project = _projectRetriever.Current; foreach (var molecule in simulationSubject.AllMolecules()) { + var defaultExpressionProfileName = CoreConstants.ContainerName.ExpressionProfileName(molecule.Name, simulationSubject.Species, simulationSubject.Name); + + var expressionProfileName = _containerTask.CreateUniqueName(project.All(), defaultExpressionProfileName, canUseBaseName: true); var expressionProfile = _expressionProfileFactory.Create(molecule.GetType(), simulationSubject.Species, molecule.Name); - //Make sure the name does not have our separator - expressionProfile.Category = simulationSubject.Name; + //Use a unique name in project + expressionProfile.Name = expressionProfileName; _expressionProfileUpdater.SynchronizeExpressionProfileWithSimulationSubject(expressionProfile, simulationSubject); //Some parameters are probably marked as FixedValue event thought they have not changed (Formula=>constant) due to change in @@ -195,7 +199,7 @@ private void addExpressionProfilesUsedBySimulationSubjectToProject(ISimulationSu //only add at the end once the expression profile has been updated simulationSubject.AddExpressionProfile(expressionProfile); - _projectRetriever.Current.AddBuildingBlock(expressionProfile); + project.AddBuildingBlock(expressionProfile); _registrationTask.Register(expressionProfile); _eventPublisher.PublishEvent(new BuildingBlockAddedEvent(expressionProfile, _projectRetriever.Current)); } diff --git a/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs b/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs index ada225fc4..29d25a467 100644 --- a/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs +++ b/tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs @@ -217,7 +217,7 @@ protected override void Because() public void should_have_created_an_expression_profile_named_differently() { _ind.Uses(_existingExpressionProfile).ShouldBeFalse(); - var expressionProfile = FindByName($"{_existingExpressionProfile.Name}_1"); + var expressionProfile = FindByName($"{_existingExpressionProfile.Name} 1"); expressionProfile.ShouldNotBeNull(); _ind.Uses(expressionProfile).ShouldBeTrue(); }