-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Revit 2023 and Rhino 7 Converter Tests with Fakes (#3)
* Moved code * update fakes * add code coverage * try code coverage again * fix test finding * still file problem? * try token a different way
- Loading branch information
1 parent
3cbed42
commit 91a69a8
Showing
98 changed files
with
1,414 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...erters/Revit/Speckle.Converters.Revit2023.Tests/ModelCurveArrayToSpeckleConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Collections; | ||
using FluentAssertions; | ||
using Moq; | ||
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; | ||
|
||
namespace Speckle.Converters.Revit2023.Tests; | ||
|
||
public class ModelCurveArrayToSpeckleConverterTests | ||
{ | ||
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 sut = new ModelCurveArrayToSpeckleConverter( | ||
_revitConversionContextStack.Object, | ||
_scalingServiceToSpeckle.Object, | ||
_curveConverter.Object | ||
); | ||
var array = _repository.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>(); | ||
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>(); | ||
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 units = "units"; | ||
context.Setup(x => x.SpeckleUnits).Returns(units); | ||
|
||
var scaleLength = 2.2; | ||
_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); | ||
|
||
var sut = new ModelCurveArrayToSpeckleConverter( | ||
_revitConversionContextStack.Object, | ||
_scalingServiceToSpeckle.Object, | ||
_curveConverter.Object | ||
); | ||
var array = _repository.Create<DB.ModelCurveArray>(); | ||
|
||
array | ||
.Setup(x => x.GetEnumerator()) | ||
.Returns(new List<DB.ModelCurve> { curve1.Object, curve2.Object }.GetEnumerator()); | ||
var polycurve = sut.Convert(array.Object); | ||
|
||
polycurve.units.Should().Be(units); | ||
polycurve.closed.Should().BeFalse(); | ||
polycurve.length.Should().Be(scaleLength); | ||
polycurve.segments.Count.Should().Be(2); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...erters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="altcover" /> | ||
<PackageReference Include="FluentAssertions" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="Moq" /> | ||
<PackageReference Include="NUnit" /> | ||
<PackageReference Include="NUnit.Analyzers" /> | ||
</ItemGroup> | ||
<Import Project="..\Speckle.Converters.RevitShared\Speckle.Converters.RevitShared.projitems" Label="Shared" /> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common\Speckle.Converters.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Speckle.Revit2023.Fakes" VersionOverride="[0.2.1-preview.6, 1.0.0)" /> | ||
</ItemGroup> | ||
</Project> |
61 changes: 61 additions & 0 deletions
61
Converters/Revit/Speckle.Converters.Revit2023.Tests/XyzConversionToPointTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using FluentAssertions; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.RevitShared.Helpers; | ||
using Speckle.Converters.RevitShared.Services; | ||
using Speckle.Converters.RevitShared.ToSpeckle; | ||
|
||
namespace Speckle.Converters.Revit2023.Tests; | ||
|
||
public class XyzConversionToPointTests | ||
{ | ||
private MockRepository _repository; | ||
|
||
private Mock<IRevitConversionContextStack> _revitConversionContextStack; | ||
private Mock<IScalingServiceToSpeckle> _scalingServiceToSpeckle; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_repository = new(MockBehavior.Strict); | ||
_revitConversionContextStack = _repository.Create<IRevitConversionContextStack>(); | ||
_scalingServiceToSpeckle = _repository.Create<IScalingServiceToSpeckle>(); | ||
} | ||
|
||
[TearDown] | ||
public void Verify() => _repository.VerifyAll(); | ||
|
||
[Test] | ||
public void Convert_Point() | ||
{ | ||
var x = 3.1; | ||
var y = 3.2; | ||
var z = 3.3; | ||
var xScaled = 4.1; | ||
var yScaled = 4.2; | ||
var zScaled = 4.3; | ||
var xyz = _repository.Create<DB.XYZ>(); | ||
xyz.Setup(x => x.X).Returns(x); | ||
xyz.Setup(x => x.Y).Returns(y); | ||
xyz.Setup(x => x.Z).Returns(z); | ||
|
||
var units = "units"; | ||
var conversionContext = _repository.Create<IConversionContext<DB.Document>>(); | ||
conversionContext.Setup(x => x.SpeckleUnits).Returns(units); | ||
|
||
_scalingServiceToSpeckle.Setup(a => a.ScaleLength(x)).Returns(xScaled); | ||
_scalingServiceToSpeckle.Setup(a => a.ScaleLength(y)).Returns(yScaled); | ||
_scalingServiceToSpeckle.Setup(a => a.ScaleLength(z)).Returns(zScaled); | ||
|
||
_revitConversionContextStack.Setup(x => x.Current).Returns(conversionContext.Object); | ||
|
||
var converter = new XyzConversionToPoint(_scalingServiceToSpeckle.Object, _revitConversionContextStack.Object); | ||
var point = converter.Convert(xyz.Object); | ||
|
||
point.x.Should().Be(xScaled); | ||
point.y.Should().Be(yScaled); | ||
point.z.Should().Be(zScaled); | ||
point.units.Should().Be(units); | ||
} | ||
} |
Oops, something went wrong.