Skip to content

Commit

Permalink
Fixes #1792 Deviation and Identity columns are not named in data browser
Browse files Browse the repository at this point in the history
  • Loading branch information
rwmcintosh committed Nov 15, 2022
1 parent 52241d7 commit 16dc7ca
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/OSPSuite.Core/Domain/Data/DataColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static class DataColumnExtensions

public static bool IsObservationAuxiliary(this DataColumn column) => dataColumnIs(column, ColumnOrigins.ObservationAuxiliary);

public static bool IsDeviation(this DataColumn column) => dataColumnIs(column, ColumnOrigins.DeviationLine);

private static bool dataColumnIs(DataColumn column, ColumnOrigins columnOrigin) => column.DataInfo?.Origin == columnOrigin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ public PathElements MapFrom(DataColumn dataColumn, IContainer rootContainer)
if (dataColumn.IsObservation())
return ObservedDataPathElementsFor(dataColumn, quantityPath);

if (dataColumn.IsBaseGrid())
return pathElementsForBaseGrid(dataColumn);
if (dataColumn.IsBaseGrid() || dataColumn.IsDeviation())
return pathElementsForNameOnlyColumn(dataColumn);

return pathElementsForUnknownColumns(dataColumn, quantityPath);
}

private static PathElements pathElementsForBaseGrid(DataColumn dataColumn)
private static PathElements pathElementsForNameOnlyColumn(DataColumn dataColumn)
{
var pathColumnValues = new PathElements();
pathColumnValues[PathElementId.Name] = new PathElement {DisplayName = dataColumn.Name};
var pathColumnValues = new PathElements
{
[PathElementId.Name] = new PathElement {DisplayName = dataColumn.Name}
};
return pathColumnValues;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Mappers;
using OSPSuite.Core.Domain.UnitSystem;
using OSPSuite.Helpers;

namespace OSPSuite.Core
{
public class concern_for_DataColumnToPathElementsMapper : ContextForIntegration<DataColumnToPathElementsMapper>
{
protected override void Context()
{
base.Context();
sut = new DataColumnToPathElementsMapper(new PathToPathElementsMapper(new EntityPathResolverForSpecs()));
}
}

public class When_resolving_name_for_a_basegrid_column : concern_for_DataColumnToPathElementsMapper
{
private DataColumn _dataColumn;
private PathElements _result;

protected override void Context()
{
base.Context();
_dataColumn = new BaseGrid("basegrid", new Dimension(new BaseDimensionRepresentation(), "dimensionName", "baseUnitName")) { QuantityInfo = new QuantityInfo(new List<string>(), QuantityType.BaseGrid), DataInfo = new DataInfo(ColumnOrigins.BaseGrid) };
}

protected override void Because()
{
_result = sut.MapFrom(_dataColumn, null);
}

[Observation]
public void the_name_mapped_should_be_the_name_of_the_column()
{
_result[PathElementId.Name].DisplayName.ShouldBeEqualTo(_dataColumn.Name);
}
}

public class When_resolving_name_for_a_calculation_column : concern_for_DataColumnToPathElementsMapper
{
private DataColumn _dataColumn;
private PathElements _result;
private IContainer _topContainer;

protected override void Context()
{
base.Context();
_topContainer = new Container().WithName("topContainerName");
_topContainer.Add(new Container().WithName("secondContainer"));
_dataColumn = new DataColumn { QuantityInfo = new QuantityInfo(new List<string> { "topContainerName", "secondContainer" }, QuantityType.Molecule), DataInfo = new DataInfo(ColumnOrigins.Calculation), Name = "dataColumnDisplayName" };
}

protected override void Because()
{
_result = sut.MapFrom(_dataColumn, _topContainer);
}

[Observation]
public void the_top_container_mapped_should_be_the_first_element_of_the_quantity_path()
{
_result[PathElementId.TopContainer].DisplayName.ShouldBeEqualTo(_dataColumn.QuantityInfo.Path.First());
_result[PathElementId.Container].DisplayName.ShouldBeEqualTo(_dataColumn.QuantityInfo.Path.ElementAt(1));
_result[PathElementId.Name].DisplayName.ShouldBeEqualTo(_dataColumn.QuantityInfo.Path.ElementAt(1));
}
}

public class When_resolving_name_for_a_observation_column : concern_for_DataColumnToPathElementsMapper
{
private DataColumn _dataColumn;
private PathElements _result;

protected override void Context()
{
base.Context();
_dataColumn = new DataColumn { QuantityInfo = new QuantityInfo(new List<string> {"observationColumnName"}, QuantityType.Molecule), DataInfo = new DataInfo(ColumnOrigins.Observation), Name = "dataColumnDisplayName" };
}

protected override void Because()
{
_result = sut.MapFrom(_dataColumn, null);
}

[Observation]
public void the_top_container_mapped_should_be_the_first_element_of_the_quantity_path()
{
_result[PathElementId.TopContainer].DisplayName.ShouldBeEqualTo(_dataColumn.QuantityInfo.Path.First());
}
}

public class When_resolving_name_for_a_deviation_column : concern_for_DataColumnToPathElementsMapper
{
private DataColumn _dataColumn;
private PathElements _result;

protected override void Context()
{
base.Context();
_dataColumn = new DataColumn { QuantityInfo = new QuantityInfo(new List<string>(), QuantityType.Molecule), DataInfo = new DataInfo(ColumnOrigins.DeviationLine), Name = "dataColumnDisplayName" };
}

protected override void Because()
{
_result = sut.MapFrom(_dataColumn, null);
}

[Observation]
public void the_name_mapped_should_be_the_name_of_the_column()
{
_result[PathElementId.Name].DisplayName.ShouldBeEqualTo(_dataColumn.Name);
}
}
}

0 comments on commit 16dc7ca

Please sign in to comment.