-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1884 Create domain object for Module
- Loading branch information
1 parent
e2bf896
commit d42c6b2
Showing
4 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using OSPSuite.Core.Domain.Builder; | ||
using OSPSuite.Core.Domain.Services; | ||
using OSPSuite.Utility.Extensions; | ||
|
||
namespace OSPSuite.Core.Domain | ||
{ | ||
public abstract class BaseModule : ObjectBase | ||
{ | ||
public IMoleculeBuildingBlock MoleculeBlock { set; get; } | ||
public IReactionBuildingBlock ReactionBlock { set; get; } | ||
public IPassiveTransportBuildingBlock PassiveTransport { set; get; } | ||
public ISpatialStructure SpatialStructure { set; get; } | ||
public IObserverBuildingBlock ObserverBlock { set; get; } | ||
public IEventGroupBuildingBlock EventBlock { set; get; } | ||
public IList<IMoleculeStartValuesBuildingBlock> MoleculeStartValueBlockCollection { set; get; } = new List<IMoleculeStartValuesBuildingBlock>(); | ||
public IList<IParameterStartValuesBuildingBlock> ParametersStartValueBlockCollection { set; get; } = new List<IParameterStartValuesBuildingBlock>(); | ||
|
||
public abstract bool UserEditable { get; } | ||
|
||
public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager) | ||
{ | ||
base.UpdatePropertiesFrom(source, cloneManager); | ||
|
||
if (!(source is BaseModule sourceModule)) | ||
return; | ||
|
||
MoleculeBlock = cloneManager.Clone(sourceModule.MoleculeBlock); | ||
ReactionBlock = cloneManager.Clone(sourceModule.ReactionBlock); | ||
PassiveTransport = cloneManager.Clone(sourceModule.PassiveTransport); | ||
SpatialStructure = cloneManager.Clone(sourceModule.SpatialStructure); | ||
ObserverBlock = cloneManager.Clone(sourceModule.ObserverBlock); | ||
EventBlock = cloneManager.Clone(sourceModule.EventBlock); | ||
|
||
sourceModule.MoleculeStartValueBlockCollection.Each(x => MoleculeStartValueBlockCollection.Add(cloneManager.Clone<IMoleculeStartValuesBuildingBlock>(x))); | ||
sourceModule.ParametersStartValueBlockCollection.Each(x => ParametersStartValueBlockCollection.Add(cloneManager.Clone(x))); | ||
} | ||
} | ||
|
||
public class ExtensionModule : BaseModule | ||
{ | ||
public override bool UserEditable => true; | ||
} | ||
|
||
public class PKSimModule : BaseModule | ||
{ | ||
public override bool UserEditable => false; | ||
|
||
public string PKSimVersion { set; get; } | ||
|
||
public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager) | ||
{ | ||
base.UpdatePropertiesFrom(source, cloneManager); | ||
if (!(source is PKSimModule sourcePKSimModule)) | ||
return; | ||
|
||
PKSimVersion = sourcePKSimModule.PKSimVersion; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using FakeItEasy; | ||
using OSPSuite.BDDHelper; | ||
using OSPSuite.BDDHelper.Extensions; | ||
using OSPSuite.Core.Domain.Builder; | ||
using OSPSuite.Core.Domain.Services; | ||
using OSPSuite.Helpers; | ||
|
||
namespace OSPSuite.Core.Domain | ||
{ | ||
public class concern_for_Module<T> : ContextSpecification<T> where T: BaseModule, new() | ||
{ | ||
protected override void Context() | ||
{ | ||
sut = new T | ||
{ | ||
PassiveTransport = new PassiveTransportBuildingBlock(), | ||
SpatialStructure = new SpatialStructure(), | ||
ObserverBlock = new ObserverBuildingBlock(), | ||
EventBlock = new EventGroupBuildingBlock(), | ||
ReactionBlock = new ReactionBuildingBlock(), | ||
MoleculeBlock = new MoleculeBuildingBlock() | ||
}; | ||
|
||
sut.MoleculeStartValueBlockCollection.Add(new MoleculeStartValuesBuildingBlock()); | ||
sut.ParametersStartValueBlockCollection.Add(new ParameterStartValuesBuildingBlock()); | ||
} | ||
} | ||
|
||
public class When_the_module_is_cloned<T> : concern_for_Module<T> where T : BaseModule, new() | ||
{ | ||
protected T _clone; | ||
private DimensionFactoryForIntegrationTests _dimensionFactory; | ||
private IModelFinalizer _modelFinalizer; | ||
private CloneManagerForModel _cloneManager; | ||
|
||
protected override void Context() | ||
{ | ||
base.Context(); | ||
_modelFinalizer = A.Fake<IModelFinalizer>(); | ||
_dimensionFactory = new DimensionFactoryForIntegrationTests(); | ||
_cloneManager = new CloneManagerForModel(new ObjectBaseFactoryForSpecs(_dimensionFactory), new DataRepositoryTask(), _modelFinalizer); | ||
} | ||
|
||
protected override void Because() | ||
{ | ||
_clone = _cloneManager.Clone(sut); | ||
} | ||
|
||
[Observation] | ||
public void should_have_created_a_clone_with_the_same_properties() | ||
{ | ||
_clone.PassiveTransport.ShouldNotBeNull(); | ||
_clone.SpatialStructure.ShouldNotBeNull(); | ||
_clone.ObserverBlock.ShouldNotBeNull(); | ||
_clone.EventBlock.ShouldNotBeNull(); | ||
_clone.ReactionBlock.ShouldNotBeNull(); | ||
_clone.MoleculeBlock.ShouldNotBeNull(); | ||
|
||
_clone.MoleculeStartValueBlockCollection.ShouldNotBeEmpty(); | ||
_clone.ParametersStartValueBlockCollection.ShouldNotBeNull(); | ||
|
||
} | ||
} | ||
|
||
public class When_the_extension_module_is_cloned : When_the_module_is_cloned<ExtensionModule> | ||
{ | ||
|
||
} | ||
|
||
public class When_the_pksim_module_is_cloned : When_the_module_is_cloned<PKSimModule> | ||
{ | ||
protected override void Context() | ||
{ | ||
base.Context(); | ||
sut.PKSimVersion = "PKSimVersion"; | ||
} | ||
|
||
[Observation] | ||
public void should_have_created_a_clone_with_the_same_PKSimVersion() | ||
{ | ||
_clone.PKSimVersion.ShouldBeEqualTo("PKSimVersion"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters