Add lib material tests
This commit is contained in:
@@ -1,25 +1,21 @@
|
|||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
using StructureHelperCommon.Models;
|
||||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DataAccess.DTOs
|
namespace DataAccess.DTOs
|
||||||
{
|
{
|
||||||
public class CrackCalculatorFromDTOConvertStrategy : ConvertStrategy<CrackCalculator, CrackCalculatorDTO>
|
public class CrackCalculatorFromDTOConvertStrategy : ConvertStrategy<CrackCalculator, CrackCalculatorDTO>
|
||||||
{
|
{
|
||||||
private IConvertStrategy<CrackCalculatorInputData, CrackCalculatorInputDataDTO> convertStrategy = new CrackCalculatorInputDataFromDTOConvertStrategy();
|
private IConvertStrategy<CrackCalculatorInputData, CrackCalculatorInputDataDTO> convertStrategy;
|
||||||
|
private IConvertStrategy<CrackCalculatorInputData, CrackCalculatorInputDataDTO> ConvertStrategy => convertStrategy ??= new CrackCalculatorInputDataFromDTOConvertStrategy();
|
||||||
|
|
||||||
public override CrackCalculator GetNewItem(CrackCalculatorDTO source)
|
public override CrackCalculator GetNewItem(CrackCalculatorDTO source)
|
||||||
{
|
{
|
||||||
NewItem = new(source.Id);
|
NewItem = new(source.Id, new ShiftTraceLogger());
|
||||||
NewItem.Name = source.Name;
|
NewItem.Name = source.Name;
|
||||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
ConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||||
convertStrategy.TraceLogger = TraceLogger;
|
ConvertStrategy.TraceLogger = TraceLogger;
|
||||||
NewItem.InputData = convertStrategy.Convert(source.InputData as CrackCalculatorInputDataDTO);
|
NewItem.InputData = ConvertStrategy.Convert(source.InputData as CrackCalculatorInputDataDTO);
|
||||||
return NewItem;
|
return NewItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -92,7 +92,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
|||||||
private void AddCrackCalculator()
|
private void AddCrackCalculator()
|
||||||
{
|
{
|
||||||
var inputData = new CrackCalculatorInputData();
|
var inputData = new CrackCalculatorInputData();
|
||||||
var calculator = new CrackCalculator()
|
var calculator = new CrackCalculator(Guid.NewGuid(), new ShiftTraceLogger())
|
||||||
{
|
{
|
||||||
Name = "New crack calculator",
|
Name = "New crack calculator",
|
||||||
TraceLogger = new ShiftTraceLogger(),
|
TraceLogger = new ShiftTraceLogger(),
|
||||||
@@ -114,7 +114,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
|||||||
|
|
||||||
private void AddForceCalculator()
|
private void AddForceCalculator()
|
||||||
{
|
{
|
||||||
NewItem = new ForceCalculator()
|
NewItem = new ForceCalculator(Guid.NewGuid())
|
||||||
{
|
{
|
||||||
Name = "New force calculator",
|
Name = "New force calculator",
|
||||||
TraceLogger = new ShiftTraceLogger(),
|
TraceLogger = new ShiftTraceLogger(),
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ namespace StructureHelperLogics.Models.Materials
|
|||||||
public class ReinforcementLibUpdateStrategy : IUpdateStrategy<IReinforcementLibMaterial>
|
public class ReinforcementLibUpdateStrategy : IUpdateStrategy<IReinforcementLibMaterial>
|
||||||
{
|
{
|
||||||
private IUpdateStrategy<ILibMaterial> libUpdateStrategy;
|
private IUpdateStrategy<ILibMaterial> libUpdateStrategy;
|
||||||
|
private IUpdateStrategy<ILibMaterial> LibUpdateStrategy => libUpdateStrategy ??= new LibMaterialUpdateStrategy();
|
||||||
public ReinforcementLibUpdateStrategy(IUpdateStrategy<ILibMaterial> libUpdateStrategy)
|
public ReinforcementLibUpdateStrategy(IUpdateStrategy<ILibMaterial> libUpdateStrategy)
|
||||||
{
|
{
|
||||||
this.libUpdateStrategy = libUpdateStrategy;
|
this.libUpdateStrategy = libUpdateStrategy;
|
||||||
}
|
}
|
||||||
public ReinforcementLibUpdateStrategy() : this(new LibMaterialUpdateStrategy())
|
public ReinforcementLibUpdateStrategy()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,7 +24,7 @@ namespace StructureHelperLogics.Models.Materials
|
|||||||
CheckObject.ThrowIfNull(sourceObject);
|
CheckObject.ThrowIfNull(sourceObject);
|
||||||
CheckObject.ThrowIfNull(targetObject);
|
CheckObject.ThrowIfNull(targetObject);
|
||||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||||
libUpdateStrategy.Update(targetObject, sourceObject);
|
LibUpdateStrategy.Update(targetObject, sourceObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
using StructureHelperCommon.Models.Materials;
|
using StructureHelperCommon.Models.Materials;
|
||||||
using StructureHelperCommon.Services;
|
using StructureHelperCommon.Services;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace StructureHelperLogics.Models.Materials
|
namespace StructureHelperLogics.Models.Materials
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
|
|||||||
|
|
||||||
private static ForceCalculator GetForceCalculator()
|
private static ForceCalculator GetForceCalculator()
|
||||||
{
|
{
|
||||||
return new ForceCalculator()
|
return new ForceCalculator(Guid.NewGuid())
|
||||||
{
|
{
|
||||||
Name = "New Force Calculator",
|
Name = "New Force Calculator",
|
||||||
TraceLogger = new ShiftTraceLogger()
|
TraceLogger = new ShiftTraceLogger()
|
||||||
@@ -44,9 +44,9 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
|
|||||||
var newInputData = new CrackCalculatorInputData();
|
var newInputData = new CrackCalculatorInputData();
|
||||||
var checkLogic = new CheckCrackCalculatorInputDataLogic
|
var checkLogic = new CheckCrackCalculatorInputDataLogic
|
||||||
{
|
{
|
||||||
InputData = newInputData
|
Entity = newInputData
|
||||||
};
|
};
|
||||||
checkLogic.InputData = newInputData;
|
checkLogic.Entity = newInputData;
|
||||||
var crackCalculator = new CrackCalculator(checkLogic, new CrackCalculatorUpdateStrategy(), null)
|
var crackCalculator = new CrackCalculator(checkLogic, new CrackCalculatorUpdateStrategy(), null)
|
||||||
{
|
{
|
||||||
Name = "New Crack Calculator",
|
Name = "New Crack Calculator",
|
||||||
|
|||||||
@@ -8,14 +8,17 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
|||||||
{
|
{
|
||||||
public class ForceCalculator : IForceCalculator
|
public class ForceCalculator : IForceCalculator
|
||||||
{
|
{
|
||||||
private IUpdateStrategy<IForceCalculator> updateStrategy;
|
private ICheckInputDataLogic<IForceCalculatorInputData>? checkInputDataLogic;
|
||||||
private ICheckInputDataLogic<IForceCalculatorInputData> checkInputDataLogic;
|
private IForceCalculatorLogic? forceCalculatorLogic;
|
||||||
private IForceCalculatorLogic forceCalculatorLogic;
|
private IUpdateStrategy<IForceCalculator>? updateStrategy;
|
||||||
|
private ICheckInputDataLogic<IForceCalculatorInputData> CheckInputDataLogic => checkInputDataLogic ??= new CheckForceCalculatorInputData();
|
||||||
|
private IForceCalculatorLogic ForceCalculatorLogic => forceCalculatorLogic ??= new ForceCalculatorLogic();
|
||||||
|
private IUpdateStrategy<IForceCalculator> UpdateStrategy => updateStrategy ??= new ForceCalculatorUpdateStrategy();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public Guid Id { get; } = Guid.NewGuid();
|
public Guid Id { get; } = Guid.NewGuid();
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; } = string.Empty;
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IForceCalculatorInputData InputData { get; set; } = new ForceCalculatorInputData();
|
public IForceCalculatorInputData InputData { get; set; } = new ForceCalculatorInputData();
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -37,14 +40,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
|||||||
this.updateStrategy = updateStrategy;
|
this.updateStrategy = updateStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForceCalculator() :
|
public ForceCalculator(Guid id)
|
||||||
this(new CheckForceCalculatorInputData(),
|
|
||||||
new ForceCalculatorLogic(),
|
|
||||||
new ForceCalculatorUpdateStrategy())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForceCalculator(Guid id) : this()
|
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
}
|
}
|
||||||
@@ -52,30 +48,30 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
|||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Service);
|
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Service);
|
||||||
checkInputDataLogic.InputData = InputData;
|
CheckInputDataLogic.InputData = InputData;
|
||||||
checkInputDataLogic.TraceLogger = TraceLogger;
|
CheckInputDataLogic.TraceLogger = TraceLogger;
|
||||||
if (checkInputDataLogic.Check() != true)
|
if (CheckInputDataLogic.Check() != true)
|
||||||
{
|
{
|
||||||
Result = new ForceCalculatorResult()
|
Result = new ForceCalculatorResult()
|
||||||
{
|
{
|
||||||
IsValid = false,
|
IsValid = false,
|
||||||
Description = checkInputDataLogic.CheckResult
|
Description = CheckInputDataLogic.CheckResult
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forceCalculatorLogic.InputData = InputData;
|
ForceCalculatorLogic.InputData = InputData;
|
||||||
if (ActionToOutputResults is not null)
|
if (ActionToOutputResults is not null)
|
||||||
{
|
{
|
||||||
forceCalculatorLogic.ActionToOutputResults = ActionToOutputResults;
|
ForceCalculatorLogic.ActionToOutputResults = ActionToOutputResults;
|
||||||
}
|
}
|
||||||
forceCalculatorLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
ForceCalculatorLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
||||||
Result = forceCalculatorLogic.GetForcesResults();
|
Result = ForceCalculatorLogic.GetForcesResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Clone()
|
public object Clone()
|
||||||
{
|
{
|
||||||
var newCalculator = new ForceCalculator();
|
var newCalculator = new ForceCalculator(Guid.NewGuid());
|
||||||
updateStrategy.Update(newCalculator, this);
|
UpdateStrategy.Update(newCalculator, this);
|
||||||
return newCalculator;
|
return newCalculator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using StructureHelperCommon.Infrastructures.Interfaces;
|
|||||||
using StructureHelperCommon.Models;
|
using StructureHelperCommon.Models;
|
||||||
using StructureHelperCommon.Models.Forces.Logics;
|
using StructureHelperCommon.Models.Forces.Logics;
|
||||||
using StructureHelperCommon.Models.Loggers;
|
using StructureHelperCommon.Models.Loggers;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Cracking.CheckLogics;
|
||||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||||
using StructureHelperLogics.NdmCalculations.Primitives.Logics;
|
using StructureHelperLogics.NdmCalculations.Primitives.Logics;
|
||||||
|
|
||||||
@@ -11,57 +12,65 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logic of checking of input data for crack calcultor
|
/// Logic of checking of input data for crack calcultor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CheckCrackCalculatorInputDataLogic : ICheckInputDataLogic<ICrackCalculatorInputData>
|
public class CheckCrackCalculatorInputDataLogic : CheckEntityLogic<ICrackCalculatorInputData>
|
||||||
{
|
{
|
||||||
private bool result;
|
private bool result;
|
||||||
private ICheckEntityLogic<IHasPrimitives> checkPrimitiveCollectionLogic;
|
private ICheckEntityLogic<IHasPrimitives> checkPrimitiveCollectionLogic;
|
||||||
|
private ICheckEntityLogic<IEnumerable<INdmPrimitive>> checkMaterialsForCrackingLogic;
|
||||||
public ICrackCalculatorInputData InputData { get; set; }
|
private ICheckEntityLogic<IEnumerable<INdmPrimitive>> CheckMaterialsForCrackingLogic => checkMaterialsForCrackingLogic ??= new PrimitivesForCrackMaterialCheckLogic();
|
||||||
|
private ICheckEntityLogic<IHasPrimitives> CheckPrimitiveCollectionLogic => checkPrimitiveCollectionLogic ??= new HasPrimitivesCheckLogic() ;
|
||||||
|
|
||||||
public string CheckResult { get; private set; }
|
|
||||||
|
|
||||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
|
||||||
|
|
||||||
public CheckCrackCalculatorInputDataLogic(ICheckEntityLogic<IHasPrimitives> checkPrimitiveCollectionLogic)
|
public CheckCrackCalculatorInputDataLogic(ICheckEntityLogic<IHasPrimitives> checkPrimitiveCollectionLogic)
|
||||||
{
|
{
|
||||||
this.checkPrimitiveCollectionLogic = checkPrimitiveCollectionLogic;
|
this.checkPrimitiveCollectionLogic = checkPrimitiveCollectionLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CheckCrackCalculatorInputDataLogic() : this (new HasPrimitivesCheckLogic())
|
public CheckCrackCalculatorInputDataLogic()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Check()
|
public override bool Check()
|
||||||
{
|
{
|
||||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
|
||||||
result = true;
|
result = true;
|
||||||
CheckResult = string.Empty;
|
CheckResult = string.Empty;
|
||||||
|
CheckCrackingMaterials();
|
||||||
CheckPrimitives();
|
CheckPrimitives();
|
||||||
CheckActions();
|
CheckActions();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CheckCrackingMaterials()
|
||||||
|
{
|
||||||
|
CheckMaterialsForCrackingLogic.TraceLogger = TraceLogger;
|
||||||
|
CheckMaterialsForCrackingLogic.Entity = Entity.Primitives;
|
||||||
|
if (CheckMaterialsForCrackingLogic.Check() == false)
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
CheckResult += CheckMaterialsForCrackingLogic.CheckResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckPrimitives()
|
private void CheckPrimitives()
|
||||||
{
|
{
|
||||||
if (checkPrimitiveCollectionLogic is null)
|
if (CheckPrimitiveCollectionLogic is null)
|
||||||
{
|
{
|
||||||
throw new StructureHelperException(ErrorStrings.ParameterIsNull + ": check primitive logic");
|
throw new StructureHelperException(ErrorStrings.ParameterIsNull + ": check primitive logic");
|
||||||
}
|
}
|
||||||
checkPrimitiveCollectionLogic.Entity = InputData;
|
CheckPrimitiveCollectionLogic.Entity = Entity;
|
||||||
checkPrimitiveCollectionLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger();
|
CheckPrimitiveCollectionLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger();
|
||||||
if (checkPrimitiveCollectionLogic.Check() == false)
|
if (CheckPrimitiveCollectionLogic.Check() == false)
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
CheckResult += checkPrimitiveCollectionLogic.CheckResult;
|
CheckResult += CheckPrimitiveCollectionLogic.CheckResult;
|
||||||
TraceLogger?.AddMessage(checkPrimitiveCollectionLogic.CheckResult, TraceLogStatuses.Error);
|
TraceLogger?.AddMessage(CheckPrimitiveCollectionLogic.CheckResult, TraceLogStatuses.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckActions()
|
private void CheckActions()
|
||||||
{
|
{
|
||||||
if (InputData.ForceActions is null || (!InputData.ForceActions.Any()))
|
if (Entity.ForceActions is null || (!Entity.ForceActions.Any()))
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
string message = "Calculator does not contain any actions\n";
|
string message = "Calculator does not contain any actions\n";
|
||||||
@@ -71,7 +80,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
};
|
};
|
||||||
var checkLogic = new CheckForceActionsLogic(TraceLogger)
|
var checkLogic = new CheckForceActionsLogic(TraceLogger)
|
||||||
{
|
{
|
||||||
Entity = InputData.ForceActions
|
Entity = Entity.ForceActions
|
||||||
};
|
};
|
||||||
if (checkLogic.Check() == false)
|
if (checkLogic.Check() == false)
|
||||||
{
|
{
|
||||||
@@ -84,7 +93,5 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
CheckResult += errorString + "\n";
|
CheckResult += errorString + "\n";
|
||||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using LoaderCalculator.Data.Materials;
|
||||||
|
using StructureHelperCommon.Infrastructures.Enums;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||||
|
|
||||||
|
namespace StructureHelperLogics.NdmCalculations.Cracking.CheckLogics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether a collection of NDM primitives contains
|
||||||
|
/// at least one material that supports crack appearance.
|
||||||
|
/// </summary>
|
||||||
|
public class PrimitivesForCrackMaterialCheckLogic
|
||||||
|
: CheckEntityLogic<IEnumerable<INdmPrimitive>>
|
||||||
|
{
|
||||||
|
public override bool Check()
|
||||||
|
{
|
||||||
|
if (Entity is null)
|
||||||
|
{
|
||||||
|
TraceMessage("Collection of primitives is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckResult = string.Empty;
|
||||||
|
|
||||||
|
bool hasCrackMaterial = Entity.Any(primitive =>
|
||||||
|
primitive?.NdmElement?.HeadMaterial?
|
||||||
|
.GetLoaderMaterial(LimitStates.SLS, CalcTerms.ShortTerm)
|
||||||
|
is ICrackMaterial);
|
||||||
|
|
||||||
|
if (!hasCrackMaterial)
|
||||||
|
{
|
||||||
|
TraceMessage(
|
||||||
|
"Collection of primitives does not have material which supports cracking");
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasCrackMaterial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,18 +1,11 @@
|
|||||||
using StructureHelperCommon.Infrastructures.Enums;
|
using StructureHelperCommon.Infrastructures.Enums;
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
using StructureHelperCommon.Infrastructures.Settings;
|
|
||||||
using StructureHelperCommon.Models;
|
using StructureHelperCommon.Models;
|
||||||
using StructureHelperCommon.Models.Calculators;
|
using StructureHelperCommon.Models.Calculators;
|
||||||
using StructureHelperCommon.Models.Forces;
|
|
||||||
using StructureHelperCommon.Models.Loggers;
|
using StructureHelperCommon.Models.Loggers;
|
||||||
using StructureHelperLogics.Models.Materials;
|
using StructureHelperLogics.Models.Materials;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StructureHelperLogics.NdmCalculations.Cracking
|
namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||||
{
|
{
|
||||||
@@ -24,20 +17,24 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
const CalcTerms shortTerm = CalcTerms.ShortTerm;
|
const CalcTerms shortTerm = CalcTerms.ShortTerm;
|
||||||
private const double maxSizeOfCrossSection = 1d;
|
private const double maxSizeOfCrossSection = 1d;
|
||||||
private CrackResult result;
|
private CrackResult result;
|
||||||
|
|
||||||
private IGetTupleInputDatasLogic datasLogic;
|
private IGetTupleInputDatasLogic datasLogic;
|
||||||
|
|
||||||
|
private ICheckEntityLogic<ICrackCalculatorInputData> checkInputDataLogic;
|
||||||
private IUpdateStrategy<ICrackCalculator> updateStrategy;
|
private IUpdateStrategy<ICrackCalculator> updateStrategy;
|
||||||
private ICheckInputDataLogic<ICrackCalculatorInputData> checkInputDataLogic;
|
private ICheckEntityLogic<ICrackCalculatorInputData> CheckInputDataLogic => checkInputDataLogic ??= new CheckCrackCalculatorInputDataLogic();
|
||||||
|
private IUpdateStrategy<ICrackCalculator> UpdateStrategy => updateStrategy ??= new CrackCalculatorUpdateStrategy();
|
||||||
|
|
||||||
public Guid Id { get; } = Guid.NewGuid();
|
public Guid Id { get; } = Guid.NewGuid();
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; } = string.Empty;
|
||||||
public ICrackCalculatorInputData InputData { get; set; }
|
public ICrackCalculatorInputData InputData { get; set; }
|
||||||
public IResult Result => result;
|
public IResult Result => result;
|
||||||
|
|
||||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||||
public bool ShowTraceData { get; set; }
|
public bool ShowTraceData { get; set; }
|
||||||
|
|
||||||
public CrackCalculator(ICheckInputDataLogic<ICrackCalculatorInputData> checkInputDataLogic,
|
public CrackCalculator(ICheckEntityLogic<ICrackCalculatorInputData> checkInputDataLogic,
|
||||||
IUpdateStrategy<ICrackCalculator> updateStrategy,
|
IUpdateStrategy<ICrackCalculator> updateStrategy,
|
||||||
IShiftTraceLogger traceLogger
|
IShiftTraceLogger traceLogger
|
||||||
)
|
)
|
||||||
@@ -45,18 +42,12 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
this.checkInputDataLogic = checkInputDataLogic;
|
this.checkInputDataLogic = checkInputDataLogic;
|
||||||
this.updateStrategy = updateStrategy;
|
this.updateStrategy = updateStrategy;
|
||||||
this.TraceLogger = traceLogger;
|
this.TraceLogger = traceLogger;
|
||||||
Name = string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrackCalculator()
|
public CrackCalculator(Guid id, IShiftTraceLogger traceLogger)
|
||||||
: this(new CheckCrackCalculatorInputDataLogic(),
|
|
||||||
new CrackCalculatorUpdateStrategy(),
|
|
||||||
new ShiftTraceLogger())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public CrackCalculator(Guid id) : this()
|
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
|
TraceLogger = traceLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Clone()
|
public object Clone()
|
||||||
@@ -64,18 +55,21 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
CrackCalculatorInputData crackInputData = new CrackCalculatorInputData();
|
CrackCalculatorInputData crackInputData = new CrackCalculatorInputData();
|
||||||
var checkDataLogic = new CheckCrackCalculatorInputDataLogic()
|
var checkDataLogic = new CheckCrackCalculatorInputDataLogic()
|
||||||
{
|
{
|
||||||
InputData = InputData
|
Entity = InputData
|
||||||
};
|
};
|
||||||
var newItem = new CrackCalculator(checkDataLogic, new CrackCalculatorUpdateStrategy(), new ShiftTraceLogger());
|
var newItem = new CrackCalculator(checkDataLogic, new CrackCalculatorUpdateStrategy(), new ShiftTraceLogger());
|
||||||
newItem.InputData = crackInputData;
|
newItem.InputData = crackInputData;
|
||||||
updateStrategy.Update(newItem, this);
|
UpdateStrategy.Update(newItem, this);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
PrepareNewResult();
|
PrepareNewResult();
|
||||||
CheckInputData();
|
if (CheckInputData() == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
TraceInputData();
|
TraceInputData();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -115,15 +109,17 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
|||||||
traceLogic.AddEntriesToTraceLogger(TraceLogger);
|
traceLogic.AddEntriesToTraceLogger(TraceLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckInputData()
|
private bool CheckInputData()
|
||||||
{
|
{
|
||||||
checkInputDataLogic.InputData = InputData;
|
CheckInputDataLogic.Entity = InputData;
|
||||||
checkInputDataLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
CheckInputDataLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
||||||
if (checkInputDataLogic.Check() == false)
|
if (CheckInputDataLogic.Check() == false)
|
||||||
{
|
{
|
||||||
result.IsValid = false;
|
result.IsValid = false;
|
||||||
result.Description += checkInputDataLogic.CheckResult;
|
result.Description += CheckInputDataLogic.CheckResult;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessCalculations()
|
private void ProcessCalculations()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace StructureHelperLogics.Services.NdmCalculations
|
|||||||
private static IForceTupleServiceLogic ForceTupleServiceLogic => forceTupleServiceLogic ??= new ForceTupleServiceLogic();
|
private static IForceTupleServiceLogic ForceTupleServiceLogic => forceTupleServiceLogic ??= new ForceTupleServiceLogic();
|
||||||
public static ForceCalculator InterpolateForceCalculator(IForceCalculator source, IStateCalcTermPair stateCalcTermPair, InterpolateTuplesResult interpolateTuplesResult)
|
public static ForceCalculator InterpolateForceCalculator(IForceCalculator source, IStateCalcTermPair stateCalcTermPair, InterpolateTuplesResult interpolateTuplesResult)
|
||||||
{
|
{
|
||||||
ForceCalculator calculator = new ForceCalculator();
|
ForceCalculator calculator = new ForceCalculator(Guid.NewGuid());
|
||||||
calculator.InputData.LimitStatesList.Clear();
|
calculator.InputData.LimitStatesList.Clear();
|
||||||
calculator.InputData.LimitStatesList.Add(stateCalcTermPair.LimitState);
|
calculator.InputData.LimitStatesList.Add(stateCalcTermPair.LimitState);
|
||||||
calculator.InputData.CalcTermsList.Clear();
|
calculator.InputData.CalcTermsList.Clear();
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models.Materials;
|
||||||
|
using StructureHelperLogics.Models.Materials;
|
||||||
|
|
||||||
|
namespace StructureHelperTests.UnitTests.MaterialTests
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class ConcreteLibUpdateStrategyTests
|
||||||
|
{
|
||||||
|
private Mock<IUpdateStrategy<ILibMaterial>> libUpdateStrategyMock;
|
||||||
|
private ConcreteLibUpdateStrategy strategy;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
libUpdateStrategyMock = new Mock<IUpdateStrategy<ILibMaterial>>();
|
||||||
|
strategy = new ConcreteLibUpdateStrategy(libUpdateStrategyMock.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_SourceIsNull_Throws()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var target = new Mock<IConcreteLibMaterial>().Object;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<StructureHelperException>(() =>
|
||||||
|
strategy.Update(target, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_TargetIsNull_Throws()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var source = new Mock<IConcreteLibMaterial>().Object;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<StructureHelperException>(() =>
|
||||||
|
strategy.Update(null, source));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_SourceAndTargetAreSameInstance_DoesNothing()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var materialMock = new Mock<IConcreteLibMaterial>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
strategy.Update(materialMock.Object, materialMock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
libUpdateStrategyMock.Verify(
|
||||||
|
x => x.Update(It.IsAny<ILibMaterial>(), It.IsAny<ILibMaterial>()),
|
||||||
|
Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_ValidObjects_UpdatesLibMaterialAndConcreteProperties()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var sourceMock = new Mock<IConcreteLibMaterial>();
|
||||||
|
var targetMock = new Mock<IConcreteLibMaterial>();
|
||||||
|
|
||||||
|
sourceMock.SetupGet(x => x.TensionForULS).Returns(false);
|
||||||
|
sourceMock.SetupGet(x => x.TensionForSLS).Returns(true);
|
||||||
|
sourceMock.SetupGet(x => x.RelativeHumidity).Returns(0.65);
|
||||||
|
sourceMock.SetupGet(x => x.MinAge).Returns(7);
|
||||||
|
sourceMock.SetupGet(x => x.MaxAge).Returns(365);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
strategy.Update(targetMock.Object, sourceMock.Object);
|
||||||
|
|
||||||
|
// Assert — lib material delegation
|
||||||
|
libUpdateStrategyMock.Verify(
|
||||||
|
x => x.Update(targetMock.Object, sourceMock.Object),
|
||||||
|
Times.Once);
|
||||||
|
|
||||||
|
// Assert — concrete-specific properties copied
|
||||||
|
targetMock.VerifySet(x => x.TensionForULS = false, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.TensionForSLS = true, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.RelativeHumidity = 0.65, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.MinAge = 7, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.MaxAge = 365, Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
using LoaderCalculator.Data.Materials;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using StructureHelper.Models.Materials;
|
||||||
|
using StructureHelperCommon.Infrastructures.Enums;
|
||||||
|
using StructureHelperCommon.Models;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Cracking.CheckLogics;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace StructureHelperTests.UnitTests.MaterialTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class PrimitivesForCrackMaterialCheckLogicTests
|
||||||
|
{
|
||||||
|
private Mock<IShiftTraceLogger> traceLoggerMock;
|
||||||
|
private PrimitivesForCrackMaterialCheckLogic logic;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
traceLoggerMock = new Mock<IShiftTraceLogger>();
|
||||||
|
|
||||||
|
logic = new PrimitivesForCrackMaterialCheckLogic
|
||||||
|
{
|
||||||
|
TraceLogger = traceLoggerMock.Object
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Check_EntityIsNull_ReturnsFalseAndTraces()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
logic.Entity = null;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
bool result = logic.Check();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.That(result, Is.False);
|
||||||
|
Assert.That(logic.CheckResult, Is.Not.Empty);
|
||||||
|
|
||||||
|
traceLoggerMock.Verify(
|
||||||
|
x => x.AddMessage(It.IsAny<string>()),
|
||||||
|
Times.AtLeastOnce);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Check_NoCrackMaterial_ReturnsFalseAndTraces()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
logic.Entity = new[]
|
||||||
|
{
|
||||||
|
CreatePrimitive(new Mock<IMaterial>().Object),
|
||||||
|
CreatePrimitive(new Mock<IMaterial>().Object)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
bool result = logic.Check();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.That(result, Is.False);
|
||||||
|
Assert.That(logic.CheckResult, Does.Contain("supports cracking"));
|
||||||
|
|
||||||
|
traceLoggerMock.Verify(
|
||||||
|
x => x.AddMessage(It.IsAny<string>()),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Check_WithCrackMaterial_ReturnsTrueAndDoesNotTrace()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
logic.Entity = new[]
|
||||||
|
{
|
||||||
|
CreatePrimitive(new Mock<IMaterial>().Object),
|
||||||
|
CreatePrimitive(new Mock<ICrackMaterial>().Object)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
bool result = logic.Check();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.That(result, Is.True);
|
||||||
|
Assert.That(logic.CheckResult, Is.Empty);
|
||||||
|
|
||||||
|
traceLoggerMock.Verify(
|
||||||
|
x => x.AddMessage(It.IsAny<string>()),
|
||||||
|
Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- helper ----------
|
||||||
|
|
||||||
|
private static INdmPrimitive CreatePrimitive(IMaterial material)
|
||||||
|
{
|
||||||
|
var headMaterialMock = new Mock<IHeadMaterial>();
|
||||||
|
headMaterialMock
|
||||||
|
.Setup(x => x.GetLoaderMaterial(LimitStates.SLS, CalcTerms.ShortTerm))
|
||||||
|
.Returns(material);
|
||||||
|
|
||||||
|
var ndmElementMock = new Mock<INdmElement>();
|
||||||
|
ndmElementMock
|
||||||
|
.SetupGet(x => x.HeadMaterial)
|
||||||
|
.Returns(headMaterialMock.Object);
|
||||||
|
|
||||||
|
var primitiveMock = new Mock<INdmPrimitive>();
|
||||||
|
primitiveMock
|
||||||
|
.SetupGet(x => x.NdmElement)
|
||||||
|
.Returns(ndmElementMock.Object);
|
||||||
|
|
||||||
|
return primitiveMock.Object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models.Materials;
|
||||||
|
using StructureHelperLogics.Models.Materials;
|
||||||
|
|
||||||
|
namespace StructureHelperTests.UnitTests.MaterialTests
|
||||||
|
{
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class ReinforcementLibUpdateStrategyTests
|
||||||
|
{
|
||||||
|
private Mock<IUpdateStrategy<ILibMaterial>> libUpdateStrategyMock;
|
||||||
|
private ReinforcementLibUpdateStrategy strategy;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
libUpdateStrategyMock = new Mock<IUpdateStrategy<ILibMaterial>>();
|
||||||
|
strategy = new ReinforcementLibUpdateStrategy(libUpdateStrategyMock.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_SourceIsNull_Throws()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var target = new Mock<IReinforcementLibMaterial>().Object;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<StructureHelperException>(() =>
|
||||||
|
strategy.Update(target, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_TargetIsNull_Throws()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var source = new Mock<IReinforcementLibMaterial>().Object;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<StructureHelperException>(() =>
|
||||||
|
strategy.Update(null, source));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_SourceAndTargetAreSameInstance_DoesNothing()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var materialMock = new Mock<IReinforcementLibMaterial>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
strategy.Update(materialMock.Object, materialMock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
libUpdateStrategyMock.Verify(
|
||||||
|
x => x.Update(It.IsAny<ILibMaterial>(), It.IsAny<ILibMaterial>()),
|
||||||
|
Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_ValidObjects_DelegatesToLibMaterialUpdateStrategy()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var sourceMock = new Mock<IReinforcementLibMaterial>();
|
||||||
|
var targetMock = new Mock<IReinforcementLibMaterial>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
strategy.Update(targetMock.Object, sourceMock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
libUpdateStrategyMock.Verify(
|
||||||
|
x => x.Update(targetMock.Object, sourceMock.Object),
|
||||||
|
Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Models.Materials;
|
||||||
|
using StructureHelperLogics.Models.Materials;
|
||||||
|
|
||||||
|
namespace StructureHelperTests.UnitTests.MaterialTests
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class SteelLibMaterialUpdateStrategyTests
|
||||||
|
{
|
||||||
|
private Mock<IUpdateStrategy<ILibMaterial>> libUpdateStrategyMock;
|
||||||
|
private SteelLibMaterialUpdateStrategy strategy;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
libUpdateStrategyMock = new Mock<IUpdateStrategy<ILibMaterial>>();
|
||||||
|
strategy = new SteelLibMaterialUpdateStrategy(libUpdateStrategyMock.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_SourceIsNull_Throws()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var target = new Mock<ISteelLibMaterial>().Object;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<StructureHelperException>(() =>
|
||||||
|
strategy.Update(target, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_TargetIsNull_Throws()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var source = new Mock<ISteelLibMaterial>().Object;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<StructureHelperException>(() =>
|
||||||
|
strategy.Update(null, source));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_SourceAndTargetAreSameInstance_DoesNothing()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var materialMock = new Mock<ISteelLibMaterial>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
strategy.Update(materialMock.Object, materialMock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
libUpdateStrategyMock.Verify(
|
||||||
|
x => x.Update(It.IsAny<ILibMaterial>(), It.IsAny<ILibMaterial>()),
|
||||||
|
Times.Never);
|
||||||
|
|
||||||
|
materialMock.VerifySet(x => x.MaxPlasticStrainRatio = It.IsAny<double>(), Times.Never);
|
||||||
|
materialMock.VerifySet(x => x.UlsFactor = It.IsAny<double>(), Times.Never);
|
||||||
|
materialMock.VerifySet(x => x.ThicknessFactor = It.IsAny<double>(), Times.Never);
|
||||||
|
materialMock.VerifySet(x => x.WorkConditionFactor = It.IsAny<double>(), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Update_ValidObjects_UpdatesLibMaterialAndSteelProperties()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var sourceMock = new Mock<ISteelLibMaterial>();
|
||||||
|
var targetMock = new Mock<ISteelLibMaterial>();
|
||||||
|
|
||||||
|
sourceMock.SetupGet(x => x.MaxPlasticStrainRatio).Returns(1.1);
|
||||||
|
sourceMock.SetupGet(x => x.UlsFactor).Returns(1.2);
|
||||||
|
sourceMock.SetupGet(x => x.ThicknessFactor).Returns(1.3);
|
||||||
|
sourceMock.SetupGet(x => x.WorkConditionFactor).Returns(1.4);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
strategy.Update(targetMock.Object, sourceMock.Object);
|
||||||
|
|
||||||
|
// Assert — lib material update
|
||||||
|
libUpdateStrategyMock.Verify(
|
||||||
|
x => x.Update(targetMock.Object, sourceMock.Object),
|
||||||
|
Times.Once);
|
||||||
|
|
||||||
|
// Assert — steel-specific properties
|
||||||
|
targetMock.VerifySet(x => x.MaxPlasticStrainRatio = 1.1, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.UlsFactor = 1.2, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.ThicknessFactor = 1.3, Times.Once);
|
||||||
|
targetMock.VerifySet(x => x.WorkConditionFactor = 1.4, Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
|
||||||
using StructureHelperCommon.Models.Materials;
|
|
||||||
using StructureHelperLogics.Models.Materials;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace StructureHelperTests.UnitTests.UpdateStrategiesTests
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
namespace YourNamespace.Tests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class ConcreteLibUpdateStrategyTests
|
|
||||||
{
|
|
||||||
private Mock<IUpdateStrategy<ILibMaterial>> mockLibUpdateStrategy;
|
|
||||||
private ConcreteLibUpdateStrategy strategy;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
mockLibUpdateStrategy = new Mock<IUpdateStrategy<ILibMaterial>>();
|
|
||||||
strategy = new ConcreteLibUpdateStrategy(mockLibUpdateStrategy.Object);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Update_ShouldUpdateTargetObject_WhenSourceAndTargetAreNotTheSame()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var targetMock = new Mock<IConcreteLibMaterial>();
|
|
||||||
var sourceMock = new Mock<IConcreteLibMaterial>();
|
|
||||||
|
|
||||||
sourceMock.Setup(s => s.TensionForULS).Returns(false);
|
|
||||||
sourceMock.Setup(s => s.TensionForSLS).Returns(true);
|
|
||||||
sourceMock.Setup(s => s.RelativeHumidity).Returns(0.75);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
strategy.Update(targetMock.Object, sourceMock.Object);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
mockLibUpdateStrategy.Verify(l => l.Update(targetMock.Object, sourceMock.Object), Times.Once);
|
|
||||||
targetMock.VerifySet(t => t.TensionForULS = false);
|
|
||||||
targetMock.VerifySet(t => t.TensionForSLS = true);
|
|
||||||
targetMock.VerifySet(t => t.RelativeHumidity = 0.75);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Update_ShouldNotUpdate_WhenSourceAndTargetAreSame()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var targetMock = new Mock<IConcreteLibMaterial>();
|
|
||||||
|
|
||||||
// Act
|
|
||||||
strategy.Update(targetMock.Object, targetMock.Object);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
mockLibUpdateStrategy.Verify(l => l.Update(It.IsAny<IConcreteLibMaterial>(), It.IsAny<IConcreteLibMaterial>()), Times.Never);
|
|
||||||
targetMock.VerifySet(t => t.TensionForULS = It.IsAny<bool>(), Times.Never);
|
|
||||||
targetMock.VerifySet(t => t.TensionForSLS = It.IsAny<bool>(), Times.Never);
|
|
||||||
targetMock.VerifySet(t => t.RelativeHumidity = It.IsAny<double>(), Times.Never);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user