Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1884 Create domain object for Module #1885

Merged
merged 5 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/OSPSuite.Core/Domain/BaseModule.cs
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
rwmcintosh marked this conversation as resolved.
Show resolved Hide resolved
{
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);
rwmcintosh marked this conversation as resolved.
Show resolved Hide resolved
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;
rwmcintosh marked this conversation as resolved.
Show resolved Hide resolved
}

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;
}
}
}
6 changes: 1 addition & 5 deletions src/OSPSuite.Core/Domain/Project.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Utility.Collections;
Expand Down Expand Up @@ -47,11 +48,6 @@ public virtual void AddObservedData(DataRepository dataRepositoryToAdd)
_allObservedData.Add(dataRepositoryToAdd);
}

public virtual void AddOImporterConfiguration(ImporterConfiguration importerConfiguration)
{
_allImporterConfigurations.Add(importerConfiguration);
}

public virtual void RemoveObservedData(DataRepository dataRepositoryToRemove)
{
_allObservedData.Remove(dataRepositoryToRemove.Id);
Expand Down
84 changes: 84 additions & 0 deletions tests/OSPSuite.Core.Tests/Domain/ModuleSpecs.cs
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");
}
}
}
44 changes: 42 additions & 2 deletions tests/OSPSuite.HelpersForTests/ModelHelperForSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,8 @@ public T CreateObjectBaseFrom<T>(T sourceObject)
if (sourceObject.IsAnImplementationOf<IParameter>())
return new Parameter().WithId(id).WithDimension(_dimensionFactory.NoDimension).DowncastTo<T>();

if (sourceObject.IsAnImplementationOf<SpatialStructure>())
return new SpatialStructure().WithId(id).DowncastTo<T>();
if (sourceObject.IsAnImplementationOf<BuildingBlock>())
return newBuildingBlockWithId(sourceObject as BuildingBlock, id).DowncastTo<T>();

if (sourceObject.IsAnImplementationOf<ConstantFormula>())
return new ConstantFormula().WithDimension(_dimensionFactory.NoDimension).WithId(id).DowncastTo<T>();
Expand All @@ -1180,9 +1180,49 @@ public T CreateObjectBaseFrom<T>(T sourceObject)
if (sourceObject.IsAnImplementationOf<IndividualParameter>())
return new IndividualParameter().WithDimension(_dimensionFactory.NoDimension).WithId(id).DowncastTo<T>();

if (sourceObject.IsAnImplementationOf<PKSimModule>())
return new PKSimModule().WithId(id).DowncastTo<T>();

if (sourceObject.IsAnImplementationOf<ExtensionModule>())
return new ExtensionModule().WithId(id).DowncastTo<T>();

return default(T);
}

private T newBuildingBlockWithId<T>(T sourceObject, string id) where T: BuildingBlock
{
BuildingBlock bb = default(T);
if (sourceObject.IsAnImplementationOf<SpatialStructure>())
bb = new SpatialStructure();

if (sourceObject.IsAnImplementationOf<MoleculeBuildingBlock>())
bb = new MoleculeBuildingBlock();

if (sourceObject.IsAnImplementationOf<ReactionBuildingBlock>())
bb = new ReactionBuildingBlock();

if (sourceObject.IsAnImplementationOf<PassiveTransportBuildingBlock>())
bb = new PassiveTransportBuildingBlock();

if (sourceObject.IsAnImplementationOf<ObserverBuildingBlock>())
bb = new ObserverBuildingBlock();

if (sourceObject.IsAnImplementationOf<EventGroupBuildingBlock>())
bb = new EventGroupBuildingBlock();

if (sourceObject.IsAnImplementationOf<MoleculeStartValuesBuildingBlock>())
bb = new MoleculeStartValuesBuildingBlock();

if (sourceObject.IsAnImplementationOf<ParameterStartValuesBuildingBlock>())
bb = new ParameterStartValuesBuildingBlock();

if (bb != null)
return bb.WithId(id).DowncastTo<T>();

return null;
}


public T Create<T>(string id) where T : class, IObjectBase
{
throw new NotSupportedException();
Expand Down