Add lib material tests
This commit is contained in:
@@ -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