Skip to content

Commit

Permalink
add and rework unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jul 3, 2024
1 parent 3e76cf5 commit ac348c6
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 74 deletions.
19 changes: 19 additions & 0 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Converters.Rhino7.T
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Speckle.Converters.RhinoShared", "DUI3-DX\Converters\Rhino\Speckle.Converters.RhinoShared\Speckle.Converters.RhinoShared.shproj", "{E1C43415-3200-45F4-8BF9-A4DD7D7F2ED9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Testing", "DUI3-DX\Sdk\Speckle.Testing\Speckle.Testing.csproj", "{407E5EB0-E86F-499E-9BC1-39FE818C55AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Mac|Any CPU = Debug Mac|Any CPU
Expand Down Expand Up @@ -2882,6 +2884,22 @@ Global
{DB892409-2185-4DDE-983E-F0DE4766129A}.Release|Any CPU.Build.0 = Release|Any CPU
{DB892409-2185-4DDE-983E-F0DE4766129A}.Release|x64.ActiveCfg = Release|Any CPU
{DB892409-2185-4DDE-983E-F0DE4766129A}.Release|x64.Build.0 = Release|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug Mac|x64.ActiveCfg = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug Mac|x64.Build.0 = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug|x64.ActiveCfg = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Debug|x64.Build.0 = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release Mac|Any CPU.Build.0 = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release Mac|x64.ActiveCfg = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release Mac|x64.Build.0 = Debug|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release|Any CPU.Build.0 = Release|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release|x64.ActiveCfg = Release|Any CPU
{407E5EB0-E86F-499E-9BC1-39FE818C55AC}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -3099,6 +3117,7 @@ Global
{99C39008-706C-45B9-8E7E-9D9B8928A278} = {D92751C8-1039-4005-90B2-913E55E0B8BD}
{DB892409-2185-4DDE-983E-F0DE4766129A} = {34C2C062-E43F-4FB5-B839-64BC044CCEF3}
{E1C43415-3200-45F4-8BF9-A4DD7D7F2ED9} = {34C2C062-E43F-4FB5-B839-64BC044CCEF3}
{407E5EB0-E86F-499E-9BC1-39FE818C55AC} = {2E00592E-558D-492D-88F9-3ECEE4C0C7DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D43D91B-4F01-4A78-8250-CC6F9BD93A14}
Expand Down
3 changes: 2 additions & 1 deletion DUI3-DX.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"DUI3-DX\\Sdk\\Speckle.Autofac\\Speckle.Autofac.csproj",
"DUI3-DX\\Sdk\\Speckle.Connectors.Utils\\Speckle.Connectors.Utils.csproj",
"DUI3-DX\\Sdk\\Speckle.Converters.Common.DependencyInjection\\Speckle.Converters.Common.DependencyInjection.csproj",
"DUI3-DX\\Sdk\\Speckle.Converters.Common\\Speckle.Converters.Common.csproj"
"DUI3-DX\\Sdk\\Speckle.Converters.Common\\Speckle.Converters.Common.csproj",
"DUI3-DX\\Sdk\\Speckle.Testing\\Speckle.Testing.csproj"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,87 +1,75 @@
using System.Collections;
using FluentAssertions;
using Moq;
using FluentAssertions;
using NUnit.Framework;
using Objects;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.Raw;
using Speckle.Converters.RevitShared.Services;
using Speckle.Testing;

namespace Speckle.Converters.Revit2023.Tests;

public class ModelCurveArrayToSpeckleConverterTests
public class ModelCurveArrayToSpeckleConverterTests: MoqTest
{
private MockRepository _repository;

private Mock<IRevitConversionContextStack> _revitConversionContextStack;
private Mock<IScalingServiceToSpeckle> _scalingServiceToSpeckle;
private Mock<ITypedConverter<DB.Curve, ICurve>> _curveConverter;

[SetUp]
public void Start()
{
_repository = new(MockBehavior.Strict);
_revitConversionContextStack = _repository.Create<IRevitConversionContextStack>();
_scalingServiceToSpeckle = _repository.Create<IScalingServiceToSpeckle>();
_curveConverter = _repository.Create<ITypedConverter<DB.Curve, ICurve>>();
}

[TearDown]
public void Verify() => _repository.VerifyAll();

[Test]
public void Convert_Empty()
{
var revitConversionContextStack = Create<IRevitConversionContextStack>();
var scalingServiceToSpeckle = Create<IScalingServiceToSpeckle>();
var curveConverter = Create<ITypedConverter<DB.Curve, ICurve>>();

var sut = new ModelCurveArrayToSpeckleConverter(
_revitConversionContextStack.Object,
_scalingServiceToSpeckle.Object,
_curveConverter.Object
revitConversionContextStack.Object,
scalingServiceToSpeckle.Object,
curveConverter.Object
);
var array = _repository.Create<DB.ModelCurveArray>();
var array = Create<DB.ModelCurveArray>();
array.Setup(x => x.GetEnumerator()).Returns(Enumerable.Empty<object>().GetEnumerator());
Assert.Throws<SpeckleConversionException>(() => sut.Convert(array.Object));
}

[Test]
public void Convert()
{
var endpoint1 = _repository.Create<DB.XYZ>();
var geometry1 = _repository.Create<DB.Curve>();
var curve1 = _repository.Create<DB.ModelCurve>();
var revitConversionContextStack = Create<IRevitConversionContextStack>();
var scalingServiceToSpeckle = Create<IScalingServiceToSpeckle>();
var curveConverter = Create<ITypedConverter<DB.Curve, ICurve>>();

var endpoint1 = Create<DB.XYZ>();
var geometry1 = Create<DB.Curve>();
var curve1 = Create<DB.ModelCurve>();
curve1.Setup(x => x.GeometryCurve).Returns(geometry1.Object);
geometry1.Setup(x => x.Length).Returns(2);
geometry1.Setup(x => x.GetEndPoint(0)).Returns(endpoint1.Object);

var endpoint2 = _repository.Create<DB.XYZ>();
var geometry2 = _repository.Create<DB.Curve>();
var curve2 = _repository.Create<DB.ModelCurve>();
var endpoint2 = Create<DB.XYZ>();
var geometry2 = Create<DB.Curve>();
var curve2 = Create<DB.ModelCurve>();
curve2.Setup(x => x.GeometryCurve).Returns(geometry2.Object);
geometry2.Setup(x => x.Length).Returns(3);
geometry2.Setup(x => x.GetEndPoint(1)).Returns(endpoint2.Object);

var context = _repository.Create<IConversionContext<DB.Document>>();
_revitConversionContextStack.Setup(x => x.Current).Returns(context.Object);
var context = Create<IConversionContext<DB.Document>>();
revitConversionContextStack.Setup(x => x.Current).Returns(context.Object);

var units = "units";
context.Setup(x => x.SpeckleUnits).Returns(units);

var scaleLength = 2.2;
_scalingServiceToSpeckle.Setup(x => x.ScaleLength(2 + 3)).Returns(scaleLength);
scalingServiceToSpeckle.Setup(x => x.ScaleLength(2 + 3)).Returns(scaleLength);

endpoint1.Setup(x => x.DistanceTo(endpoint2.Object)).Returns(4.4);

_curveConverter.Setup(x => x.Convert(geometry1.Object)).Returns(_repository.Create<ICurve>().Object);
_curveConverter.Setup(x => x.Convert(geometry2.Object)).Returns(_repository.Create<ICurve>().Object);
curveConverter.Setup(x => x.Convert(geometry1.Object)).Returns(Create<ICurve>().Object);
curveConverter.Setup(x => x.Convert(geometry2.Object)).Returns(Create<ICurve>().Object);

var sut = new ModelCurveArrayToSpeckleConverter(
_revitConversionContextStack.Object,
_scalingServiceToSpeckle.Object,
_curveConverter.Object
revitConversionContextStack.Object,
scalingServiceToSpeckle.Object,
curveConverter.Object
);
var array = _repository.Create<DB.ModelCurveArray>();
var array = Create<DB.ModelCurveArray>();

array
.Setup(x => x.GetEnumerator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common\Speckle.Converters.Common.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Testing\Speckle.Testing.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Speckle.Revit2023.Fakes" VersionOverride="[0.2.1-preview.4, 1.0.0)" />
<PackageReference Include="Speckle.Revit2023.Fakes" VersionOverride="[0.2.1-preview.5, 1.0.0)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
},
"Speckle.Revit2023.Fakes": {
"type": "Direct",
"requested": "[0.2.1-preview.4, 1.0.0)",
"resolved": "0.2.1-preview.4",
"contentHash": "ZyPgvJ5BfC/lF+40bb24OSE8k5taszGU1fLs21dEI5GDsVRfPgeMIXFXDdpjjqtEZQbeteCWfkY3ef5OpHgW2g==",
"requested": "[0.2.1-preview.5, 1.0.0)",
"resolved": "0.2.1-preview.5",
"contentHash": "J5IWMCdG+ENVlxFrGc6blG2skWU0f9RXyjsNVGTokmAgELXDKJjggkQhBsU+9hVJPjpyGM38uNgJ1NKWEaur2w==",
"dependencies": {
"System.Drawing.Common": "8.0.6"
}
Expand Down Expand Up @@ -480,6 +480,13 @@
"Speckle.Objects": "[3.0.1-alpha.14, )"
}
},
"speckle.testing": {
"type": "Project",
"dependencies": {
"Moq": "[4.20.70, )",
"NUnit": "[4.1.0, )"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "CentralTransitive",
"requested": "[7.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using Rhino;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.Rhino7.ToSpeckle.Raw;
using Speckle.Testing;

namespace Speckle.Converters.Rhino7.Tests;

public class ArcToSpeckleConverterTests : MoqTest
{
[Test]
public void Convert_ShouldConvertArcCorrectly()
{
// Arrange
var radius = 1.1d;
var mockPointConverter = Create<ITypedConverter<RG.Point3d, SOG.Point>>();
var mockPlaneConverter = Create<ITypedConverter<RG.Plane, SOG.Plane>>();
var mockBoxConverter = Create<ITypedConverter<RG.Box, SOG.Box>>();
var mockContextStack = Create<IConversionContextStack<RhinoDoc, UnitSystem>>();
var factory = Create<IBoxFactory>();


var context = Create<IConversionContext<RhinoDoc>>();
context.Setup(x => x.SpeckleUnits).Returns("units");
mockContextStack.Setup(cs => cs.Current).Returns(context.Object);

var targetArc = Create<RG.Arc>();
var targetPlane = Create<RG.Plane>();
var targetBox = Create<RG.Box>();
var point3d = Create<RG.Point3d>();
var boundbox = Create<RG.BoundingBox>();

targetArc.Setup(x => x.Plane).Returns(targetPlane.Object);
targetArc.Setup(x => x.Radius).Returns(radius);
targetArc.Setup(x => x.StartAngle).Returns(radius);
targetArc.Setup(x => x.EndAngle).Returns(radius);
targetArc.Setup(x => x.Angle).Returns(radius);
targetArc.Setup(x => x.Length).Returns(radius);
targetArc.Setup(x => x.StartPoint).Returns(point3d.Object);
targetArc.Setup(x => x.MidPoint).Returns(point3d.Object);
targetArc.Setup(x => x.EndPoint).Returns(point3d.Object);
targetArc.Setup(x => x.BoundingBox()).Returns(boundbox.Object);
factory.Setup(x => x.Create(boundbox.Object)).Returns(targetBox.Object);

mockPlaneConverter.Setup(pc => pc.Convert(targetPlane.Object)).Returns(new SOG.Plane());
mockPointConverter.Setup(pc => pc.Convert(It.IsAny<RG.Point3d>())).Returns(new SOG.Point());
mockBoxConverter.Setup(bc => bc.Convert(targetBox.Object)).Returns(new SOG.Box());

var converter = new ArcToSpeckleConverter(
mockPointConverter.Object,
mockPlaneConverter.Object,
mockBoxConverter.Object,
mockContextStack.Object,
factory.Object
);

// Act
var result = converter.Convert(targetArc.Object);

// Assert
result.Should().NotBeNull();
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
using Moq;
using NUnit.Framework;
using NUnit.Framework;
using Rhino;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.Rhino7.ToSpeckle.Raw;
using Speckle.Testing;

namespace Speckle.Converters.Rhino7.Tests;

public class EllipseToSpeckleConverterTests
public class EllipseToSpeckleConverterTests: MoqTest
{
private MockRepository _repository;

private Mock<IConversionContextStack<RhinoDoc, UnitSystem>> _conversionContextStack;

private Mock<ITypedConverter<RG.Plane, SOG.Plane>> _planeConverter;
private Mock<ITypedConverter<RG.Box, SOG.Box>> _boxConverter;

[SetUp]
public void Setup()
[Test]
public void Convert_Test()
{
_repository = new(MockBehavior.Strict);
_conversionContextStack = _repository.Create<IConversionContextStack<RhinoDoc, UnitSystem>>();
_planeConverter = _repository.Create<ITypedConverter<RG.Plane, SOG.Plane>>();
_boxConverter = _repository.Create<ITypedConverter<RG.Box, SOG.Box>>();
}
var conversionContextStack = Create<IConversionContextStack<RhinoDoc, UnitSystem>>();
var planeConverter = Create<ITypedConverter<RG.Plane, SOG.Plane>>();
var boxConverter = Create<ITypedConverter<RG.Box, SOG.Box>>();

[TearDown]
public void Verify() => _repository.VerifyAll();
var x = new EllipseToSpeckleConverter(planeConverter.Object, boxConverter.Object, conversionContextStack.Object);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -15,10 +15,11 @@
<Import Project="..\Speckle.Converters.RhinoShared\Speckle.Converters.RhinoShared.projitems" Label="Shared" />

<ItemGroup>
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common\Speckle.Converters.Common.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common\Speckle.Converters.Common.csproj" />
<ProjectReference Include="..\..\..\Sdk\Speckle.Testing\Speckle.Testing.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Speckle.Rhino7.Fakes" VersionOverride="0.2.1-preview.4" />
<PackageReference Include="Speckle.Rhino7.Fakes" VersionOverride="0.2.1-preview.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
},
"Speckle.Rhino7.Fakes": {
"type": "Direct",
"requested": "[0.2.1-preview.4, )",
"resolved": "0.2.1-preview.4",
"contentHash": "8o2pESS4SWjLG1nc62Jo1CzTbbwm8ad61KF1y2NVDUbbfzd4YPkY7VFF4zJUM3sW0pWhnkslOomOPblg9Px22Q==",
"requested": "[0.2.1-preview.5, )",
"resolved": "0.2.1-preview.5",
"contentHash": "ugh9ojdGDmtj8nXtPiSVMFxrr7eztUqyuNT8TYHflALOdphyd9663Q5MxUJT74D629W6BZhRefLaIPYH9FIxMQ==",
"dependencies": {
"System.Drawing.Common": "8.0.6"
}
Expand Down Expand Up @@ -480,6 +480,13 @@
"Speckle.Objects": "[3.0.1-alpha.14, )"
}
},
"speckle.testing": {
"type": "Project",
"dependencies": {
"Moq": "[4.20.70, )",
"NUnit": "[4.1.0, )"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "CentralTransitive",
"requested": "[7.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ public class ArcToSpeckleConverter : ITypedConverter<RG.Arc, SOG.Arc>
private readonly ITypedConverter<RG.Plane, SOG.Plane> _planeConverter;
private readonly ITypedConverter<RG.Box, SOG.Box> _boxConverter;
private readonly IConversionContextStack<RhinoDoc, UnitSystem> _contextStack;
private readonly IBoxFactory _boxFactory;

public ArcToSpeckleConverter(
ITypedConverter<RG.Point3d, SOG.Point> pointConverter,
ITypedConverter<RG.Plane, SOG.Plane> planeConverter,
ITypedConverter<RG.Box, SOG.Box> boxConverter,
IConversionContextStack<RhinoDoc, UnitSystem> contextStack
)
IConversionContextStack<RhinoDoc, UnitSystem> contextStack, IBoxFactory boxFactory)
{
_pointConverter = pointConverter;
_planeConverter = planeConverter;
_boxConverter = boxConverter;
_contextStack = contextStack;
_boxFactory = boxFactory;
}

/// <summary>
Expand All @@ -47,6 +48,6 @@ public SOG.Arc Convert(RG.Arc target) =>
endPoint = _pointConverter.Convert(target.EndPoint),
domain = new SOP.Interval(0, 1),
length = target.Length,
bbox = _boxConverter.Convert(new RG.Box(target.BoundingBox()))
bbox = _boxConverter.Convert(_boxFactory.Create(target.BoundingBox()))
};
}
Loading

0 comments on commit ac348c6

Please sign in to comment.