Skip to content

Commit

Permalink
Add Revit 2023 and Rhino 7 Converter Tests with Fakes (#3)
Browse files Browse the repository at this point in the history
* 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
adamhathcock authored Jul 4, 2024
1 parent 3cbed42 commit 91a69a8
Show file tree
Hide file tree
Showing 98 changed files with 1,414 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ jobs:

- name: ⚒️ Run build
run: ./build.ps1

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v4
with:
files: ./**/*.Tests/coverage.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: ⬆️ Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
1 change: 0 additions & 1 deletion Build/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public static class Consts
{
public static readonly string[] Solutions = ["Speckle.Connectors.sln" ];
public static readonly string[] TestProjects = [];

public static readonly InstallerProject[] InstallerManifests =
{
Expand Down
15 changes: 4 additions & 11 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void RemoveDirectory(string d)

Target(
RESTORE,
DependsOn(FORMAT),
Consts.Solutions,
s =>
{
Expand Down Expand Up @@ -111,18 +112,10 @@ void RemoveDirectory(string d)
Target(
TEST,
DependsOn(BUILD),
Consts.TestProjects,
t =>
Glob.Files(".", "**/*.Tests.csproj"),
file =>
{
IEnumerable<string> GetFiles(string d)
{
return Glob.Files(".", d);
}
foreach (var file in GetFiles($"**/{t}.csproj"))
{
Run("dotnet", $"test {file} -c Release --no-build --no-restore --verbosity=normal /p:AltCover=true");
}
Run("dotnet", $"test {file} -c Release --no-build --no-restore --verbosity=normal /p:AltCover=true");
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,17 @@
"Speckle.Converters.Common": "[2.0.999-local, )"
}
},
"speckle.converters.rhino7": {
"type": "Project",
"dependencies": {
"RhinoCommon": "[7.13.21348.13001, )",
"Speckle.Converters.Common": "[2.0.999-local, )"
}
},
"speckle.converters.rhino7.dependencyinjection": {
"type": "Project",
"dependencies": {
"RhinoCommon": "[7.13.21348.13001, )"
"Speckle.Converters.Rhino7": "[2.0.999-local, )"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
Expand Down
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);
}
}
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>
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);
}
}
Loading

0 comments on commit 91a69a8

Please sign in to comment.