Add lib material tests
This commit is contained in:
@@ -1,25 +1,21 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataAccess.DTOs
|
||||
{
|
||||
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)
|
||||
{
|
||||
NewItem = new(source.Id);
|
||||
NewItem = new(source.Id, new ShiftTraceLogger());
|
||||
NewItem.Name = source.Name;
|
||||
convertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
convertStrategy.TraceLogger = TraceLogger;
|
||||
NewItem.InputData = convertStrategy.Convert(source.InputData as CrackCalculatorInputDataDTO);
|
||||
ConvertStrategy.ReferenceDictionary = ReferenceDictionary;
|
||||
ConvertStrategy.TraceLogger = TraceLogger;
|
||||
NewItem.InputData = ConvertStrategy.Convert(source.InputData as CrackCalculatorInputDataDTO);
|
||||
return NewItem;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -92,7 +92,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
private void AddCrackCalculator()
|
||||
{
|
||||
var inputData = new CrackCalculatorInputData();
|
||||
var calculator = new CrackCalculator()
|
||||
var calculator = new CrackCalculator(Guid.NewGuid(), new ShiftTraceLogger())
|
||||
{
|
||||
Name = "New crack calculator",
|
||||
TraceLogger = new ShiftTraceLogger(),
|
||||
@@ -114,7 +114,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
|
||||
private void AddForceCalculator()
|
||||
{
|
||||
NewItem = new ForceCalculator()
|
||||
NewItem = new ForceCalculator(Guid.NewGuid())
|
||||
{
|
||||
Name = "New force calculator",
|
||||
TraceLogger = new ShiftTraceLogger(),
|
||||
|
||||
@@ -10,11 +10,12 @@ namespace StructureHelperLogics.Models.Materials
|
||||
public class ReinforcementLibUpdateStrategy : IUpdateStrategy<IReinforcementLibMaterial>
|
||||
{
|
||||
private IUpdateStrategy<ILibMaterial> libUpdateStrategy;
|
||||
private IUpdateStrategy<ILibMaterial> LibUpdateStrategy => libUpdateStrategy ??= new LibMaterialUpdateStrategy();
|
||||
public ReinforcementLibUpdateStrategy(IUpdateStrategy<ILibMaterial> libUpdateStrategy)
|
||||
{
|
||||
this.libUpdateStrategy = libUpdateStrategy;
|
||||
}
|
||||
public ReinforcementLibUpdateStrategy() : this(new LibMaterialUpdateStrategy())
|
||||
public ReinforcementLibUpdateStrategy()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -23,7 +24,7 @@ namespace StructureHelperLogics.Models.Materials
|
||||
CheckObject.ThrowIfNull(sourceObject);
|
||||
CheckObject.ThrowIfNull(targetObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
libUpdateStrategy.Update(targetObject, sourceObject);
|
||||
LibUpdateStrategy.Update(targetObject, sourceObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Materials;
|
||||
using StructureHelperCommon.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
|
||||
|
||||
private static ForceCalculator GetForceCalculator()
|
||||
{
|
||||
return new ForceCalculator()
|
||||
return new ForceCalculator(Guid.NewGuid())
|
||||
{
|
||||
Name = "New Force Calculator",
|
||||
TraceLogger = new ShiftTraceLogger()
|
||||
@@ -44,9 +44,9 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
|
||||
var newInputData = new CrackCalculatorInputData();
|
||||
var checkLogic = new CheckCrackCalculatorInputDataLogic
|
||||
{
|
||||
InputData = newInputData
|
||||
Entity = newInputData
|
||||
};
|
||||
checkLogic.InputData = newInputData;
|
||||
checkLogic.Entity = newInputData;
|
||||
var crackCalculator = new CrackCalculator(checkLogic, new CrackCalculatorUpdateStrategy(), null)
|
||||
{
|
||||
Name = "New Crack Calculator",
|
||||
|
||||
@@ -8,14 +8,17 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public class ForceCalculator : IForceCalculator
|
||||
{
|
||||
private IUpdateStrategy<IForceCalculator> updateStrategy;
|
||||
private ICheckInputDataLogic<IForceCalculatorInputData> checkInputDataLogic;
|
||||
private IForceCalculatorLogic forceCalculatorLogic;
|
||||
private ICheckInputDataLogic<IForceCalculatorInputData>? checkInputDataLogic;
|
||||
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/>
|
||||
public Guid Id { get; } = Guid.NewGuid();
|
||||
/// <inheritdoc/>
|
||||
public string Name { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
/// <inheritdoc/>
|
||||
public IForceCalculatorInputData InputData { get; set; } = new ForceCalculatorInputData();
|
||||
/// <inheritdoc/>
|
||||
@@ -37,14 +40,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public ForceCalculator() :
|
||||
this(new CheckForceCalculatorInputData(),
|
||||
new ForceCalculatorLogic(),
|
||||
new ForceCalculatorUpdateStrategy())
|
||||
{
|
||||
}
|
||||
|
||||
public ForceCalculator(Guid id) : this()
|
||||
public ForceCalculator(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
@@ -52,30 +48,30 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public void Run()
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Service);
|
||||
checkInputDataLogic.InputData = InputData;
|
||||
checkInputDataLogic.TraceLogger = TraceLogger;
|
||||
if (checkInputDataLogic.Check() != true)
|
||||
CheckInputDataLogic.InputData = InputData;
|
||||
CheckInputDataLogic.TraceLogger = TraceLogger;
|
||||
if (CheckInputDataLogic.Check() != true)
|
||||
{
|
||||
Result = new ForceCalculatorResult()
|
||||
{
|
||||
IsValid = false,
|
||||
Description = checkInputDataLogic.CheckResult
|
||||
Description = CheckInputDataLogic.CheckResult
|
||||
};
|
||||
return;
|
||||
}
|
||||
forceCalculatorLogic.InputData = InputData;
|
||||
ForceCalculatorLogic.InputData = InputData;
|
||||
if (ActionToOutputResults is not null)
|
||||
{
|
||||
forceCalculatorLogic.ActionToOutputResults = ActionToOutputResults;
|
||||
ForceCalculatorLogic.ActionToOutputResults = ActionToOutputResults;
|
||||
}
|
||||
forceCalculatorLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
||||
Result = forceCalculatorLogic.GetForcesResults();
|
||||
ForceCalculatorLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
||||
Result = ForceCalculatorLogic.GetForcesResults();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var newCalculator = new ForceCalculator();
|
||||
updateStrategy.Update(newCalculator, this);
|
||||
var newCalculator = new ForceCalculator(Guid.NewGuid());
|
||||
UpdateStrategy.Update(newCalculator, this);
|
||||
return newCalculator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Forces.Logics;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking.CheckLogics;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives.Logics;
|
||||
|
||||
@@ -11,57 +12,65 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
/// <summary>
|
||||
/// Logic of checking of input data for crack calcultor
|
||||
/// </summary>
|
||||
public class CheckCrackCalculatorInputDataLogic : ICheckInputDataLogic<ICrackCalculatorInputData>
|
||||
public class CheckCrackCalculatorInputDataLogic : CheckEntityLogic<ICrackCalculatorInputData>
|
||||
{
|
||||
private bool result;
|
||||
private ICheckEntityLogic<IHasPrimitives> checkPrimitiveCollectionLogic;
|
||||
|
||||
public ICrackCalculatorInputData InputData { get; set; }
|
||||
|
||||
|
||||
public string CheckResult { get; private set; }
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
private ICheckEntityLogic<IEnumerable<INdmPrimitive>> checkMaterialsForCrackingLogic;
|
||||
private ICheckEntityLogic<IEnumerable<INdmPrimitive>> CheckMaterialsForCrackingLogic => checkMaterialsForCrackingLogic ??= new PrimitivesForCrackMaterialCheckLogic();
|
||||
private ICheckEntityLogic<IHasPrimitives> CheckPrimitiveCollectionLogic => checkPrimitiveCollectionLogic ??= new HasPrimitivesCheckLogic() ;
|
||||
|
||||
public CheckCrackCalculatorInputDataLogic(ICheckEntityLogic<IHasPrimitives> 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);
|
||||
result = true;
|
||||
CheckResult = string.Empty;
|
||||
CheckCrackingMaterials();
|
||||
CheckPrimitives();
|
||||
CheckActions();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckCrackingMaterials()
|
||||
{
|
||||
CheckMaterialsForCrackingLogic.TraceLogger = TraceLogger;
|
||||
CheckMaterialsForCrackingLogic.Entity = Entity.Primitives;
|
||||
if (CheckMaterialsForCrackingLogic.Check() == false)
|
||||
{
|
||||
result = false;
|
||||
CheckResult += CheckMaterialsForCrackingLogic.CheckResult;
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckPrimitives()
|
||||
{
|
||||
if (checkPrimitiveCollectionLogic is null)
|
||||
if (CheckPrimitiveCollectionLogic is null)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ParameterIsNull + ": check primitive logic");
|
||||
}
|
||||
checkPrimitiveCollectionLogic.Entity = InputData;
|
||||
checkPrimitiveCollectionLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger();
|
||||
if (checkPrimitiveCollectionLogic.Check() == false)
|
||||
CheckPrimitiveCollectionLogic.Entity = Entity;
|
||||
CheckPrimitiveCollectionLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger();
|
||||
if (CheckPrimitiveCollectionLogic.Check() == false)
|
||||
{
|
||||
result = false;
|
||||
CheckResult += checkPrimitiveCollectionLogic.CheckResult;
|
||||
TraceLogger?.AddMessage(checkPrimitiveCollectionLogic.CheckResult, TraceLogStatuses.Error);
|
||||
CheckResult += CheckPrimitiveCollectionLogic.CheckResult;
|
||||
TraceLogger?.AddMessage(CheckPrimitiveCollectionLogic.CheckResult, TraceLogStatuses.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckActions()
|
||||
{
|
||||
if (InputData.ForceActions is null || (!InputData.ForceActions.Any()))
|
||||
if (Entity.ForceActions is null || (!Entity.ForceActions.Any()))
|
||||
{
|
||||
result = false;
|
||||
string message = "Calculator does not contain any actions\n";
|
||||
@@ -71,7 +80,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
};
|
||||
var checkLogic = new CheckForceActionsLogic(TraceLogger)
|
||||
{
|
||||
Entity = InputData.ForceActions
|
||||
Entity = Entity.ForceActions
|
||||
};
|
||||
if (checkLogic.Check() == false)
|
||||
{
|
||||
@@ -84,7 +93,5 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
CheckResult += errorString + "\n";
|
||||
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.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
{
|
||||
@@ -24,20 +17,24 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
const CalcTerms shortTerm = CalcTerms.ShortTerm;
|
||||
private const double maxSizeOfCrossSection = 1d;
|
||||
private CrackResult result;
|
||||
|
||||
private IGetTupleInputDatasLogic datasLogic;
|
||||
|
||||
private ICheckEntityLogic<ICrackCalculatorInputData> checkInputDataLogic;
|
||||
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 string Name { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public ICrackCalculatorInputData InputData { get; set; }
|
||||
public IResult Result => result;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
public bool ShowTraceData { get; set; }
|
||||
|
||||
public CrackCalculator(ICheckInputDataLogic<ICrackCalculatorInputData> checkInputDataLogic,
|
||||
public CrackCalculator(ICheckEntityLogic<ICrackCalculatorInputData> checkInputDataLogic,
|
||||
IUpdateStrategy<ICrackCalculator> updateStrategy,
|
||||
IShiftTraceLogger traceLogger
|
||||
)
|
||||
@@ -45,18 +42,12 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
this.checkInputDataLogic = checkInputDataLogic;
|
||||
this.updateStrategy = updateStrategy;
|
||||
this.TraceLogger = traceLogger;
|
||||
Name = string.Empty;
|
||||
}
|
||||
|
||||
public CrackCalculator()
|
||||
: this(new CheckCrackCalculatorInputDataLogic(),
|
||||
new CrackCalculatorUpdateStrategy(),
|
||||
new ShiftTraceLogger())
|
||||
{ }
|
||||
|
||||
public CrackCalculator(Guid id) : this()
|
||||
public CrackCalculator(Guid id, IShiftTraceLogger traceLogger)
|
||||
{
|
||||
Id = id;
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
@@ -64,18 +55,21 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
CrackCalculatorInputData crackInputData = new CrackCalculatorInputData();
|
||||
var checkDataLogic = new CheckCrackCalculatorInputDataLogic()
|
||||
{
|
||||
InputData = InputData
|
||||
Entity = InputData
|
||||
};
|
||||
var newItem = new CrackCalculator(checkDataLogic, new CrackCalculatorUpdateStrategy(), new ShiftTraceLogger());
|
||||
newItem.InputData = crackInputData;
|
||||
updateStrategy.Update(newItem, this);
|
||||
UpdateStrategy.Update(newItem, this);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
PrepareNewResult();
|
||||
CheckInputData();
|
||||
if (CheckInputData() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TraceInputData();
|
||||
try
|
||||
{
|
||||
@@ -115,15 +109,17 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
traceLogic.AddEntriesToTraceLogger(TraceLogger);
|
||||
}
|
||||
|
||||
private void CheckInputData()
|
||||
private bool CheckInputData()
|
||||
{
|
||||
checkInputDataLogic.InputData = InputData;
|
||||
checkInputDataLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
||||
if (checkInputDataLogic.Check() == false)
|
||||
CheckInputDataLogic.Entity = InputData;
|
||||
CheckInputDataLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger(50);
|
||||
if (CheckInputDataLogic.Check() == false)
|
||||
{
|
||||
result.IsValid = false;
|
||||
result.Description += checkInputDataLogic.CheckResult;
|
||||
result.Description += CheckInputDataLogic.CheckResult;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ProcessCalculations()
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace StructureHelperLogics.Services.NdmCalculations
|
||||
private static IForceTupleServiceLogic ForceTupleServiceLogic => forceTupleServiceLogic ??= new ForceTupleServiceLogic();
|
||||
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.Add(stateCalcTermPair.LimitState);
|
||||
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