using Moq; using NUnit.Framework; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models; using StructureHelperLogics.Models.BeamShears; namespace StructureHelperTests.UnitTests.BeamShearTests { [TestFixture] public class BeamShearStrengthByStirrupDensityTests { private Mock _mockStirrupEffectiveness; private Mock _mockStirrupByDensity; private Mock _mockInclinedSection; private Mock _mockTraceLogger; private BeamShearStrengthByStirrupDensityLogic _beamShearStrength; [SetUp] public void Setup() { _mockStirrupEffectiveness = new Mock(); _mockStirrupByDensity = new Mock(); _mockInclinedSection = new Mock(); _mockTraceLogger = new Mock(); _beamShearStrength = new BeamShearStrengthByStirrupDensityLogic( _mockStirrupEffectiveness.Object, _mockStirrupByDensity.Object, _mockInclinedSection.Object, _mockTraceLogger.Object ); } [Test] public void GetShearStrength_CalculatesCorrectly() { // Arrange _mockInclinedSection.Setup(s => s.StartCoord).Returns(1.0); _mockInclinedSection.Setup(s => s.EndCoord).Returns(3.0); _mockInclinedSection.Setup(s => s.EffectiveDepth).Returns(2.0); _mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(0.5); _mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(1.2); _mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(1.1); _mockStirrupByDensity.Setup(s => s.StirrupDensity).Returns(4.0); double expectedStrength = 1.2 * 1.1 * 1.0 * 4.0; // Min(2.0, 1.0) = 1.0 // Act double result = _beamShearStrength.GetShearStrength(); // Assert Assert.That(result, Is.EqualTo(expectedStrength).Within(1e-6)); _mockTraceLogger.Verify(t => t.AddMessage(It.IsAny(), It.IsAny()), Times.AtLeastOnce); } [Test] public void GetShearStrength_ThrowsException_WhenDependenciesAreNull() { // Arrange var invalidInstance = new BeamShearStrengthByStirrupDensityLogic( _mockStirrupEffectiveness.Object, null, // Invalid _mockInclinedSection.Object, _mockTraceLogger.Object ); // Act & Assert Assert.Throws(() => invalidInstance.GetShearStrength()); } } }