From 958e6880c863b612094b3b628d7bff4137deb8ea Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Fri, 17 Feb 2023 16:00:45 +0100 Subject: [PATCH] =?UTF-8?q?Remove=20interface=20for=20object=20path=20maki?= =?UTF-8?q?ng=20stuff=20just=20too=20complicated=20fo=E2=80=A6=20(#1905)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove interface for object path making stuff just too complicated for nothing * Fixing tests * Fixes #1904 parent --- .../Builder/ApplicationMoleculeBuilder.cs | 6 +- .../Domain/Builder/EventAssignmentBuilder.cs | 6 +- src/OSPSuite.Core/Domain/Builder/IWithPath.cs | 4 +- .../Domain/Builder/PathAndValueEntity.cs | 14 +- .../PathAndValueEntityBuildingBlock.cs | 6 +- .../Domain/Builder/StartValueBuildingBlock.cs | 6 +- src/OSPSuite.Core/Domain/Container.cs | 30 ++-- src/OSPSuite.Core/Domain/EventAssignment.cs | 4 +- src/OSPSuite.Core/Domain/Exceptions.cs | 2 +- src/OSPSuite.Core/Domain/FormulaUsablePath.cs | 14 +- .../Domain/FormulaUsablePathExtensions.cs | 2 +- src/OSPSuite.Core/Domain/Formulas/Formula.cs | 16 +- .../Domain/Formulas/FormulaExtensions.cs | 2 +- .../Domain/Formulas/FormulaFactory.cs | 2 +- .../Formulas/TableFormulaWithOffset .cs | 4 +- .../Formulas/TableFormulaWithXArgument.cs | 4 +- .../Domain/KeywordReplacerCollection.cs | 4 +- ...ssignmentBuilderToEventAssignmentMapper.cs | 2 +- ...QuantityPathToQuantityDisplayPathMapper.cs | 2 +- .../Mappers/ProcessRateParameterCreator.cs | 2 +- src/OSPSuite.Core/Domain/ObjectPath.cs | 159 +++++++----------- .../Domain/ObjectPathExtensions.cs | 12 +- src/OSPSuite.Core/Domain/ObjectPathFactory.cs | 32 ++-- .../Domain/QuantityAndContainer.cs | 6 + .../Domain/Repositories/FavoriteRepository.cs | 2 +- .../Repositories/IFavoriteRepository.cs | 2 +- .../Domain/Services/EntityPathResolver.cs | 8 +- .../Domain/Services/FormulaTask.cs | 8 +- .../Domain/Services/IKeywordReplacer.cs | 2 +- .../Domain/Services/KeywordReplacerTask.cs | 6 +- .../Services/KeywordWithPathReplacer.cs | 2 +- .../Domain/Services/ModelFinalizer.cs | 12 +- .../Domain/Services/ModelValidator.cs | 2 +- .../Services/MoleculeStartValuesCreator.cs | 4 +- .../Services/ParameterStartValuesCreator.cs | 12 +- .../Domain/Services/SimpleKeywordReplacer.cs | 2 +- .../Services/TopContainerPathReplacer.cs | 2 +- src/OSPSuite.Core/Domain/TimePath.cs | 39 ++--- .../Xml/ContainerXmlSerializer.cs | 1 + .../Xml/ObjectPathXmlSerializer.cs | 2 +- .../Services/CircularReferenceChecker.cs | 4 +- .../FormulaUsablePathsTeXBuilder.cs | 8 +- .../Mappers/DiffItemToDiffItemDTOMapper.cs | 2 +- .../Helpers/AssertForSpecs.cs | 13 +- .../ContainerXmlSerializerSpecs.cs | 13 +- .../EventBuilderXmlSerializerSpecs.cs | 2 +- .../FormulaCacheXmlSerializerSpecs.cs | 2 +- .../MoleculeBuilderXmlSerializerSpecs.cs | 5 +- .../ObserverBuilderXmlSerializerSpecs.cs | 2 +- .../ParameterBuilderXmlSerializerSpecs.cs | 2 +- .../ProcessBuilderXmlSerializerSpecs.cs | 2 +- .../Domain/ContainerSpecs.cs | 21 ++- .../Domain/ExplicitFormulaSpecs.cs | 12 +- .../FormulaUsablePathExtensionsSpecs.cs | 4 +- .../Domain/FormulaUsablePathSpecs.cs | 22 +-- .../Domain/KeywordReplacerCollectionSpecs.cs | 4 +- .../Domain/KeywordReplacerTaskSpecs.cs | 6 +- .../Domain/ObjectPathExtensionsSpecs.cs | 4 +- .../Domain/ObjectPathFactorySpecs.cs | 12 +- .../Domain/ObjectPathSpecs.cs | 2 +- .../Domain/ParameterStartValueSpecs.cs | 2 +- .../ProcessRateParameterCreatorSpecs.cs | 6 +- .../Domain/TimePathSpecs.cs | 4 +- ...borhoodBuilderToNeighborhoodMapperSpecs.cs | 57 +++---- .../Services/CircularReferenceCheckerSpecs.cs | 14 +- .../Services/KeywordWithPathReplacerSpecs.cs | 8 +- ...dentificationSimulationPathUpdaterSpecs.cs | 2 +- .../Services/SimpleKeywordReplacerSpecs.cs | 8 +- .../Services/TopContainerPathReplacerSpecs.cs | 6 +- 69 files changed, 342 insertions(+), 354 deletions(-) diff --git a/src/OSPSuite.Core/Domain/Builder/ApplicationMoleculeBuilder.cs b/src/OSPSuite.Core/Domain/Builder/ApplicationMoleculeBuilder.cs index caf7511eb..6c176fafe 100644 --- a/src/OSPSuite.Core/Domain/Builder/ApplicationMoleculeBuilder.cs +++ b/src/OSPSuite.Core/Domain/Builder/ApplicationMoleculeBuilder.cs @@ -17,12 +17,12 @@ public interface IApplicationMoleculeBuilder : IUsingFormula /// /// Must be defined relative to the root container of the application /// - IObjectPath RelativeContainerPath { get; set; } + ObjectPath RelativeContainerPath { get; set; } } public class ApplicationMoleculeBuilder : Entity, IApplicationMoleculeBuilder { - public IObjectPath RelativeContainerPath { get; set; } + public ObjectPath RelativeContainerPath { get; set; } public IFormula Formula { get; set; } public IDimension Dimension { get; set; } @@ -33,7 +33,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone var srcAppMoleculeBuilder = source as IApplicationMoleculeBuilder; if (srcAppMoleculeBuilder == null) return; - RelativeContainerPath = srcAppMoleculeBuilder.RelativeContainerPath.Clone(); + RelativeContainerPath = srcAppMoleculeBuilder.RelativeContainerPath.Clone(); Formula = cloneManager.Clone(srcAppMoleculeBuilder.Formula); Dimension = srcAppMoleculeBuilder.Dimension; } diff --git a/src/OSPSuite.Core/Domain/Builder/EventAssignmentBuilder.cs b/src/OSPSuite.Core/Domain/Builder/EventAssignmentBuilder.cs index 5e77f127c..1aa9e3bbd 100644 --- a/src/OSPSuite.Core/Domain/Builder/EventAssignmentBuilder.cs +++ b/src/OSPSuite.Core/Domain/Builder/EventAssignmentBuilder.cs @@ -9,7 +9,7 @@ public interface IAssignment : IUsingFormula /// /// Path to IUsingFormulaEntity object, whose formula will be changed /// - IObjectPath ObjectPath { get; set; } + ObjectPath ObjectPath { get; set; } /// /// Defines whether the formula itself or the VALUE of the formula @@ -28,7 +28,7 @@ public interface IEventAssignmentBuilder : IAssignment public class EventAssignmentBuilder : Entity, IEventAssignmentBuilder { - public IObjectPath ObjectPath { get; set; } + public ObjectPath ObjectPath { get; set; } /// /// New formula to be set when event fires @@ -48,7 +48,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone UseAsValue = srcEventAssignmentBuilder.UseAsValue; Dimension = srcEventAssignmentBuilder.Dimension; - ObjectPath = srcEventAssignmentBuilder.ObjectPath.Clone(); + ObjectPath = srcEventAssignmentBuilder.ObjectPath.Clone(); } } } \ No newline at end of file diff --git a/src/OSPSuite.Core/Domain/Builder/IWithPath.cs b/src/OSPSuite.Core/Domain/Builder/IWithPath.cs index 575bf95c3..02d0b6d5d 100644 --- a/src/OSPSuite.Core/Domain/Builder/IWithPath.cs +++ b/src/OSPSuite.Core/Domain/Builder/IWithPath.cs @@ -2,7 +2,7 @@ { public interface IWithPath { - IObjectPath Path { get; set; } - IObjectPath ContainerPath { get; set; } + ObjectPath Path { get; set; } + ObjectPath ContainerPath { get; set; } } } \ No newline at end of file diff --git a/src/OSPSuite.Core/Domain/Builder/PathAndValueEntity.cs b/src/OSPSuite.Core/Domain/Builder/PathAndValueEntity.cs index 0698f7438..a553f4980 100644 --- a/src/OSPSuite.Core/Domain/Builder/PathAndValueEntity.cs +++ b/src/OSPSuite.Core/Domain/Builder/PathAndValueEntity.cs @@ -8,7 +8,7 @@ namespace OSPSuite.Core.Domain.Builder { public abstract class PathAndValueEntity : Entity, IUsingFormula, IWithDisplayUnit, IWithPath, IWithNullableValue { - private IObjectPath _containerPath; + private ObjectPath _containerPath; protected IFormula _formula; private Unit _displayUnit; private IDimension _dimension; @@ -22,12 +22,12 @@ protected PathAndValueEntity() ValueOrigin = new ValueOrigin(); } - private void entityFullPathToComponents(IObjectPath fullPath) + private void entityFullPathToComponents(ObjectPath fullPath) { if (fullPath.Any()) { Name = fullPath.Last(); - ContainerPath = fullPath.Clone(); + ContainerPath = fullPath.Clone(); if (ContainerPath.Count > 0) ContainerPath.RemoveAt(ContainerPath.Count - 1); } @@ -38,7 +38,7 @@ private void entityFullPathToComponents(IObjectPath fullPath) } } - public IObjectPath ContainerPath + public ObjectPath ContainerPath { get => _containerPath; set => SetProperty(ref _containerPath, value); @@ -63,9 +63,9 @@ public Unit DisplayUnit } - public IObjectPath Path + public ObjectPath Path { - get => ContainerPath.Clone().AndAdd(Name); + get => ContainerPath.Clone().AndAdd(Name); set => entityFullPathToComponents(value); } @@ -131,7 +131,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone if (sourcePathAndValueEntity == null) return; Value = sourcePathAndValueEntity.Value; - ContainerPath = sourcePathAndValueEntity.ContainerPath.Clone(); + ContainerPath = sourcePathAndValueEntity.ContainerPath.Clone(); DisplayUnit = sourcePathAndValueEntity.DisplayUnit; Dimension = sourcePathAndValueEntity.Dimension; Formula = cloneManager.Clone(sourcePathAndValueEntity.Formula); diff --git a/src/OSPSuite.Core/Domain/Builder/PathAndValueEntityBuildingBlock.cs b/src/OSPSuite.Core/Domain/Builder/PathAndValueEntityBuildingBlock.cs index c708d6ee5..66c11d1c6 100644 --- a/src/OSPSuite.Core/Domain/Builder/PathAndValueEntityBuildingBlock.cs +++ b/src/OSPSuite.Core/Domain/Builder/PathAndValueEntityBuildingBlock.cs @@ -8,9 +8,9 @@ namespace OSPSuite.Core.Domain.Builder { public abstract class PathAndValueEntityBuildingBlock : BuildingBlock, IBuildingBlock where T: class, IWithPath, IObjectBase { - protected ICache _allValues = new Cache(x => x.Path, x => null); + protected ICache _allValues = new Cache(x => x.Path, x => null); - public T this[IObjectPath objectPath] + public T this[ObjectPath objectPath] { get => _allValues[objectPath]; set => _allValues[objectPath] = value; @@ -29,7 +29,7 @@ public void Remove(T startValue) } - public void Remove(IObjectPath objectPath) + public void Remove(ObjectPath objectPath) { Remove(this[objectPath]); } diff --git a/src/OSPSuite.Core/Domain/Builder/StartValueBuildingBlock.cs b/src/OSPSuite.Core/Domain/Builder/StartValueBuildingBlock.cs index d6e138907..afbf16de6 100644 --- a/src/OSPSuite.Core/Domain/Builder/StartValueBuildingBlock.cs +++ b/src/OSPSuite.Core/Domain/Builder/StartValueBuildingBlock.cs @@ -12,7 +12,7 @@ public interface IStartValuesBuildingBlock : IBuildingBlock where T : clas /// /// /// - T this[IObjectPath objectPath] { get; set; } + T this[ObjectPath objectPath] { get; set; } /// /// Id of the spatial structure used to create the parameter start values. @@ -34,7 +34,7 @@ public interface IStartValuesBuildingBlock : IBuildingBlock where T : clas /// /// Removes the start value with path if available. Does nothing otherwise /// - void Remove(IObjectPath objectPath); + void Remove(ObjectPath objectPath); } public abstract class StartValueBuildingBlock : PathAndValueEntityBuildingBlock, IStartValuesBuildingBlock where T : class, IStartValue @@ -55,7 +55,7 @@ private bool refersTo(IBuildingBlock buildingBlock, string idToCheck) protected StartValueBuildingBlock() { - _allValues = new Cache(x => x.Path, x => null); + _allValues = new Cache(x => x.Path, x => null); } public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager) diff --git a/src/OSPSuite.Core/Domain/Container.cs b/src/OSPSuite.Core/Domain/Container.cs index c8cad2a96..438d780ef 100644 --- a/src/OSPSuite.Core/Domain/Container.cs +++ b/src/OSPSuite.Core/Domain/Container.cs @@ -24,6 +24,11 @@ public interface IContainer : IEntity, IEnumerable /// IReadOnlyList Children { get; } + /// + /// Returns the path to the parent container. + /// It should only be set if the container has no parent in the hierarchy. Otherwise, it will be null + /// + ObjectPath ParentPath { get; set; } /// /// Add the given child to the container @@ -92,15 +97,14 @@ public interface IContainer : IEntity, IEnumerable public class Container : Entity, IContainer { - private readonly List _children; - private ContainerMode _mode; + private readonly List _children = new List(); + + private ContainerMode _mode = ContainerMode.Logical; + private ContainerType _containerType; - public Container() - { - _children = new List(); - Mode = ContainerMode.Logical; - } + //Path to parent container is null by default. In this case, it will be evaluated from container structure + private ObjectPath _parentPath; public virtual IReadOnlyList Children => _children; @@ -137,6 +141,12 @@ public ContainerMode Mode set => SetProperty(ref _mode, value); } + public ObjectPath ParentPath + { + get => _parentPath; + set => SetProperty(ref _parentPath, value); + } + public ContainerType ContainerType { get => _containerType; @@ -190,10 +200,7 @@ public override void AcceptVisitor(IVisitor visitor) /// /// Returns all children of type /// - public virtual IEnumerable GetChildren() where T : class, IEntity - { - return GetChildren(x => true); - } + public virtual IEnumerable GetChildren() where T : class, IEntity => GetChildren(x => true); public virtual IEnumerable GetChildren(Func predicate) where T : class, IEntity { @@ -250,6 +257,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone Mode = container.Mode; ContainerType = container.ContainerType; + ParentPath = container.ParentPath?.Clone(); } public IEnumerator GetEnumerator() diff --git a/src/OSPSuite.Core/Domain/EventAssignment.cs b/src/OSPSuite.Core/Domain/EventAssignment.cs index 015f06dc1..c84174d16 100644 --- a/src/OSPSuite.Core/Domain/EventAssignment.cs +++ b/src/OSPSuite.Core/Domain/EventAssignment.cs @@ -31,7 +31,7 @@ public class EventAssignment : Entity, IEventAssignment /// /// Path to IUsingFormulaEntity object, whose formula will be changed /// - public IObjectPath ObjectPath { get; set; } + public ObjectPath ObjectPath { get; set; } /// /// Defines whether the formula itself or the VALUE of the formula @@ -54,7 +54,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone var sourceEventAssignment = source as IEventAssignment; if (sourceEventAssignment == null) return; UseAsValue = sourceEventAssignment.UseAsValue; - ObjectPath = sourceEventAssignment.ObjectPath.Clone(); + ObjectPath = sourceEventAssignment.ObjectPath.Clone(); Dimension = sourceEventAssignment.Dimension; } } diff --git a/src/OSPSuite.Core/Domain/Exceptions.cs b/src/OSPSuite.Core/Domain/Exceptions.cs index e5c0f2393..636d6a99e 100644 --- a/src/OSPSuite.Core/Domain/Exceptions.cs +++ b/src/OSPSuite.Core/Domain/Exceptions.cs @@ -128,7 +128,7 @@ public MissingMoleculeAmountException(string containerName, string moleculeName) public class UnableToResolvePathException : OSPSuiteException { - public UnableToResolvePathException(IObjectPath objectPath, IEntity currentEntity) + public UnableToResolvePathException(ObjectPath objectPath, IEntity currentEntity) : base($"Unable to resolve path '{objectPath}' for entity '{currentEntity.Name}' with path '{currentEntity.EntityPath()}'") { diff --git a/src/OSPSuite.Core/Domain/FormulaUsablePath.cs b/src/OSPSuite.Core/Domain/FormulaUsablePath.cs index c3a35d543..7778d04a5 100644 --- a/src/OSPSuite.Core/Domain/FormulaUsablePath.cs +++ b/src/OSPSuite.Core/Domain/FormulaUsablePath.cs @@ -1,23 +1,23 @@ using System.Collections.Generic; +using System.Linq; using OSPSuite.Core.Domain.UnitSystem; using OSPSuite.Utility.Extensions; namespace OSPSuite.Core.Domain { - public interface IFormulaUsablePath : IWithDimension, IObjectPath - { - string Alias { get; set; } - } - - public class FormulaUsablePath : ObjectPath, IFormulaUsablePath + public class FormulaUsablePath : ObjectPath, IWithDimension { public string Alias { get; set; } - public IDimension Dimension { get; set; } + public virtual IDimension Dimension { get; set; } public FormulaUsablePath() { } + public FormulaUsablePath(FormulaUsablePath from) : base(from._pathEntries) + { + } + public FormulaUsablePath(params string[] pathEntries) : base(pathEntries) { } diff --git a/src/OSPSuite.Core/Domain/FormulaUsablePathExtensions.cs b/src/OSPSuite.Core/Domain/FormulaUsablePathExtensions.cs index f51f4c1a8..81107f53c 100644 --- a/src/OSPSuite.Core/Domain/FormulaUsablePathExtensions.cs +++ b/src/OSPSuite.Core/Domain/FormulaUsablePathExtensions.cs @@ -2,7 +2,7 @@ namespace OSPSuite.Core.Domain { public static class FormulaUsablePathExtensions { - public static TObjectPath WithAlias(this TObjectPath objectPath,string alias) where TObjectPath:IFormulaUsablePath + public static TObjectPath WithAlias(this TObjectPath objectPath, string alias) where TObjectPath : FormulaUsablePath { objectPath.Alias = alias; return objectPath; diff --git a/src/OSPSuite.Core/Domain/Formulas/Formula.cs b/src/OSPSuite.Core/Domain/Formulas/Formula.cs index 2f6f2927b..b793630d3 100644 --- a/src/OSPSuite.Core/Domain/Formulas/Formula.cs +++ b/src/OSPSuite.Core/Domain/Formulas/Formula.cs @@ -20,7 +20,7 @@ public interface IFormula : IObjectBase, IWithDimension /// Object path to IFormulaUsable-entities used in current formula /// /// - IReadOnlyList ObjectPaths { get; } + IReadOnlyList ObjectPaths { get; } /// /// Concrete IFormulaUsable-entities used by current formula @@ -61,13 +61,13 @@ public interface IFormula : IObjectBase, IWithDimension /// Adds a new path reference to the Formulas. /// /// The new reference. - void AddObjectPath(IFormulaUsablePath newPath); + void AddObjectPath(FormulaUsablePath newPath); /// /// Removes the specified path reference from formula. /// /// The reference to remove. - void RemoveObjectPath(IFormulaUsablePath pathToRemove); + void RemoveObjectPath(FormulaUsablePath pathToRemove); /// /// Removes all object paths defined in the formula @@ -78,7 +78,7 @@ public interface IFormula : IObjectBase, IWithDimension public abstract class Formula : ObjectBase, IFormula { private readonly List _objectReferences = new List(); - private List _objectPaths = new List(); + private List _objectPaths = new List(); public virtual IDimension Dimension { get; set; } = Constants.Dimension.NO_DIMENSION; public virtual IReadOnlyList ObjectReferences => _objectReferences; @@ -113,7 +113,7 @@ private void onReferencePropertyChanged(object sender, PropertyChangedEventArgs } } - public virtual IReadOnlyList ObjectPaths + public virtual IReadOnlyList ObjectPaths { get => _objectPaths; set @@ -137,7 +137,7 @@ private void checkAliases(IEnumerable aliases) /// Adds a new reference to the Formulas. /// /// The new reference. - public virtual void AddObjectPath(IFormulaUsablePath newPath) + public virtual void AddObjectPath(FormulaUsablePath newPath) { _objectPaths.Add(newPath); } @@ -146,7 +146,7 @@ public virtual void AddObjectPath(IFormulaUsablePath newPath) /// Removes the specified reference from formula. /// /// The reference to remove. - public virtual void RemoveObjectPath(IFormulaUsablePath pathToRemove) + public virtual void RemoveObjectPath(FormulaUsablePath pathToRemove) { _objectPaths.Remove(pathToRemove); } @@ -164,7 +164,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone var srcFormula = source as Formula; if (srcFormula == null) return; - srcFormula.ObjectPaths.Each(path => _objectPaths.Add(path.Clone())); + srcFormula.ObjectPaths.Each(path => _objectPaths.Add(path.Clone())); Dimension = srcFormula.Dimension; } diff --git a/src/OSPSuite.Core/Domain/Formulas/FormulaExtensions.cs b/src/OSPSuite.Core/Domain/Formulas/FormulaExtensions.cs index 1f14a2762..bd3dcb278 100644 --- a/src/OSPSuite.Core/Domain/Formulas/FormulaExtensions.cs +++ b/src/OSPSuite.Core/Domain/Formulas/FormulaExtensions.cs @@ -95,7 +95,7 @@ public static bool IsCachable(this IFormula formula) /// Returns the used object path with the given in the or null if /// the is not used. /// - public static IFormulaUsablePath FormulaUsablePathBy(this IFormula formula, string alias) + public static FormulaUsablePath FormulaUsablePathBy(this IFormula formula, string alias) { return formula.ObjectPaths.FirstOrDefault(x => string.Equals(x.Alias, alias)); } diff --git a/src/OSPSuite.Core/Domain/Formulas/FormulaFactory.cs b/src/OSPSuite.Core/Domain/Formulas/FormulaFactory.cs index 91c9fdca1..7433b1d66 100644 --- a/src/OSPSuite.Core/Domain/Formulas/FormulaFactory.cs +++ b/src/OSPSuite.Core/Domain/Formulas/FormulaFactory.cs @@ -101,7 +101,7 @@ private ExplicitFormula createReferenceStartValueFormula(string formulaString, s .WithFormulaString(formulaString); } - private IFormulaUsablePath createVolumeReferencePath(params string[] pathToVolumeParameter) + private FormulaUsablePath createVolumeReferencePath(params string[] pathToVolumeParameter) { return _objectPathFactory.CreateFormulaUsablePathFrom(pathToVolumeParameter) .WithAlias(Constants.VOLUME_ALIAS) diff --git a/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithOffset .cs b/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithOffset .cs index 3f67a0b8e..eb9a8c5c3 100644 --- a/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithOffset .cs +++ b/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithOffset .cs @@ -21,7 +21,7 @@ public class TableFormulaWithOffset : Formula /// Add path to the object with table formula /// /// - public void AddTableObjectPath(IFormulaUsablePath tableObjectPath) + public void AddTableObjectPath(FormulaUsablePath tableObjectPath) { TableObjectAlias = tableObjectPath.Alias; AddObjectPath(tableObjectPath); @@ -31,7 +31,7 @@ public void AddTableObjectPath(IFormulaUsablePath tableObjectPath) /// Add path to the object with offset formula /// /// - public void AddOffsetObjectPath(IFormulaUsablePath offsetObjectPath) + public void AddOffsetObjectPath(FormulaUsablePath offsetObjectPath) { OffsetObjectAlias = offsetObjectPath.Alias; AddObjectPath(offsetObjectPath); diff --git a/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithXArgument.cs b/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithXArgument.cs index 64ae81076..56b618d55 100644 --- a/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithXArgument.cs +++ b/src/OSPSuite.Core/Domain/Formulas/TableFormulaWithXArgument.cs @@ -13,7 +13,7 @@ public class TableFormulaWithXArgument : Formula /// /// Adds path to the object with table formula /// - public void AddTableObjectPath(IFormulaUsablePath tableObjectPath) + public void AddTableObjectPath(FormulaUsablePath tableObjectPath) { TableObjectAlias = tableObjectPath.Alias; AddObjectPath(tableObjectPath); @@ -22,7 +22,7 @@ public void AddTableObjectPath(IFormulaUsablePath tableObjectPath) /// /// Adds path to the object with x-argument /// - public void AddXArgumentObjectPath(IFormulaUsablePath xArgumentObjectPath) + public void AddXArgumentObjectPath(FormulaUsablePath xArgumentObjectPath) { XArgumentAlias = xArgumentObjectPath.Alias; AddObjectPath(xArgumentObjectPath); diff --git a/src/OSPSuite.Core/Domain/KeywordReplacerCollection.cs b/src/OSPSuite.Core/Domain/KeywordReplacerCollection.cs index 773fadfed..d2b6e6a1e 100644 --- a/src/OSPSuite.Core/Domain/KeywordReplacerCollection.cs +++ b/src/OSPSuite.Core/Domain/KeywordReplacerCollection.cs @@ -14,7 +14,7 @@ public interface IKeywordReplacerCollection : IEnumerable /// formula. For formula, used ReplaceReferences Returns true if the object path was changed otherwise false /// /// - void ReplaceIn(IObjectPath objectPath); + void ReplaceIn(ObjectPath objectPath); /// /// Adds the replacement. @@ -105,7 +105,7 @@ private void replaceInDynamicFormula(DynamicFormula dynamicFormula) dynamicFormula?.Criteria.Each(ReplaceIn); } - public void ReplaceIn(IObjectPath objectPath) + public void ReplaceIn(ObjectPath objectPath) { _allObjectPathReplacer.Each(r => r.ReplaceIn(objectPath)); } diff --git a/src/OSPSuite.Core/Domain/Mappers/EventAssignmentBuilderToEventAssignmentMapper.cs b/src/OSPSuite.Core/Domain/Mappers/EventAssignmentBuilderToEventAssignmentMapper.cs index 70ae0cf9b..dc78a0d98 100644 --- a/src/OSPSuite.Core/Domain/Mappers/EventAssignmentBuilderToEventAssignmentMapper.cs +++ b/src/OSPSuite.Core/Domain/Mappers/EventAssignmentBuilderToEventAssignmentMapper.cs @@ -49,7 +49,7 @@ private IEventAssignment createAssignment(IEventAssignmentBuilder assignmentBuil .WithDimension(assignmentBuilder.Dimension) .WithFormula(_formulaMapper.MapFrom(assignmentBuilder.Formula, buildConfiguration)); - assignment.ObjectPath = assignmentBuilder.ObjectPath.Clone(); + assignment.ObjectPath = assignmentBuilder.ObjectPath.Clone(); assignment.UseAsValue = assignmentBuilder.UseAsValue; buildConfiguration.AddBuilderReference(assignment, assignmentBuilder); diff --git a/src/OSPSuite.Core/Domain/Mappers/IQuantityPathToQuantityDisplayPathMapper.cs b/src/OSPSuite.Core/Domain/Mappers/IQuantityPathToQuantityDisplayPathMapper.cs index 01c2ce63f..5fea2cb5c 100644 --- a/src/OSPSuite.Core/Domain/Mappers/IQuantityPathToQuantityDisplayPathMapper.cs +++ b/src/OSPSuite.Core/Domain/Mappers/IQuantityPathToQuantityDisplayPathMapper.cs @@ -83,7 +83,7 @@ private PathElements displayPathForColumn(DataColumn column, ISimulation simulat return _dataColumnToPathElementsMapper.MapFrom(column, simulation?.Model.Root); } - private PathElements displayPathForQuantity(IContainer rootContainer, IObjectPath objectPath) + private PathElements displayPathForQuantity(IContainer rootContainer, ObjectPath objectPath) { return _pathToPathElementsMapper.MapFrom(rootContainer, objectPath.ToList()); } diff --git a/src/OSPSuite.Core/Domain/Mappers/ProcessRateParameterCreator.cs b/src/OSPSuite.Core/Domain/Mappers/ProcessRateParameterCreator.cs index 3b97e279a..85cef6017 100644 --- a/src/OSPSuite.Core/Domain/Mappers/ProcessRateParameterCreator.cs +++ b/src/OSPSuite.Core/Domain/Mappers/ProcessRateParameterCreator.cs @@ -54,7 +54,7 @@ private void addAdditionalParentReference(IFormula formula) } } - private bool isRelativePath(IObjectPath objectPath) + private bool isRelativePath(ObjectPath objectPath) { if (!objectPath.Any()) return false; diff --git a/src/OSPSuite.Core/Domain/ObjectPath.cs b/src/OSPSuite.Core/Domain/ObjectPath.cs index 283c10b42..97a341548 100644 --- a/src/OSPSuite.Core/Domain/ObjectPath.cs +++ b/src/OSPSuite.Core/Domain/ObjectPath.cs @@ -7,85 +7,7 @@ namespace OSPSuite.Core.Domain { - public interface IObjectPath : IReadOnlyCollection - { - /// - /// Single string describing the path - /// - string PathAsString { get; } - - /// - /// Add one entry at the end of the path - /// - /// path entry to add - void Add(string pathEntry); - - /// - /// Add one entry at the front of the path - /// - /// path entry to add - void AddAtFront(string pathEntry); - - /// - /// Replace the first matching path entry with the given replacement if the entry is used in the current path - /// - /// path entry to be replaced - /// replacements for the path entry - void Replace(string entry, string replacement); - - /// - /// Replace the first matching path entry with the given replacements if the entry is used in the current path - /// returns true if a replacement was performed otherwise false - /// - /// path entry to be replaced - /// list of replacements for the path entry - void Replace(string entry, IEnumerable replacements); - - /// - /// Removes the first occurrence of specified . - /// - /// The entry to be removed. - void Remove(string entry); - - /// - /// Returns the entity of type with the given path relative to the - /// - /// - /// - /// is thrown if object could not be retrieve or if the specified type does not match the - /// retrieved type - /// - T Resolve(IEntity refEntity) where T : class; - - T Clone() where T : IObjectPath; - - /// - /// Gets or set the item at the given index (Should be used for replace only) - /// Throws an exception if the index is bigger than the actual size of the path - /// - string this[int index] { get; set; } - - /// - /// Remove the path element defined at the given index. - /// Throws an exception if the index is bigger than the actual size of the path - /// - /// The zero-based index of the item to remove - void RemoveAt(int index); - - /// - /// Removes the first element. This is equivalent to RemoveAt(0). - /// Throws an exception if the path does not contain any element - /// - void RemoveFirst(); - - /// - /// Replaces the path with the path entries in - /// - /// Path entries used to replace the path - void ReplaceWith(IEnumerable pathEntries); - } - - public class ObjectPath : IObjectPath + public class ObjectPath : IReadOnlyCollection { /// /// String indicating that the referenced objectBase is located in a @@ -100,7 +22,7 @@ public class ObjectPath : IObjectPath protected readonly List _pathEntries; - public static IObjectPath Empty { get; } = new ObjectPath(); + public static ObjectPath Empty { get; } = new ObjectPath(); public ObjectPath() : this(new List()) { @@ -115,6 +37,9 @@ public ObjectPath(IEnumerable pathEntries) _pathEntries = pathEntries.ToList(); } + /// + /// Single string describing the path + /// public virtual string PathAsString { get @@ -133,12 +58,21 @@ public virtual string PathAsString } } - public void Add(string pathEntry) + /// + /// Add one entry at the end of the path + /// + /// path entry to add + public virtual void Add(string pathEntry) { _pathEntries.Add(pathEntry); } - public void Replace(string entry, string replacement) + /// + /// Replace the first matching path entry with the given replacement if the entry is used in the current path + /// + /// path entry to be replaced + /// replacements for the path entry + public virtual void Replace(string entry, string replacement) { int index = _pathEntries.IndexOf(entry); if (index == Constants.NOT_FOUND_INDEX) @@ -147,7 +81,13 @@ public void Replace(string entry, string replacement) _pathEntries[index] = replacement; } - public void Replace(string entry, IEnumerable replacements) + /// + /// Replace the first matching path entry with the given replacements if the entry is used in the current path + /// returns true if a replacement was performed otherwise false + /// + /// path entry to be replaced + /// list of replacements for the path entry + public virtual void Replace(string entry, IEnumerable replacements) { int index = _pathEntries.IndexOf(entry); if (index == Constants.NOT_FOUND_INDEX) @@ -160,11 +100,23 @@ public void Replace(string entry, IEnumerable replacements) } } - public void Remove(string entry) + /// + /// Removes the first occurrence of specified . + /// + /// The entry to be removed. + public virtual void Remove(string entry) { _pathEntries.Remove(entry); } + /// + /// Returns the entity of type with the given path relative to the + /// + /// + /// + /// is thrown if object could not be retrieve or if the specified type does not match the + /// retrieved type + /// public virtual T Resolve(IEntity refEntity) where T : class { if (_pathEntries.Count == 0) @@ -198,28 +150,39 @@ public virtual T Resolve(IEntity refEntity) where T : class return resolvePath(dependentObject, usePath); } - public virtual T Clone() where T : IObjectPath + public virtual T Clone() where T : ObjectPath { return new ObjectPath(_pathEntries).DowncastTo(); } - public string this[int index] + /// + /// Gets or set the item at the given index (Should be used for replace only) + /// Throws an exception if the index is bigger than the actual size of the path + /// + public virtual string this[int index] { get => _pathEntries[index]; set => _pathEntries[index] = value; } - public void RemoveAt(int index) - { - _pathEntries.RemoveAt(index); - } + /// + /// Remove the path element defined at the given index. + /// Throws an exception if the index is bigger than the actual size of the path + /// + /// The zero-based index of the item to remove + public virtual void RemoveAt(int index) => _pathEntries.RemoveAt(index); - public void RemoveFirst() - { - RemoveAt(0); - } + /// + /// Removes the first element. This is equivalent to RemoveAt(0). + /// Throws an exception if the path does not contain any element + /// + public virtual void RemoveFirst() => RemoveAt(0); - public void ReplaceWith(IEnumerable pathEntries) + /// + /// Replaces the path with the path entries in + /// + /// Path entries used to replace the path + public virtual void ReplaceWith(IEnumerable pathEntries) { _pathEntries.Clear(); _pathEntries.AddRange(pathEntries); @@ -235,7 +198,11 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } - public void AddAtFront(string pathEntry) + /// + /// Add one entry at the front of the path + /// + /// path entry to add + public virtual void AddAtFront(string pathEntry) { _pathEntries.Insert(0, pathEntry); } diff --git a/src/OSPSuite.Core/Domain/ObjectPathExtensions.cs b/src/OSPSuite.Core/Domain/ObjectPathExtensions.cs index 9320a6bad..be6742a07 100644 --- a/src/OSPSuite.Core/Domain/ObjectPathExtensions.cs +++ b/src/OSPSuite.Core/Domain/ObjectPathExtensions.cs @@ -4,24 +4,24 @@ namespace OSPSuite.Core.Domain { public static class ObjectPathExtensions { - public static TObjectPath AndAdd(this TObjectPath objectPath, string entryToAdd) where TObjectPath : IObjectPath + public static TObjectPath AndAdd(this TObjectPath objectPath, string entryToAdd) where TObjectPath : ObjectPath { objectPath.Add(entryToAdd); return objectPath; } - public static TObjectPath AndAddAtFront(this TObjectPath objectPath, string entryToAddAtFront) where TObjectPath : IObjectPath + public static TObjectPath AndAddAtFront(this TObjectPath objectPath, string entryToAddAtFront) where TObjectPath : ObjectPath { objectPath.AddAtFront(entryToAddAtFront); return objectPath; } /// - /// Returns the entity of type with the given path relatve to the + /// Returns the entity of type with the given path relative to the /// . /// If the entity could not be resolved, success will be set to false and the returned value is null. /// - public static T TryResolve(this IObjectPath objectPath, IEntity refEntity, out bool success) where T : class + public static T TryResolve(this ObjectPath objectPath, IEntity refEntity, out bool success) where T : class { try { @@ -37,10 +37,10 @@ public static T TryResolve(this IObjectPath objectPath, IEntity refEntity, ou } /// - /// Returns the entity of type with the given path relatve to the + /// Returns the entity of type with the given path relative to the /// . If the entity could not be resolved, returns null /// - public static T TryResolve(this IObjectPath objectPath, IEntity refEntity) where T : class + public static T TryResolve(this ObjectPath objectPath, IEntity refEntity) where T : class { bool isFound; var result = TryResolve(objectPath, refEntity, out isFound); diff --git a/src/OSPSuite.Core/Domain/ObjectPathFactory.cs b/src/OSPSuite.Core/Domain/ObjectPathFactory.cs index ff20395ab..5ebd36091 100644 --- a/src/OSPSuite.Core/Domain/ObjectPathFactory.cs +++ b/src/OSPSuite.Core/Domain/ObjectPathFactory.cs @@ -11,32 +11,32 @@ public interface IObjectPathFactory /// Creates the AbsoluteObjectPath to the specified entity. /// /// The ref entity. - IFormulaUsablePath CreateAbsoluteFormulaUsablePath(IFormulaUsable entity); + FormulaUsablePath CreateAbsoluteFormulaUsablePath(IFormulaUsable entity); /// /// Creates a object path containing the given path entries /// /// entries used to create the path - IFormulaUsablePath CreateFormulaUsablePathFrom(params string[] entries); + FormulaUsablePath CreateFormulaUsablePathFrom(params string[] entries); - IFormulaUsablePath CreateFormulaUsablePathFrom(IEnumerable entries); + FormulaUsablePath CreateFormulaUsablePathFrom(IEnumerable entries); /// /// Creates an object path representing the Time Parameter /// TimePath CreateTimePath(IDimension timeDimension); - IObjectPath CreateObjectPathFrom(params string[] entries); - IObjectPath CreateObjectPathFrom(IEnumerable entries); + ObjectPath CreateObjectPathFrom(params string[] entries); + ObjectPath CreateObjectPathFrom(IEnumerable entries); - IObjectPath CreateAbsoluteObjectPath(IEntity entity); + ObjectPath CreateAbsoluteObjectPath(IEntity entity); /// /// Creates a ObjectPath representing the relative Position of usedObject according to usingObject /// - IObjectPath CreateRelativeObjectPath(IEntity usingObject, IEntity usedObject); + ObjectPath CreateRelativeObjectPath(IEntity usingObject, IEntity usedObject); - IFormulaUsablePath CreateRelativeFormulaUsablePath(IEntity usingObject, IFormulaUsable usedObject); + FormulaUsablePath CreateRelativeFormulaUsablePath(IEntity usingObject, IFormulaUsable usedObject); } public class ObjectPathFactory : IObjectPathFactory @@ -48,7 +48,7 @@ public ObjectPathFactory(IAliasCreator aliasCreator) _aliasCreator = aliasCreator; } - public IFormulaUsablePath CreateAbsoluteFormulaUsablePath(IFormulaUsable entity) + public FormulaUsablePath CreateAbsoluteFormulaUsablePath(IFormulaUsable entity) { var newFormulaUseablePath = new FormulaUsablePath(); addPathEntry(entity, newFormulaUseablePath); @@ -57,7 +57,7 @@ public IFormulaUsablePath CreateAbsoluteFormulaUsablePath(IFormulaUsable entity) return newFormulaUseablePath; } - public IObjectPath CreateAbsoluteObjectPath(IEntity entity) + public ObjectPath CreateAbsoluteObjectPath(IEntity entity) { var newObjectPath = new ObjectPath(); addPathEntry(entity, newObjectPath); @@ -86,12 +86,12 @@ private string createAliasFrom(string name) return _aliasCreator.CreateAliasFrom(name); } - public IFormulaUsablePath CreateFormulaUsablePathFrom(params string[] entries) + public FormulaUsablePath CreateFormulaUsablePathFrom(params string[] entries) { return CreateFormulaUsablePathFrom(entries.AsEnumerable()); } - public IFormulaUsablePath CreateFormulaUsablePathFrom(IEnumerable entries) + public FormulaUsablePath CreateFormulaUsablePathFrom(IEnumerable entries) { var newFormulaUseablePath = new FormulaUsablePath(); entries.Each(newFormulaUseablePath.Add); @@ -99,12 +99,12 @@ public IFormulaUsablePath CreateFormulaUsablePathFrom(IEnumerable entrie return newFormulaUseablePath; } - public IObjectPath CreateObjectPathFrom(params string[] entries) + public ObjectPath CreateObjectPathFrom(params string[] entries) { return CreateObjectPathFrom(entries.AsEnumerable()); } - public IObjectPath CreateObjectPathFrom(IEnumerable entries) + public ObjectPath CreateObjectPathFrom(IEnumerable entries) { var newObjectPath = new ObjectPath(); entries.Each(newObjectPath.Add); @@ -119,14 +119,14 @@ public TimePath CreateTimePath(IDimension timeDimension) /// /// Creates a ObjectPath representing the relative Position of usedObject according to usingObject /// - public IObjectPath CreateRelativeObjectPath(IEntity usingObject, IEntity usedObject) + public ObjectPath CreateRelativeObjectPath(IEntity usingObject, IEntity usedObject) { var objectPath = new ObjectPath(); addRelativePathEntries(usingObject, usedObject, objectPath); return objectPath; } - public IFormulaUsablePath CreateRelativeFormulaUsablePath(IEntity usingObject, IFormulaUsable usedObject) + public FormulaUsablePath CreateRelativeFormulaUsablePath(IEntity usingObject, IFormulaUsable usedObject) { var newFormulaUseablePath = new FormulaUsablePath(); addRelativePathEntries(usingObject, usedObject, newFormulaUseablePath); diff --git a/src/OSPSuite.Core/Domain/QuantityAndContainer.cs b/src/OSPSuite.Core/Domain/QuantityAndContainer.cs index 1ab0ed078..05feb9ac2 100644 --- a/src/OSPSuite.Core/Domain/QuantityAndContainer.cs +++ b/src/OSPSuite.Core/Domain/QuantityAndContainer.cs @@ -34,6 +34,12 @@ public override void AcceptVisitor(IVisitor visitor) public IReadOnlyList Children => _container.Children; + public ObjectPath ParentPath + { + get => _container.ParentPath; + set => _container.ParentPath = value; + } + public ContainerMode Mode { get => _container.Mode; diff --git a/src/OSPSuite.Core/Domain/Repositories/FavoriteRepository.cs b/src/OSPSuite.Core/Domain/Repositories/FavoriteRepository.cs index 235b7fe69..bd32e5ec1 100644 --- a/src/OSPSuite.Core/Domain/Repositories/FavoriteRepository.cs +++ b/src/OSPSuite.Core/Domain/Repositories/FavoriteRepository.cs @@ -32,7 +32,7 @@ public void RemoveFavorite(string parameterPath) Favorites.Remove(parameterPath); } - public bool Contains(IObjectPath parameterPath) + public bool Contains(ObjectPath parameterPath) { return Favorites.Contains(parameterPath.PathAsString); } diff --git a/src/OSPSuite.Core/Domain/Repositories/IFavoriteRepository.cs b/src/OSPSuite.Core/Domain/Repositories/IFavoriteRepository.cs index c0f4ff995..f5621f821 100644 --- a/src/OSPSuite.Core/Domain/Repositories/IFavoriteRepository.cs +++ b/src/OSPSuite.Core/Domain/Repositories/IFavoriteRepository.cs @@ -8,7 +8,7 @@ public interface IFavoriteRepository : IRepository void AddFavorite(string favorite); void AddFavorites(IEnumerable favorites); void RemoveFavorite(string favorite); - bool Contains(IObjectPath parameterPath); + bool Contains(ObjectPath parameterPath); void Clear(); Favorites Favorites { get; } } diff --git a/src/OSPSuite.Core/Domain/Services/EntityPathResolver.cs b/src/OSPSuite.Core/Domain/Services/EntityPathResolver.cs index 929e9f1cf..fd892dfb2 100644 --- a/src/OSPSuite.Core/Domain/Services/EntityPathResolver.cs +++ b/src/OSPSuite.Core/Domain/Services/EntityPathResolver.cs @@ -23,7 +23,7 @@ public interface IEntityPathResolver /// /// Returns a consolidated absolute object path for the given entity /// - IObjectPath ObjectPathFor(IEntity entity, bool addSimulationName = false); + ObjectPath ObjectPathFor(IEntity entity, bool addSimulationName = false); } public class EntityPathResolver : IEntityPathResolver @@ -45,13 +45,13 @@ public string FullPathFor(IEntity entity) return ObjectPathFor(entity, addSimulationName: true).ToString(); } - public virtual IObjectPath ObjectPathFor(IEntity entity, bool addSimulationName = false) + public virtual ObjectPath ObjectPathFor(IEntity entity, bool addSimulationName = false) { var objectPath = _objectPathFactory.CreateAbsoluteObjectPath(entity); return convertedPath(objectPath, entity.RootContainer, addSimulationName); } - private IObjectPath convertedPath(IObjectPath objectPath, IContainer rootContainer, bool addSimulationName) + private ObjectPath convertedPath(ObjectPath objectPath, IContainer rootContainer, bool addSimulationName) { if (!objectPath.Any()) return objectPath; @@ -71,7 +71,7 @@ private IObjectPath convertedPath(IObjectPath objectPath, IContainer rootContain return objectPath; } - private IObjectPath removeFirstEntryOf(IObjectPath objectPath) + private ObjectPath removeFirstEntryOf(ObjectPath objectPath) { objectPath.Remove(objectPath[0]); return objectPath; diff --git a/src/OSPSuite.Core/Domain/Services/FormulaTask.cs b/src/OSPSuite.Core/Domain/Services/FormulaTask.cs index be6ec27c6..8214343b9 100644 --- a/src/OSPSuite.Core/Domain/Services/FormulaTask.cs +++ b/src/OSPSuite.Core/Domain/Services/FormulaTask.cs @@ -127,9 +127,9 @@ public bool FormulasAreTheSame(IFormula firstFormula, IFormula secondFormula) return false; //check that formula have the same references using the same alias - var firstObjectPathCache = new Cache(x => x.Alias); + var firstObjectPathCache = new Cache(x => x.Alias); firstObjectPathCache.AddRange(firstExplicit.ObjectPaths); - var secondObjectPathCache = new Cache(x => x.Alias); + var secondObjectPathCache = new Cache(x => x.Alias); secondObjectPathCache.AddRange(secondExplicit.ObjectPaths); @@ -151,13 +151,13 @@ public bool FormulasAreTheSame(IFormula firstFormula, IFormula secondFormula) public void ExpandNeighborhoodReferencesIn(IModel model) { - void updatePath(IUsingFormula usingFormula, IFormulaUsablePath path) => updateNeighborhoodReferencingPath(model, path, usingFormula); + void updatePath(IUsingFormula usingFormula, FormulaUsablePath path) => updateNeighborhoodReferencingPath(model, path, usingFormula); model.Root.GetAllChildren(x => x.Formula.IsReferencingNeighborhood()) .Each(x => x.Formula.ObjectPaths.Each(path => updatePath(x, path))); } - private void updateNeighborhoodReferencingPath(IModel model, IFormulaUsablePath formulaUsablePath, IUsingFormula usingFormula) + private void updateNeighborhoodReferencingPath(IModel model, FormulaUsablePath formulaUsablePath, IUsingFormula usingFormula) { var pathAsList = formulaUsablePath.ToList(); var firstIndex = pathAsList.FindIndex(x => x == NBH); diff --git a/src/OSPSuite.Core/Domain/Services/IKeywordReplacer.cs b/src/OSPSuite.Core/Domain/Services/IKeywordReplacer.cs index 57f0e0366..a6f2bc703 100644 --- a/src/OSPSuite.Core/Domain/Services/IKeywordReplacer.cs +++ b/src/OSPSuite.Core/Domain/Services/IKeywordReplacer.cs @@ -16,7 +16,7 @@ public interface IKeywordInObjectPathReplacer : IKeywordReplacer /// returns true if a replacement was done, otherwise false /// /// The object path. - void ReplaceIn(IObjectPath objectPath); + void ReplaceIn(ObjectPath objectPath); } public interface IKeywordInTagsReplacer : IKeywordReplacer diff --git a/src/OSPSuite.Core/Domain/Services/KeywordReplacerTask.cs b/src/OSPSuite.Core/Domain/Services/KeywordReplacerTask.cs index a043b5906..7b17893f5 100644 --- a/src/OSPSuite.Core/Domain/Services/KeywordReplacerTask.cs +++ b/src/OSPSuite.Core/Domain/Services/KeywordReplacerTask.cs @@ -66,7 +66,7 @@ void ReplaceIn(ITransport realization, IContainer rootContainer, string molecule /// Create a new object path based on the given object path where the keyword have been replaced with the appropriate /// names from the root container /// - IObjectPath CreateModelPathFor(IObjectPath objectPath, IContainer rootContainer); + ObjectPath CreateModelPathFor(ObjectPath objectPath, IContainer rootContainer); /// /// Replaces recursively the keywords used in formula defined in neighborhoods and UsingEntityFormula with the @@ -175,11 +175,11 @@ private void replaceInEventGroup(IEventGroup eventGroup, KeywordReplacerCollecti eventGroup.GetAllChildren().Select(x => x.ObjectPath).Each(keywordReplacer.ReplaceIn); } - public IObjectPath CreateModelPathFor(IObjectPath objectPath, IContainer rootContainer) + public ObjectPath CreateModelPathFor(ObjectPath objectPath, IContainer rootContainer) { var keywordReplacer = new KeywordReplacerCollection(); addCommonModelReplacersTo(keywordReplacer, rootContainer); - var modelPath = objectPath.Clone(); + var modelPath = objectPath.Clone(); keywordReplacer.ReplaceIn(modelPath); return modelPath; } diff --git a/src/OSPSuite.Core/Domain/Services/KeywordWithPathReplacer.cs b/src/OSPSuite.Core/Domain/Services/KeywordWithPathReplacer.cs index e248c44f0..a679004b6 100644 --- a/src/OSPSuite.Core/Domain/Services/KeywordWithPathReplacer.cs +++ b/src/OSPSuite.Core/Domain/Services/KeywordWithPathReplacer.cs @@ -25,7 +25,7 @@ public KeywordWithPathReplacer(string keyword, IEnumerable replacingPath /// Replaces the Keyword in the given list. /// /// The objectPath entries where Keyword should be replaced. - public void ReplaceIn(IObjectPath objectPath) + public void ReplaceIn(ObjectPath objectPath) { objectPath.Replace(_keyword, _replacingPath); } diff --git a/src/OSPSuite.Core/Domain/Services/ModelFinalizer.cs b/src/OSPSuite.Core/Domain/Services/ModelFinalizer.cs index 535d8ffd6..f950b8def 100644 --- a/src/OSPSuite.Core/Domain/Services/ModelFinalizer.cs +++ b/src/OSPSuite.Core/Domain/Services/ModelFinalizer.cs @@ -39,7 +39,7 @@ public void FinalizeClone(IModel cloneModel, IModel sourceModel) finalizeReactions(sourceReactionContainerCache, cloneReactionContainerCache); } - private void finalizeReactions(ICache sourceReactionContainerCache, ICache cloneReactionContainerCache) + private void finalizeReactions(ICache sourceReactionContainerCache, ICache cloneReactionContainerCache) { foreach (var keyValue in sourceReactionContainerCache.KeyValues) { @@ -68,15 +68,15 @@ private void finalizePartners(IContainer cloneContainer, IEnumerable createReactionContainerCache(IModel model) + private Cache createReactionContainerCache(IModel model) { - var cache = new Cache(); + var cache = new Cache(); var reactionContainer = model.Root.GetAllChildren(x => x.Children.Any(child => child.IsAnImplementationOf())); reactionContainer.Each(cont => cache.Add(_objectPathFactory.CreateAbsoluteObjectPath(cont), cont)); return cache; } - private void finalizeEventTransports(IModel cloneModel, ICache sourceEventGroups, ICache cloneEventGroups) + private void finalizeEventTransports(IModel cloneModel, ICache sourceEventGroups, ICache cloneEventGroups) { foreach (var sourceKeyValues in sourceEventGroups.KeyValues) { @@ -100,9 +100,9 @@ private void finalizeEventContainer(IContainer sourceEventGroup, IContainer clon finalizeTransportsInMoleculeParentContainer(cloneModel, sourceEventGroup, cloneEventGroup); } - private Cache createEventGroupCache(IModel model) + private Cache createEventGroupCache(IModel model) { - var cache = new Cache(); + var cache = new Cache(); var eventGroups = model.Root.GetAllChildren(); eventGroups.Each(eg => cache.Add(_objectPathFactory.CreateAbsoluteObjectPath(eg), eg)); return cache; diff --git a/src/OSPSuite.Core/Domain/Services/ModelValidator.cs b/src/OSPSuite.Core/Domain/Services/ModelValidator.cs index e9bcaadb7..68012b381 100644 --- a/src/OSPSuite.Core/Domain/Services/ModelValidator.cs +++ b/src/OSPSuite.Core/Domain/Services/ModelValidator.cs @@ -84,7 +84,7 @@ protected void CheckFormulaIn(IUsingFormula entity, IFormula formulaToCheck, Res } } - protected void CheckPath(IUsingFormula entity, IObjectPath objectPathToCheck, ResolveErrorBehavior resolveErrorBehavior) + protected void CheckPath(IUsingFormula entity, ObjectPath objectPathToCheck, ResolveErrorBehavior resolveErrorBehavior) { var builder = _buildConfiguration.BuilderFor(entity); var objectWithError = builder ?? entity; diff --git a/src/OSPSuite.Core/Domain/Services/MoleculeStartValuesCreator.cs b/src/OSPSuite.Core/Domain/Services/MoleculeStartValuesCreator.cs index 81895e558..11ee59dd8 100644 --- a/src/OSPSuite.Core/Domain/Services/MoleculeStartValuesCreator.cs +++ b/src/OSPSuite.Core/Domain/Services/MoleculeStartValuesCreator.cs @@ -21,7 +21,7 @@ public interface IMoleculeStartValuesCreator : IEmptyStartValueCreator /// The value origin for the value /// a MoleculeStartValue object - MoleculeStartValue CreateMoleculeStartValue(IObjectPath containerPath, string moleculeName, IDimension dimension, Unit displayUnit = null, ValueOrigin valueOrigin = null); + MoleculeStartValue CreateMoleculeStartValue(ObjectPath containerPath, string moleculeName, IDimension dimension, Unit displayUnit = null, ValueOrigin valueOrigin = null); } internal class MoleculeStartValuesCreator : IMoleculeStartValuesCreator @@ -76,7 +76,7 @@ private static void setMoleculeStartValue(IMoleculeBuilder moleculeBuilder, Mole moleculeStartValue.Value = moleculeBuilder.GetDefaultMoleculeStartValue(); } - public MoleculeStartValue CreateMoleculeStartValue(IObjectPath containerPath, string moleculeName, IDimension dimension, Unit displayUnit = null, ValueOrigin valueOrigin = null) + public MoleculeStartValue CreateMoleculeStartValue(ObjectPath containerPath, string moleculeName, IDimension dimension, Unit displayUnit = null, ValueOrigin valueOrigin = null) { var msv = new MoleculeStartValue { diff --git a/src/OSPSuite.Core/Domain/Services/ParameterStartValuesCreator.cs b/src/OSPSuite.Core/Domain/Services/ParameterStartValuesCreator.cs index a07cbed37..b14feb6c0 100644 --- a/src/OSPSuite.Core/Domain/Services/ParameterStartValuesCreator.cs +++ b/src/OSPSuite.Core/Domain/Services/ParameterStartValuesCreator.cs @@ -29,7 +29,7 @@ public interface IParameterStartValuesCreator : IEmptyStartValueCreatorThe path of the parameter /// The Parameter object that has the start value and dimension to use /// A new ParameterStartValue - ParameterStartValue CreateParameterStartValue(IObjectPath parameterPath, IParameter parameter); + ParameterStartValue CreateParameterStartValue(ObjectPath parameterPath, IParameter parameter); /// /// Creates and returns a new parameter start value with startValue as StartValue @@ -45,17 +45,17 @@ public interface IParameterStartValuesCreator : IEmptyStartValueCreatorValue origin for this parameter start value /// Value indicating if the value stored is the default value from the parameter. /// A new ParameterStartValue - ParameterStartValue CreateParameterStartValue(IObjectPath parameterPath, double startValue, IDimension dimension, Unit displayUnit = null, + ParameterStartValue CreateParameterStartValue(ObjectPath parameterPath, double startValue, IDimension dimension, Unit displayUnit = null, ValueOrigin valueOrigin = null, bool isDefault = false); } internal class ParameterStartValuesCreator : IParameterStartValuesCreator { private readonly IObjectBaseFactory _objectBaseFactory; - private readonly IObjectPathFactory _objectPathFactory; + private readonly ObjectPathFactory _objectPathFactory; private readonly IIdGenerator _idGenerator; - public ParameterStartValuesCreator(IObjectBaseFactory objectBaseFactory, IObjectPathFactory objectPathFactory, IIdGenerator idGenerator) + public ParameterStartValuesCreator(IObjectBaseFactory objectBaseFactory, ObjectPathFactory objectPathFactory, IIdGenerator idGenerator) { _objectBaseFactory = objectBaseFactory; _objectPathFactory = objectPathFactory; @@ -174,7 +174,7 @@ private ParameterStartValue containerParameterValueFor(IParameter parameter) return CreateParameterStartValue(parameterPath, parameter); } - public ParameterStartValue CreateParameterStartValue(IObjectPath parameterPath, double startValue, IDimension dimension, + public ParameterStartValue CreateParameterStartValue(ObjectPath parameterPath, double startValue, IDimension dimension, Unit displayUnit = null, ValueOrigin valueOrigin = null, bool isDefault = false) { var psv = new ParameterStartValue @@ -191,7 +191,7 @@ public ParameterStartValue CreateParameterStartValue(IObjectPath parameterPath, return psv; } - public ParameterStartValue CreateParameterStartValue(IObjectPath parameterPath, IParameter parameter) + public ParameterStartValue CreateParameterStartValue(ObjectPath parameterPath, IParameter parameter) { return CreateParameterStartValue(parameterPath, parameter.Value, parameter.Dimension, parameter.DisplayUnit, parameter.ValueOrigin, parameter.IsDefault); diff --git a/src/OSPSuite.Core/Domain/Services/SimpleKeywordReplacer.cs b/src/OSPSuite.Core/Domain/Services/SimpleKeywordReplacer.cs index 5ca4faf68..669ceb037 100644 --- a/src/OSPSuite.Core/Domain/Services/SimpleKeywordReplacer.cs +++ b/src/OSPSuite.Core/Domain/Services/SimpleKeywordReplacer.cs @@ -26,7 +26,7 @@ public SimpleKeywordReplacer(string keyword, string replacement) /// Replaces the Keyword in the given list. /// /// The objectPath entries. - public void ReplaceIn(IObjectPath objectPath) + public void ReplaceIn(ObjectPath objectPath) { objectPath.Replace(_keyword, _replacement); } diff --git a/src/OSPSuite.Core/Domain/Services/TopContainerPathReplacer.cs b/src/OSPSuite.Core/Domain/Services/TopContainerPathReplacer.cs index 12c2328f2..f13de013a 100644 --- a/src/OSPSuite.Core/Domain/Services/TopContainerPathReplacer.cs +++ b/src/OSPSuite.Core/Domain/Services/TopContainerPathReplacer.cs @@ -18,7 +18,7 @@ public TopContainerPathReplacer(string rootName, IReadOnlyList topContai _topContainerNames = topContainerNames; } - public void ReplaceIn(IObjectPath objectPath) + public void ReplaceIn(ObjectPath objectPath) { //no element if (!objectPath.Any()) diff --git a/src/OSPSuite.Core/Domain/TimePath.cs b/src/OSPSuite.Core/Domain/TimePath.cs index 9d1155241..e09382dea 100644 --- a/src/OSPSuite.Core/Domain/TimePath.cs +++ b/src/OSPSuite.Core/Domain/TimePath.cs @@ -8,11 +8,10 @@ namespace OSPSuite.Core.Domain /// /// represents a reference to the Simulation time /// - public class TimePath : IFormulaUsablePath + public class TimePath : FormulaUsablePath { private readonly List _path; private readonly TimeParameter _timeParameter; - public string Alias { set; get; } public TimePath() { @@ -21,29 +20,28 @@ public TimePath() Alias = Constants.TIME; } - public string PathAsString => "TIME"; - public void Add(string pathEntry) + public override void Add(string pathEntry) { /*nothing to do here*/ } - public void Replace(string entry, string replacement) + public override void Replace(string entry, string replacement) { /*nothing to do here*/ } - public void Replace(string entry, IEnumerable replacements) + public override void Replace(string entry, IEnumerable replacements) { /*nothing to do here*/ } - public void Remove(string entry) + public override void Remove(string entry) { /*nothing to do here*/ } - public T Resolve(IEntity dependentObject) where T : class + public override T Resolve(IEntity dependentObject) { _timeParameter.ParentContainer = dependentObject.RootContainer; return _timeParameter.DowncastTo(); @@ -55,12 +53,12 @@ public IDimension TimeDimension set => _timeParameter.Dimension = value; } - public T Clone() where T : IObjectPath + public override T Clone() { return new TimePath {TimeDimension = TimeDimension, Alias = Alias}.DowncastTo(); } - public string this[int index] + public override string this[int index] { get => Constants.TIME; set @@ -69,22 +67,22 @@ public string this[int index] } } - public void RemoveAt(int index) + public override void RemoveAt(int index) { /*nothing to do here*/ } - public void RemoveFirst() + public override void RemoveFirst() { /*nothing to do here*/ } - public void ReplaceWith(IEnumerable pathEntries) + public override void ReplaceWith(IEnumerable pathEntries) { /*nothing to do here*/ } - public void AddAtFront(string pathEntry) + public override void AddAtFront(string pathEntry) { /*nothing to do here*/ } @@ -100,24 +98,13 @@ public override int GetHashCode() return PathAsString.GetHashCode(); } - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return _path.GetEnumerator(); - } - public override string ToString() { return PathAsString; } - public int Count => _path.Count; - public IDimension Dimension + public override IDimension Dimension { get => TimeDimension; set => TimeDimension = value; diff --git a/src/OSPSuite.Core/Serialization/Xml/ContainerXmlSerializer.cs b/src/OSPSuite.Core/Serialization/Xml/ContainerXmlSerializer.cs index 292fb39de..8dc40fc94 100644 --- a/src/OSPSuite.Core/Serialization/Xml/ContainerXmlSerializer.cs +++ b/src/OSPSuite.Core/Serialization/Xml/ContainerXmlSerializer.cs @@ -9,6 +9,7 @@ public override void PerformMapping() base.PerformMapping(); Map(x => x.Mode); Map(x => x.ContainerType); + Map(x => x.ParentPath); MapEnumerable(x => x.Children,x => x.Add); } } diff --git a/src/OSPSuite.Core/Serialization/Xml/ObjectPathXmlSerializer.cs b/src/OSPSuite.Core/Serialization/Xml/ObjectPathXmlSerializer.cs index 5f234e53d..eb1d2ae70 100644 --- a/src/OSPSuite.Core/Serialization/Xml/ObjectPathXmlSerializer.cs +++ b/src/OSPSuite.Core/Serialization/Xml/ObjectPathXmlSerializer.cs @@ -7,7 +7,7 @@ namespace OSPSuite.Core.Serialization.Xml { - public class ObjectPathXmlSerializer : OSPSuiteXmlSerializer where T : class, IObjectPath + public class ObjectPathXmlSerializer : OSPSuiteXmlSerializer where T : ObjectPath { public ObjectPathXmlSerializer() { diff --git a/src/OSPSuite.Core/Services/CircularReferenceChecker.cs b/src/OSPSuite.Core/Services/CircularReferenceChecker.cs index 8ad514b1f..3183c5d25 100644 --- a/src/OSPSuite.Core/Services/CircularReferenceChecker.cs +++ b/src/OSPSuite.Core/Services/CircularReferenceChecker.cs @@ -16,7 +16,7 @@ public interface ICircularReferenceChecker /// Returns true if the usage of in the formula of /// would result in circular references otherwise false /// - bool HasCircularReference(IObjectPath path, IEntity referenceObject); + bool HasCircularReference(ObjectPath path, IEntity referenceObject); /// /// Check the given for circular references and returns any problem that may have been found @@ -38,7 +38,7 @@ public CircularReferenceChecker(IObjectPathFactory objectPathFactory, IObjectTyp _entityReferenceCache = new Cache>(x => new List()); } - public bool HasCircularReference(IObjectPath path, IEntity referenceObject) + public bool HasCircularReference(ObjectPath path, IEntity referenceObject) { try { diff --git a/src/OSPSuite.Infrastructure.Reporting/TeXBuilder/FormulaUsablePathsTeXBuilder.cs b/src/OSPSuite.Infrastructure.Reporting/TeXBuilder/FormulaUsablePathsTeXBuilder.cs index 7369afd9f..ca9133303 100644 --- a/src/OSPSuite.Infrastructure.Reporting/TeXBuilder/FormulaUsablePathsTeXBuilder.cs +++ b/src/OSPSuite.Infrastructure.Reporting/TeXBuilder/FormulaUsablePathsTeXBuilder.cs @@ -9,7 +9,7 @@ namespace OSPSuite.Infrastructure.Reporting.TeXBuilder { - internal class FormulaUsablePathsTeXBuilder : TeXChunkBuilder> + internal class FormulaUsablePathsTeXBuilder : TeXChunkBuilder> { private const string PATH = "Path"; private const string ALIAS = "Alias"; @@ -23,17 +23,17 @@ public FormulaUsablePathsTeXBuilder(ITeXBuilderRepository builderRepository) _builderRepository = builderRepository; } - public override void Build(IEnumerable formulaUsablePaths, BuildTracker buildTracker) + public override void Build(IEnumerable formulaUsablePaths, BuildTracker buildTracker) { _builderRepository.Report(tableFor(formulaUsablePaths), buildTracker); } - public override string TeXChunk(IEnumerable formulaUsablePaths) + public override string TeXChunk(IEnumerable formulaUsablePaths) { return _builderRepository.ChunkFor(tableFor(formulaUsablePaths)); } - private static SimpleTable tableFor(IEnumerable formulaUsablePaths) + private static SimpleTable tableFor(IEnumerable formulaUsablePaths) { var dataTable = new DataTable(REFERENCES); dataTable.AddColumn(ALIAS); diff --git a/src/OSPSuite.Presentation/Mappers/DiffItemToDiffItemDTOMapper.cs b/src/OSPSuite.Presentation/Mappers/DiffItemToDiffItemDTOMapper.cs index d4f3f250f..69fdb7272 100644 --- a/src/OSPSuite.Presentation/Mappers/DiffItemToDiffItemDTOMapper.cs +++ b/src/OSPSuite.Presentation/Mappers/DiffItemToDiffItemDTOMapper.cs @@ -105,7 +105,7 @@ private string objectNameFrom(DiffItem diffItem) displayIf(diffItem, x => x.MoleculeName) ?? displayIf(diffItem, x => x.Category) ?? displayIf(diffItem, x => displayNameFor(new Category { Name = x.Category })) ?? - displayIf(diffItem, x => ancestorDisplayName(diffItem)) ?? + displayIf(diffItem, x => ancestorDisplayName(diffItem)) ?? displayIf(diffItem, x => ancestorDisplayName(diffItem)) ?? displayIf(diffItem, x => x.Name) ?? _displayNameProvider.DisplayNameFor(diffItem.Object1); diff --git a/tests/OSPSuite.Core.IntegrationTests/Helpers/AssertForSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Helpers/AssertForSpecs.cs index 5b3657278..f36781199 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Helpers/AssertForSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Helpers/AssertForSpecs.cs @@ -310,15 +310,15 @@ public static void AreEqual(T x1, T x2) where T : class return; } - if (x1.IsAnImplementationOf()) + if (x1.IsAnImplementationOf()) { - AreEqualFormulaUsablePath((IFormulaUsablePath) x1, (IFormulaUsablePath) x2); + AreEqualFormulaUsablePath(x1.DowncastTo(), x2.DowncastTo()); return; } - if (x1.IsAnImplementationOf()) + if (x1.IsAnImplementationOf()) { - AreEqualObjectPath((IObjectPath) x1, (IObjectPath) x2); + AreEqualObjectPath(x1.DowncastTo(), x2.DowncastTo()); return; } @@ -462,13 +462,13 @@ private static void AreEqualEnumerableWithSameOrder(IEnumerable x2, IEnume } } - public static void AreEqualObjectPath(IObjectPath x1, IObjectPath x2) + public static void AreEqualObjectPath(ObjectPath x1, ObjectPath x2) { if (!AssertBothNotNull(x1, x2)) return; AssertAreEqual(x1.PathAsString, x2.PathAsString); } - public static void AreEqualFormulaUsablePath(IFormulaUsablePath x1, IFormulaUsablePath x2) + public static void AreEqualFormulaUsablePath(FormulaUsablePath x1, FormulaUsablePath x2) { if (!AssertBothNotNull(x1, x2)) return; AreEqualObjectPath(x1, x2); @@ -532,6 +532,7 @@ public static void AreEqualContainer(IContainer x1, IContainer x2) { if (!AssertBothNotNull(x1, x2)) return; AreEqualEntity(x1, x2); + AreEqualObjectPath(x1.ParentPath, x2.ParentPath); Assert.AreEqual(x1.Mode, x2.Mode); AreEqualEnumerableOfNamedObjects(x1.Children, x2.Children, x => x.Name); } diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/ContainerXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/ContainerXmlSerializerSpecs.cs index 5a9b8a68e..78c009e89 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/ContainerXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/ContainerXmlSerializerSpecs.cs @@ -10,20 +10,21 @@ public class ContainerXmlSerializerSpecs : ModellingXmlSerializerBaseSpecs [Test] public void TestSerializationEmptyContainer() { - Container x1 = CreateObject().WithName("Conrad").WithMode(ContainerMode.Logical); - IContainer x2 = SerializeAndDeserialize(x1); + var x1 = CreateObject().WithName("Conrad").WithMode(ContainerMode.Logical); + x1.ParentPath = new ObjectPath("A", "B"); + var x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualContainer(x2, x1); } [Test] public void TestSerializationNonEmptyContainer() { - Container x1 = CreateObject().WithName("Conrad").WithMode(ContainerMode.Physical); - Observer o1 = CreateObject().WithName("Oberon").WithParentContainer(x1); - Container c1 = CreateObject().WithName("Carolin").WithMode(ContainerMode.Logical); + var x1 = CreateObject().WithName("Conrad").WithMode(ContainerMode.Physical); + var o1 = CreateObject().WithName("Oberon").WithParentContainer(x1); + var c1 = CreateObject().WithName("Carolin").WithMode(ContainerMode.Logical); x1.Add(c1); - IContainer x2 = SerializeAndDeserialize(x1); + var x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualContainer(x2, x1); } diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/EventBuilderXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/EventBuilderXmlSerializerSpecs.cs index c2a98264c..8959f3ef0 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/EventBuilderXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/EventBuilderXmlSerializerSpecs.cs @@ -34,7 +34,7 @@ public void TestSerialization() x1.OneTime = true; IFormula f1 = CreateObject().WithDimension(DimensionLength).WithFormulaString("3*Patty"); - IFormulaUsablePath fup = new FormulaUsablePath(new string[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); + var fup = new FormulaUsablePath(new string[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); f1.AddObjectPath(fup); IFormula f2 = CreateObject().WithDimension(DimensionLength).WithValue(23.4); diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/FormulaCacheXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/FormulaCacheXmlSerializerSpecs.cs index 9c52dd3ee..a5759534c 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/FormulaCacheXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/FormulaCacheXmlSerializerSpecs.cs @@ -13,7 +13,7 @@ public void TestSerialization() { IFormula f1 = CreateObject().WithName("F.Constantin").WithDimension(DimensionLength).WithValue(2.1); IFormula f2 = CreateObject().WithName("F.Erika").WithDimension(DimensionLength).WithFormulaString("A * 2"); - IFormulaUsablePath fup = new FormulaUsablePath(new[] {"aa", "bb"}).WithAlias("b").WithDimension(DimensionLength); + var fup = new FormulaUsablePath(new[] {"aa", "bb"}).WithAlias("b").WithDimension(DimensionLength); f2.AddObjectPath(fup); FormulaCache x1 = new FormulaCache(); diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/MoleculeBuilderXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/MoleculeBuilderXmlSerializerSpecs.cs index f68b6321f..d44ff9b3d 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/MoleculeBuilderXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/MoleculeBuilderXmlSerializerSpecs.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using NPOI.SS.Formula.Functions; +using NUnit.Framework; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; using OSPSuite.Core.Domain.Formulas; @@ -22,7 +23,7 @@ public void TestSerialization() .WithDimension(DimensionLength); t1.AddParameter(transporterParameter); IFormula f1 = CreateObject().WithDimension(DimensionLength).WithFormulaString("3*Patty"); - IFormulaUsablePath fup = new FormulaUsablePath(new[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); + var fup = new FormulaUsablePath(new[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); f1.AddObjectPath(fup); IParameter p1 = CreateObject().WithName("Patricia").WithFormula(f1).WithValue(3.1).WithMode(ParameterBuildMode.Property); IParameter p2 = CreateObject().WithName("Pascal").WithFormula(f1).WithValue(3.2).WithMode(ParameterBuildMode.Local); diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/ObserverBuilderXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/ObserverBuilderXmlSerializerSpecs.cs index 86217a55b..bf30ad5eb 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/ObserverBuilderXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/ObserverBuilderXmlSerializerSpecs.cs @@ -48,7 +48,7 @@ public void TestSerializationObserverBuilderWithExplicitFormula() x1.AddMoleculeName("CO2"); ExplicitFormula f1 = CreateObject().WithName("Fortunato").WithDimension(DimensionLength); - IFormulaUsablePath fup = new FormulaUsablePath(new string[] {"aa", "bb"}).WithAlias("b").WithDimension(DimensionLength); + var fup = new FormulaUsablePath(new string[] {"aa", "bb"}).WithAlias("b").WithDimension(DimensionLength); f1.AddObjectPath(fup); IFormulaCache formulaCache = new FormulaCache(); diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/ParameterBuilderXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/ParameterBuilderXmlSerializerSpecs.cs index 77e2c7798..422ae3a15 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/ParameterBuilderXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/ParameterBuilderXmlSerializerSpecs.cs @@ -53,7 +53,7 @@ public void TestSerializationParameterBuilderWithParameterWithExplicitFormula() Parameter x1 = CreateObject().WithName("Peter").WithFormula(f1); x1.BuildMode = ParameterBuildMode.Local; - IFormulaUsablePath fup = new FormulaUsablePath(new[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); + var fup = new FormulaUsablePath(new[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); f1.AddObjectPath(fup); x1.Value = 3.4; diff --git a/tests/OSPSuite.Core.IntegrationTests/Serializers/ProcessBuilderXmlSerializerSpecs.cs b/tests/OSPSuite.Core.IntegrationTests/Serializers/ProcessBuilderXmlSerializerSpecs.cs index 72028b5ac..7f33c473d 100644 --- a/tests/OSPSuite.Core.IntegrationTests/Serializers/ProcessBuilderXmlSerializerSpecs.cs +++ b/tests/OSPSuite.Core.IntegrationTests/Serializers/ProcessBuilderXmlSerializerSpecs.cs @@ -17,7 +17,7 @@ public void TestSerialization() x1.Formula = CreateObject().WithDimension(DimensionLength).WithValue(23.4); x1.CreateProcessRateParameter = true; IFormula f1 = CreateObject().WithDimension(DimensionLength).WithFormulaString("3*Patty"); - IFormulaUsablePath fup = new FormulaUsablePath(new[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); + var fup = new FormulaUsablePath(new[] {"Patricia"}).WithAlias("Patty").WithDimension(DimensionLength); f1.AddObjectPath(fup); //WithValue to avoid formula evaluation in McAssertForSpecs-comparison. IParameter p1 = CreateObject().WithName("Patricia").WithFormula(f1).WithValue(3.1); diff --git a/tests/OSPSuite.Core.Tests/Domain/ContainerSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ContainerSpecs.cs index 2d3f84e0f..688d19e99 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ContainerSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ContainerSpecs.cs @@ -224,7 +224,7 @@ protected override void Because() public void should_resolve_the_container_with_the_accurate_predicate_and_return_the_container_as_well() { _results.Count.ShouldBeEqualTo(3); - _results.Any(x=>x.IsNamed("TATA")).ShouldBeTrue(); + _results.Any(x => x.IsNamed("TATA")).ShouldBeTrue(); _results.Any(x => x.IsNamed("TITI")).ShouldBeTrue(); _results.Any(x => x.IsNamed("TOTO")).ShouldBeFalse(); _results.Contains(sut).ShouldBeTrue(); @@ -260,4 +260,23 @@ public void should_resolve_the_container_with_the_accurate_predicate_and_not_ret _results.Contains(sut).ShouldBeFalse(); } } + + public class When_updating_properties_from_another_container : concern_for_Container + { + [Observation] + public void should_have_set_the_parent_type_to_null_if_not_set_in_the_other_container() + { + var container = new Container(); + sut.UpdatePropertiesFrom(container, null); + sut.ParentPath.ShouldBeNull(); + } + + [Observation] + public void should_have_set_a_clone_otherwise() + { + var container = new Container {ParentPath = new ObjectPath("TOTO", "TATA")}; + sut.UpdatePropertiesFrom(container, null); + sut.ParentPath.ShouldOnlyContainInOrder("TOTO", "TATA"); + } + } } \ No newline at end of file diff --git a/tests/OSPSuite.Core.Tests/Domain/ExplicitFormulaSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ExplicitFormulaSpecs.cs index 16f559b21..a5267e94e 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ExplicitFormulaSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ExplicitFormulaSpecs.cs @@ -10,8 +10,8 @@ public abstract class concern_for_ExplicitFormula : ContextSpecification(); A.CallTo(() => _y.Value).Returns(3); - _pathX = A.Fake(); - A.CallTo(() => _pathX.Alias).Returns("x"); + _pathX = A.Fake(); + _pathX.Alias = "x"; A.CallTo(() => _pathX.Resolve(_usingObj)).Returns(_x); - _pathY = A.Fake(); - A.CallTo(() => _pathY.Alias).Returns("y"); + _pathY = A.Fake(); + _pathY.Alias = "y"; A.CallTo(() => _pathY.Resolve(_usingObj)).Returns(_y); diff --git a/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathExtensionsSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathExtensionsSpecs.cs index 7ea097b5b..5c96ef4f7 100644 --- a/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathExtensionsSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathExtensionsSpecs.cs @@ -6,11 +6,11 @@ namespace OSPSuite.Core.Domain { public abstract class concern_for_object_path_extensions : StaticContextSpecification { - protected IFormulaUsablePath _formulaUsablePath; + protected FormulaUsablePath _formulaUsablePath; protected override void Context() { - _formulaUsablePath = A.Fake(); + _formulaUsablePath = A.Fake(); } } diff --git a/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathSpecs.cs index 20f1efa67..d49a3adee 100644 --- a/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/FormulaUsablePathSpecs.cs @@ -6,7 +6,7 @@ namespace OSPSuite.Core.Domain { - public abstract class concern_for_FormulaUsablePath : ContextSpecification + public abstract class concern_for_FormulaUsablePath : ContextSpecification { protected IContainer _comp; protected IContainer _organ; @@ -76,8 +76,8 @@ public void should_return_null() public class When_cloning_a_formula_usable_path : concern_for_FormulaUsablePath { - private IObjectPath _objectPath; - private IObjectPath _clonePath; + private ObjectPath _objectPath; + private ObjectPath _clonePath; protected override void Context() { @@ -86,25 +86,25 @@ protected override void Context() protected override void Because() { - _clonePath = _objectPath.Clone(); + _clonePath = _objectPath.Clone(); } [Observation] public void should_return_a_formula_usable_path() { - _clonePath.ShouldBeAnInstanceOf(); + _clonePath.ShouldBeAnInstanceOf(); } [Observation] public void should_have_updated_the_alias() { - _clonePath.DowncastTo().Alias.ShouldBeEqualTo("C"); + _clonePath.DowncastTo().Alias.ShouldBeEqualTo("C"); } } public class When_comparing_equal_paths : concern_for_FormulaUsablePath { - private IFormulaUsablePath _equalPath; + private FormulaUsablePath _equalPath; protected override void Context() { @@ -122,7 +122,7 @@ public void should_return_true() public class When_comparing_different_paths : concern_for_FormulaUsablePath { - private IFormulaUsablePath _differentPath; + private FormulaUsablePath _differentPath; protected override void Context() { @@ -138,10 +138,10 @@ public void should_return_false() } } - public class When_comparing_path_diffeering_only_by_dimension : concern_for_FormulaUsablePath + public class When_comparing_path_differing_only_by_dimension : concern_for_FormulaUsablePath { - private IFormulaUsablePath _differentPath; - + private FormulaUsablePath _differentPath; + protected override void Context() { base.Context(); diff --git a/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerCollectionSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerCollectionSpecs.cs index b1e56fe50..1c9dde2d0 100644 --- a/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerCollectionSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerCollectionSpecs.cs @@ -19,8 +19,8 @@ public class When_replacing_the_keywords_in_an_entity : concern_for_KeywordRepla private IParameter _parameter; private IKeywordInObjectPathReplacer _replacement; private IKeywordInTagsReplacer _replacementTag; - private IFormulaUsablePath _objectPath1; - private IFormulaUsablePath _objectPath2; + private FormulaUsablePath _objectPath1; + private FormulaUsablePath _objectPath2; protected override void Context() { diff --git a/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerTaskSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerTaskSpecs.cs index 211531699..92dff3d86 100644 --- a/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerTaskSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/KeywordReplacerTaskSpecs.cs @@ -12,9 +12,9 @@ namespace OSPSuite.Core.Domain public abstract class concern_for_KeywordReplacerTask : ContextSpecification { protected string _modelName; - protected IFormulaUsablePath _objPathFirstNeighbor; - protected IFormulaUsablePath _objPathMolecule; - protected IFormulaUsablePath _objPathOrganism; + protected FormulaUsablePath _objPathFirstNeighbor; + protected FormulaUsablePath _objPathMolecule; + protected FormulaUsablePath _objPathOrganism; protected IModel _model; protected override void Context() diff --git a/tests/OSPSuite.Core.Tests/Domain/ObjectPathExtensionsSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ObjectPathExtensionsSpecs.cs index d44d95ae3..3f7ae4d81 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ObjectPathExtensionsSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ObjectPathExtensionsSpecs.cs @@ -7,13 +7,13 @@ namespace OSPSuite.Core.Domain { public abstract class concern_for_ObjectPathExtensions : StaticContextSpecification { - protected IObjectPath _objectPath; + protected ObjectPath _objectPath; protected string _entryToAdd; protected override void Context() { _entryToAdd = "toto"; - _objectPath = A.Fake(); + _objectPath = A.Fake(); } } diff --git a/tests/OSPSuite.Core.Tests/Domain/ObjectPathFactorySpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ObjectPathFactorySpecs.cs index 161c44b20..b33e0c787 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ObjectPathFactorySpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ObjectPathFactorySpecs.cs @@ -32,7 +32,7 @@ protected override void Context() public class When_we_create_an_absolute_path_to_a_top_container : concern_for_ObjectPathFactory { - private IObjectPath _objectPath; + private ObjectPath _objectPath; protected override void Because() { @@ -54,7 +54,7 @@ public void resolve_should_return_root() public class When_we_create_an_absolute_path_to_an_entity_without_a_parent_container : concern_for_ObjectPathFactory { - private IObjectPath _objectPath; + private ObjectPath _objectPath; private IEntity _aParameter; protected override void Context() @@ -79,7 +79,7 @@ public void should_return_path_to_itself() public class When_we_create_an_absolute_path_to_a_root_container : concern_for_ObjectPathFactory { - private IObjectPath _objectPath; + private ObjectPath _objectPath; private IEntity _rootContainer; protected override void Context() @@ -104,7 +104,7 @@ public void should_return_path_to_itself() public class When_we_create_an_absolute_path_to_parameter : concern_for_ObjectPathFactory { - private IFormulaUsablePath _formulaUsablePath; + private FormulaUsablePath _formulaUsablePath; protected override void Because() { @@ -128,7 +128,7 @@ public void should_return_parameter() public class When_creating_a_time_path_object_path : concern_for_ObjectPathFactory { - private IFormulaUsablePath _timePath; + private FormulaUsablePath _timePath; private IDimension _timeDimension; protected override void Context() @@ -156,7 +156,7 @@ public void should_have_set_the_dimension_of_the_object_path_to_the_time_dimensi public class When_creating_a_relative_path_to_ourself:concern_for_ObjectPathFactory { - private IObjectPath _path; + private ObjectPath _path; protected override void Because() { _path = sut.CreateRelativeObjectPath(_parameter, _parameter); diff --git a/tests/OSPSuite.Core.Tests/Domain/ObjectPathSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ObjectPathSpecs.cs index 09a952136..1c6ee13ee 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ObjectPathSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ObjectPathSpecs.cs @@ -4,7 +4,7 @@ namespace OSPSuite.Core.Domain { - public abstract class concern_for_ObjectPath : ContextSpecification + public abstract class concern_for_ObjectPath : ContextSpecification { protected override void Context() { diff --git a/tests/OSPSuite.Core.Tests/Domain/ParameterStartValueSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ParameterStartValueSpecs.cs index cc5630854..659870e05 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ParameterStartValueSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ParameterStartValueSpecs.cs @@ -172,7 +172,7 @@ protected override void Context() _comparable = new ParameterStartValue(); sut.Path = new ObjectPath("A", "B", "Name"); - _comparable.Path = sut.Path.Clone(); + _comparable.Path = sut.Path.Clone(); sut.Value = 1.0; _comparable.Value = sut.Value; diff --git a/tests/OSPSuite.Core.Tests/Domain/ProcessRateParameterCreatorSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/ProcessRateParameterCreatorSpecs.cs index 5f5d9f703..ad132a7bb 100644 --- a/tests/OSPSuite.Core.Tests/Domain/ProcessRateParameterCreatorSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/ProcessRateParameterCreatorSpecs.cs @@ -25,9 +25,9 @@ public class When_creating_a_parameter_rate_for_a_process_builder : concern_for_ private IParameter _processRateParameter; private IProcessBuilder _processBuilder; private IBuildConfiguration _buildConfiguration; - private IFormulaUsablePath _formulaUsablePathB; - private IFormulaUsablePath _formulaUsablePathA; - private IFormulaUsablePath _formulaUsablePathFU; + private FormulaUsablePath _formulaUsablePathB; + private FormulaUsablePath _formulaUsablePathA; + private FormulaUsablePath _formulaUsablePathFU; private FormulaUsablePath _formulaUsablePathBW; protected override void Context() diff --git a/tests/OSPSuite.Core.Tests/Domain/TimePathSpecs.cs b/tests/OSPSuite.Core.Tests/Domain/TimePathSpecs.cs index 23866705b..c0ddde9a6 100644 --- a/tests/OSPSuite.Core.Tests/Domain/TimePathSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Domain/TimePathSpecs.cs @@ -5,7 +5,7 @@ namespace OSPSuite.Core.Domain { - public abstract class concern_for_TimePath : ContextSpecification + public abstract class concern_for_TimePath : ContextSpecification { protected IDimension _time; @@ -38,7 +38,7 @@ public void should_create_a_time_parameter() _res.GetType().ShouldBeEqualTo(typeof(TimeParameter)); } [Observation] - public void returned_object_should_have_diemension_time() + public void returned_object_should_have_dimension_time() { _res.Dimension.ShouldBeEqualTo(_time); } diff --git a/tests/OSPSuite.Core.Tests/Mappers/NeighborhoodBuilderToNeighborhoodMapperSpecs.cs b/tests/OSPSuite.Core.Tests/Mappers/NeighborhoodBuilderToNeighborhoodMapperSpecs.cs index fc533045c..f45a026f0 100644 --- a/tests/OSPSuite.Core.Tests/Mappers/NeighborhoodBuilderToNeighborhoodMapperSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Mappers/NeighborhoodBuilderToNeighborhoodMapperSpecs.cs @@ -21,16 +21,15 @@ public abstract class concern_for_NeighborhoodBuilderToNeighborhoodMapper : Cont protected override void Context() { _objectBaseFactory = A.Fake(); - _containerMapper = A.Fake< IContainerBuilderToContainerMapper>(); - _objectPathFactory =A.Fake(); - _cloneManagerForModel =A.Fake(); + _containerMapper = A.Fake(); + _objectPathFactory = A.Fake(); + _cloneManagerForModel = A.Fake(); _keywordReplacerTask = A.Fake(); _parameterMapper = A.Fake(); - sut = new NeighborhoodBuilderToNeighborhoodMapper(_objectBaseFactory, _containerMapper, _objectPathFactory,_keywordReplacerTask,_cloneManagerForModel,_parameterMapper); + sut = new NeighborhoodBuilderToNeighborhoodMapper(_objectBaseFactory, _containerMapper, _objectPathFactory, _keywordReplacerTask, _cloneManagerForModel, _parameterMapper); } } - public class When_mapping_a_neighborhood_builder_to_a_neighborhood : concern_for_NeighborhoodBuilderToNeighborhoodMapper { private INeighborhoodBuilder _neighborhoodBuilder; @@ -45,10 +44,7 @@ public class When_mapping_a_neighborhood_builder_to_a_neighborhood : concern_for private IContainer _firstNeighborInModel; private IContainer _secondNeighborInModel; private IBuildConfiguration _buildConfiguration; - private IContainer _moleculeContainer - - - ; + private IContainer _moleculeContainer; protected override void Context() { @@ -60,42 +56,43 @@ protected override void Context() _neighborhoodBuilder = A.Fake().WithName("tralala"); _neighborhoodBuilder.FirstNeighbor = A.Fake(); _neighborhoodBuilder.SecondNeighbor = A.Fake(); - A.CallTo(()=>_neighborhoodBuilder.MoleculeProperties).Returns(A.Fake()); + A.CallTo(() => _neighborhoodBuilder.MoleculeProperties).Returns(A.Fake()); var para1 = A.Fake(); var para2 = A.Fake(); - A.CallTo(()=>_neighborhoodBuilder.Parameters).Returns(new[] { para1, para2 }); - _clonePara1 =A.Fake(); - _clonePara2 =A.Fake(); - var firstNeighborBuilderPath = A.Fake(); - var secondNeighborBuilderPath = A.Fake(); - A.CallTo(()=>_objectPathFactory.CreateAbsoluteObjectPath(_neighborhoodBuilder.FirstNeighbor)).Returns(firstNeighborBuilderPath); - A.CallTo(()=>_objectPathFactory.CreateAbsoluteObjectPath(_neighborhoodBuilder.SecondNeighbor)).Returns(secondNeighborBuilderPath); - var firstNeighborModelPath = A.Fake(); - var secondNeighborModelPath = A.Fake(); + A.CallTo(() => _neighborhoodBuilder.Parameters).Returns(new[] {para1, para2}); + _clonePara1 = A.Fake(); + _clonePara2 = A.Fake(); + var firstNeighborBuilderPath = A.Fake(); + var secondNeighborBuilderPath = A.Fake(); + A.CallTo(() => _objectPathFactory.CreateAbsoluteObjectPath(_neighborhoodBuilder.FirstNeighbor)).Returns(firstNeighborBuilderPath); + A.CallTo(() => _objectPathFactory.CreateAbsoluteObjectPath(_neighborhoodBuilder.SecondNeighbor)).Returns(secondNeighborBuilderPath); + var firstNeighborModelPath = A.Fake(); + var secondNeighborModelPath = A.Fake(); _firstNeighborInModel = A.Fake(); _secondNeighborInModel = A.Fake(); - A.CallTo(()=>_keywordReplacerTask.CreateModelPathFor(firstNeighborBuilderPath, _model.Root)).Returns(firstNeighborModelPath); - A.CallTo(()=>_keywordReplacerTask.CreateModelPathFor(secondNeighborBuilderPath, _model.Root)).Returns(secondNeighborModelPath); - A.CallTo(()=>firstNeighborModelPath.Resolve(_rootContainer)).Returns(_firstNeighborInModel); - A.CallTo(()=>secondNeighborModelPath.Resolve(_rootContainer)).Returns(_secondNeighborInModel); - _moleculeContainer= A.Fake(); - A.CallTo(() => _containerMapper.MapFrom(_neighborhoodBuilder.MoleculeProperties, _buildConfiguration)).Returns(_moleculeContainer); + A.CallTo(() => _keywordReplacerTask.CreateModelPathFor(firstNeighborBuilderPath, _model.Root)).Returns(firstNeighborModelPath); + A.CallTo(() => _keywordReplacerTask.CreateModelPathFor(secondNeighborBuilderPath, _model.Root)).Returns(secondNeighborModelPath); + A.CallTo(() => firstNeighborModelPath.Resolve(_rootContainer)).Returns(_firstNeighborInModel); + A.CallTo(() => secondNeighborModelPath.Resolve(_rootContainer)).Returns(_secondNeighborInModel); + _moleculeContainer = A.Fake(); + A.CallTo(() => _containerMapper.MapFrom(_neighborhoodBuilder.MoleculeProperties, _buildConfiguration)).Returns(_moleculeContainer); _molecule1 = "molecule1"; _molecule2 = "molecule2"; _moleculeNames = new List {_molecule1, _molecule2}; - A.CallTo(()=>_objectBaseFactory.Create()).Returns(A.Fake()); - A.CallTo(() => _parameterMapper.MapFrom(para1,_buildConfiguration)).Returns(_clonePara1); - A.CallTo(() => _parameterMapper.MapFrom(para2,_buildConfiguration)).Returns(_clonePara2); + A.CallTo(() => _objectBaseFactory.Create()).Returns(A.Fake()); + A.CallTo(() => _parameterMapper.MapFrom(para1, _buildConfiguration)).Returns(_clonePara1); + A.CallTo(() => _parameterMapper.MapFrom(para2, _buildConfiguration)).Returns(_clonePara2); } protected override void Because() { _neighborhood = sut.MapFrom(_neighborhoodBuilder, _model, _buildConfiguration, _moleculeNames, _moleculeNames); } + [Observation] public void should_return_a_neighborhood_whose_name_was_set_to_the_name_of_the_neighborhood_builder() { - A.CallTo(() => _neighborhood.UpdatePropertiesFrom(_neighborhoodBuilder, _cloneManagerForModel)).MustHaveHappened(); + A.CallTo(() => _neighborhood.UpdatePropertiesFrom(_neighborhoodBuilder, _cloneManagerForModel)).MustHaveHappened(); } [Observation] @@ -118,4 +115,4 @@ public void should_have_updated_the_container_type_of_the_molecule_container_to_ _moleculeContainer.ContainerType.ShouldBeEqualTo(ContainerType.Molecule); } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/OSPSuite.Core.Tests/Services/CircularReferenceCheckerSpecs.cs b/tests/OSPSuite.Core.Tests/Services/CircularReferenceCheckerSpecs.cs index 5c53a2fbe..665105aa8 100644 --- a/tests/OSPSuite.Core.Tests/Services/CircularReferenceCheckerSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Services/CircularReferenceCheckerSpecs.cs @@ -13,7 +13,7 @@ namespace OSPSuite.Core.Services public abstract class concern_for_CircularReferenceChecker : ContextSpecification { protected IFormula _formula; - protected List _objectPaths; + protected List _objectPaths; protected IQuantity _testObject; protected IObjectPathFactory _objectPathFactory; private IObjectTypeResolver _objectTypeResolver; @@ -21,7 +21,7 @@ public abstract class concern_for_CircularReferenceChecker : ContextSpecificatio protected override void Context() { _formula = A.Fake(); - _objectPaths = new List(); + _objectPaths = new List(); A.CallTo(() => _formula.ObjectPaths).Returns(_objectPaths); _testObject = A.Fake(); _testObject.Formula = _formula; @@ -50,12 +50,12 @@ public void should_always_return_no_circular_references() public class When_checking_a_self_reference : concern_for_CircularReferenceChecker { private bool _result; - private IFormulaUsablePath _path; + private FormulaUsablePath _path; protected override void Context() { base.Context(); - _path = A.Fake(); + _path = A.Fake(); A.CallTo(() => _path.Resolve(_testObject)).Returns(_testObject); _objectPaths.Add(_path); } @@ -75,7 +75,7 @@ public void should_always_return_circular_references() public class When_checking_a_two_step_reference : concern_for_CircularReferenceChecker { private bool _result; - private IFormulaUsablePath _path; + private FormulaUsablePath _path; protected override void Context() { @@ -84,12 +84,12 @@ protected override void Context() var stepFormula = A.Fake(); - var otherPath = A.Fake(); + var otherPath = A.Fake(); otherPath.Alias = "ToTestObject"; A.CallTo(() => otherPath.Resolve(stepOne)).Returns(_testObject); - _path = A.Fake(); + _path = A.Fake(); _path.Alias = "ToStepOne"; A.CallTo(() => _path.Resolve(_testObject)).Returns(stepOne); stepOne.Formula = stepFormula; diff --git a/tests/OSPSuite.Core.Tests/Services/KeywordWithPathReplacerSpecs.cs b/tests/OSPSuite.Core.Tests/Services/KeywordWithPathReplacerSpecs.cs index 64a5949f8..78fdc787f 100644 --- a/tests/OSPSuite.Core.Tests/Services/KeywordWithPathReplacerSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Services/KeywordWithPathReplacerSpecs.cs @@ -20,9 +20,9 @@ protected override void Context() } } - public class When_told_to_replace_keyword_with_a_path_in_a_path_conntaining_keyword : concern_for_KeywordWithPathReplacer + public class When_told_to_replace_keyword_with_a_path_in_a_path_containing_keyword : concern_for_KeywordWithPathReplacer { - private IFormulaUsablePath _path; + private FormulaUsablePath _path; protected override void Context() { @@ -53,9 +53,9 @@ public void should_not_change_the_order_of_the_elements() } - public class When_told_to_replace_keyword_with_a_path_in_a_path_not_conntaining_keyword : concern_for_KeywordWithPathReplacer + public class When_told_to_replace_keyword_with_a_path_in_a_path_not_containing_keyword : concern_for_KeywordWithPathReplacer { - private IFormulaUsablePath _path; + private FormulaUsablePath _path; protected override void Context() { diff --git a/tests/OSPSuite.Core.Tests/Services/ParameterIdentificationSimulationPathUpdaterSpecs.cs b/tests/OSPSuite.Core.Tests/Services/ParameterIdentificationSimulationPathUpdaterSpecs.cs index e1e84582d..08cbc06f5 100644 --- a/tests/OSPSuite.Core.Tests/Services/ParameterIdentificationSimulationPathUpdaterSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Services/ParameterIdentificationSimulationPathUpdaterSpecs.cs @@ -31,7 +31,7 @@ public class When_the_parameter_identification_task_is_updating_paths_for_a_simu private IProject _project; private ParameterIdentification _parameterIdentification; private DataRepository _simulationDataRepository; - private IObjectPath _initialObjectPath; + private ObjectPath _initialObjectPath; private DataRepository _observationDataRepository; private ResidualsResult _residualsResult; diff --git a/tests/OSPSuite.Core.Tests/Services/SimpleKeywordReplacerSpecs.cs b/tests/OSPSuite.Core.Tests/Services/SimpleKeywordReplacerSpecs.cs index d28dbe998..a668015ca 100644 --- a/tests/OSPSuite.Core.Tests/Services/SimpleKeywordReplacerSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Services/SimpleKeywordReplacerSpecs.cs @@ -21,7 +21,7 @@ protected override void Context() public class When_told_to_replace_keyword_using_simple_key_replacer_in_a_Path_conntaining_keyWord : concern_for_SimpleKeywordReplacer { - private IFormulaUsablePath _path; + private FormulaUsablePath _path; protected override void Context() { @@ -38,7 +38,7 @@ public void should_have_removed_key_word_from_path() _path.Contains(_keyword).ShouldBeFalse(); } [Observation] - public void should_have_added_replacment_from_in_path() + public void should_have_added_replacement_from_in_path() { _path.Contains(_replacement).ShouldBeTrue(); } @@ -50,9 +50,9 @@ public void should_not_change_the_order_of_the_elements() } - public class When_told_to_replace_keyword_using_simple_key_replacer_in_a_path_not_conntaining_keyword : concern_for_SimpleKeywordReplacer + public class When_told_to_replace_keyword_using_simple_key_replacer_in_a_path_not_containing_keyword : concern_for_SimpleKeywordReplacer { - private IFormulaUsablePath _path; + private FormulaUsablePath _path; protected override void Context() { diff --git a/tests/OSPSuite.Core.Tests/Services/TopContainerPathReplacerSpecs.cs b/tests/OSPSuite.Core.Tests/Services/TopContainerPathReplacerSpecs.cs index 282e8a272..14662cd39 100644 --- a/tests/OSPSuite.Core.Tests/Services/TopContainerPathReplacerSpecs.cs +++ b/tests/OSPSuite.Core.Tests/Services/TopContainerPathReplacerSpecs.cs @@ -9,7 +9,7 @@ namespace OSPSuite.Core.Services public abstract class concern_for_TopContainerPathReplacer : ContextSpecification { protected string _modelName; - protected IObjectPath _objectPath; + protected ObjectPath _objectPath; private IReadOnlyList _topContainerNames; protected override void Context() @@ -63,13 +63,13 @@ public void should_not_change_the_path() public class When_replacing_a_path_that_does_not_start_with_a_key_word_or_a_relative_path_marker : concern_for_TopContainerPathReplacer { - private IObjectPath _pathWithModelNameFirst; + private ObjectPath _pathWithModelNameFirst; protected override void Context() { base.Context(); _objectPath = new ObjectPath("root2", "B"); - _pathWithModelNameFirst = _objectPath.Clone(); + _pathWithModelNameFirst = _objectPath.Clone(); _pathWithModelNameFirst.AddAtFront(_modelName); }