44using Microsoft . Extensions . Logging ;
55using OSPSuite . BDDHelper ;
66using OSPSuite . BDDHelper . Extensions ;
7+ using OSPSuite . Core ;
78using OSPSuite . Core . Domain ;
89using OSPSuite . Core . Domain . ParameterIdentifications ;
910using OSPSuite . Core . Domain . Services . ParameterIdentifications ;
1011using OSPSuite . Core . Services ;
12+ using OSPSuite . Utility . Extensions ;
1113using PKSim . Core . Model ;
1214using PKSim . Core . Snapshots . Mappers ;
1315using Parameter = PKSim . Core . Snapshots . Parameter ;
@@ -19,26 +21,32 @@ public abstract class concern_for_IdentificationParameterMapper : ContextSpecifi
1921 protected ParameterMapper _parameterMapper ;
2022 protected IdentificationParameter _identificationParameter ;
2123 protected Snapshots . IdentificationParameter _snapshot ;
22- private Simulation _simulation ;
24+ protected Simulation _simulation ;
2325 private IParameter _parameter1 ;
2426 private IParameter _parameter2 ;
27+ private IParameter _parameter3 ;
2528 private IParameter _startValueParameter ;
2629 protected Parameter _snapshotStartValueParameter ;
2730 protected ParameterSelection _parameterSelection1 ;
2831 protected ParameterSelection _parameterSelection2 ;
32+ private ParameterSelection _parameterSelection3 ;
33+ private ParameterSelection _gfrSelection ;
2934 protected IIdentificationParameterFactory _identificationParameterFactory ;
3035 protected IOSPSuiteLogger _logger ;
3136 protected ParameterIdentificationContext _parameterIdentificationContext ;
3237 private ParameterIdentification _parameterIdentification ;
3338 private PKSimProject _project ;
3439 protected IIdentificationParameterTask _identificationParameterTask ;
3540 private SnapshotContext _snapshotContext ;
41+ private IParameter _gfrFraction ;
42+ private IParameter _renalClearances ;
43+ private ParameterSelection _renalSelection ;
3644
3745 protected override Task Context ( )
3846 {
3947 _parameterMapper = A . Fake < ParameterMapper > ( ) ;
40- _identificationParameterFactory = A . Fake < IIdentificationParameterFactory > ( ) ;
41- _logger = A . Fake < IOSPSuiteLogger > ( ) ;
48+ _identificationParameterFactory = A . Fake < IIdentificationParameterFactory > ( ) ;
49+ _logger = A . Fake < IOSPSuiteLogger > ( ) ;
4250 _identificationParameterTask = A . Fake < IIdentificationParameterTask > ( ) ;
4351 sut = new IdentificationParameterMapper ( _parameterMapper , _identificationParameterFactory , _identificationParameterTask , _logger ) ;
4452
@@ -56,25 +64,55 @@ protected override Task Context()
5664 _identificationParameter . Name = "PARAM" ;
5765 _parameter1 = DomainHelperForSpecs . ConstantParameterWithValue ( ) . WithName ( "P1" ) ;
5866 _parameter2 = DomainHelperForSpecs . ConstantParameterWithValue ( ) . WithName ( "P2" ) ;
67+ _parameter3 = DomainHelperForSpecs . ConstantParameterWithValue ( ) . WithName ( "P3" ) ;
68+ _gfrFraction = DomainHelperForSpecs . ConstantParameterWithValue ( ) . WithName ( "P4" ) ;
69+ _renalClearances = DomainHelperForSpecs . ConstantParameterWithValue ( ) . WithName ( "P5" ) ;
5970 _simulation = A . Fake < Simulation > ( ) . WithName ( "S" ) ;
60- _simulation . Model . Root = new Container { _parameter1 , _parameter2 } ;
71+ _simulation . Model . Root = new Container
72+ {
73+ _parameter1 ,
74+ _parameter2 ,
75+ new Container { _parameter3 } . WithName ( CoreConstants . ContainerName . Applications ) ,
76+ new Container
77+ {
78+ new Container
79+ {
80+ _gfrFraction
81+ } . WithName ( "Glomerular Filtration-GFR" ) ,
82+ new Container
83+ {
84+ _renalClearances
85+ } . WithName ( "Renal Clearances-test" )
86+ } . WithName ( "Alprazolam" )
87+ } ;
6188
6289 _identificationParameter . Scaling = Scalings . Linear ;
6390 _parameterSelection1 = new ParameterSelection ( _simulation , _parameter1 . Name ) ;
6491 _parameterSelection2 = new ParameterSelection ( _simulation , _parameter2 . Name ) ;
92+ _parameterSelection3 = new ParameterSelection ( _simulation , new ObjectPath ( CoreConstants . ContainerName . Applications , _parameter3 . Name ) ) ;
93+ _gfrSelection = new ParameterSelection ( _simulation , new ObjectPath ( "Alprazolam" , "Glomerular Filtration-GFR" , _gfrFraction . Name ) ) ;
94+ _renalSelection = new ParameterSelection ( _simulation , new ObjectPath ( "Alprazolam" , "Renal Clearances-test" , _renalClearances . Name ) ) ;
6595 _identificationParameter . AddLinkedParameter ( _parameterSelection1 ) ;
6696 _identificationParameter . AddLinkedParameter ( _parameterSelection2 ) ;
97+ _identificationParameter . AddLinkedParameter ( _parameterSelection3 ) ;
98+ _identificationParameter . AddLinkedParameter ( _gfrSelection ) ;
99+ _identificationParameter . AddLinkedParameter ( _renalSelection ) ;
67100
68101 _snapshotStartValueParameter = new Parameter ( ) ;
69102 A . CallTo ( ( ) => _parameterMapper . MapToSnapshot ( _startValueParameter ) ) . Returns ( _snapshotStartValueParameter ) ;
70103
71104 _project = new PKSimProject ( ) ;
72105 _project . AddBuildingBlock ( _simulation ) ;
73- _snapshotContext = new SnapshotContext ( _project , ProjectVersions . Current ) ;
106+ _snapshotContext = new SnapshotContext ( _project , GetSnapshotContextVersion ( ) ) ;
74107 _parameterIdentification = new ParameterIdentification ( ) ;
75108 _parameterIdentificationContext = new ParameterIdentificationContext ( _parameterIdentification , _snapshotContext ) ;
76109 return _completed ;
77110 }
111+
112+ protected virtual ProjectVersion GetSnapshotContextVersion ( )
113+ {
114+ return ProjectVersions . Current ;
115+ }
78116 }
79117
80118 public class When_mapping_an_identification_parameter_to_snapshot : concern_for_IdentificationParameterMapper
@@ -167,4 +205,66 @@ public void should_log_a_warning()
167205 A . CallTo ( ( ) => _logger . AddToLog ( A < string > . _ , LogLevel . Warning , A < string > . _ ) ) . MustHaveHappened ( ) ;
168206 }
169207 }
208+
209+ public class When_updating_a_v11_snapshot : concern_for_IdentificationParameterMapper
210+ {
211+ private IdentificationParameter _newParameterIdentification ;
212+
213+ protected override async Task Context ( )
214+ {
215+ await base . Context ( ) ;
216+ _snapshot = await sut . MapToSnapshot ( _identificationParameter ) ;
217+ A . CallTo ( ( ) => _identificationParameterFactory . CreateFor ( A < IEnumerable < ParameterSelection > > . _ , _parameterIdentificationContext . ParameterIdentification ) ) . ReturnsLazily ( x => createNewIdentificationParameter ( x . Arguments . Get < IEnumerable < ParameterSelection > > ( 0 ) ) ) ;
218+ renameApplications ( _simulation . Model ) ;
219+ renameRenalClearances ( _simulation . Model ) ;
220+ }
221+
222+ protected override ProjectVersion GetSnapshotContextVersion ( )
223+ {
224+ return ProjectVersions . V11 ;
225+ }
226+
227+ private IdentificationParameter createNewIdentificationParameter ( IEnumerable < ParameterSelection > parameterSelections )
228+ {
229+ var newIdentificationParameter = new IdentificationParameter ( ) ;
230+
231+ parameterSelections . Each ( newIdentificationParameter . AddLinkedParameter ) ;
232+ return newIdentificationParameter ;
233+ }
234+
235+ private void renameRenalClearances ( IModel model )
236+ {
237+ model . Root . GetAllChildren < IContainer > ( ) . Each ( container =>
238+ {
239+ if ( container . Name . Equals ( "Glomerular Filtration-GFR" ) )
240+ container . Name = "Glomerular Filtration-GFR-Alprazolam" ;
241+
242+ if ( container . Name . Equals ( "Renal Clearances-test" ) )
243+ container . Name = "Renal Clearances-test-Alprazolam" ;
244+ } ) ;
245+ }
246+
247+ private static void renameApplications ( IModel model )
248+ {
249+ model . Root . GetAllChildren < IContainer > ( ) . Each ( container =>
250+ {
251+ if ( container . Name . Equals ( CoreConstants . ContainerName . Applications ) )
252+ container . Name = "Events" ;
253+ } ) ;
254+ }
255+
256+ protected override async Task Because ( )
257+ {
258+ _newParameterIdentification = await sut . MapToModel ( _snapshot , _parameterIdentificationContext ) ;
259+ }
260+
261+ [ Observation ]
262+ public void should_change_the_parameter_selection_paths ( )
263+ {
264+ _newParameterIdentification . AllLinkedParameters . Count . ShouldBeEqualTo ( 5 ) ;
265+ _newParameterIdentification . AllLinkedParameters [ 2 ] . PathArray . ShouldContain ( "Events" ) ;
266+ _newParameterIdentification . AllLinkedParameters [ 3 ] . PathArray . ShouldContain ( "Glomerular Filtration-GFR-Alprazolam" ) ;
267+ _newParameterIdentification . AllLinkedParameters [ 4 ] . PathArray . ShouldContain ( "Renal Clearances-test-Alprazolam" ) ;
268+ }
269+ }
170270}
0 commit comments