Skip to content

Commit

Permalink
Convert to Xunit (#196)
Browse files Browse the repository at this point in the history
* xunit unit tests

* most pass with formatting

* convert objects to xunit

* remove nunit

* format

* merge fixes

* switch objects to fluent assertions

* update to fluent assertions

* more FA

* convert all to FA

* Format

* Fix tests

* formatting

* hopefully made credential test better

* Catch more specific exception

* use another more specific exception

* Fix tests

* update to xunit

* update packages
  • Loading branch information
adamhathcock authored Jan 9, 2025
1 parent 465f635 commit 14d9598
Show file tree
Hide file tree
Showing 91 changed files with 2,684 additions and 2,211 deletions.
2 changes: 0 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project>
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<AnalysisMode>Recommended</AnalysisMode>
<NoWarn>
$(NoWarn);
<!-- Things we need to test -->
Expand All @@ -9,7 +8,6 @@
<!-- Analysers that provide no tangeable value to a test project -->
CA5394;CA2007;CA1852;CA1819;CA1711;CA1063;CA1816;CA2234;CS8618;CA1054;CA1810;CA2208;CA1019;CA1831;
</NoWarn>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
</PropertyGroup>

<Target Name="DeepClean">
Expand Down
13 changes: 6 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
<Project>
<ItemGroup>
<PackageVersion Include="altcover" Version="8.9.3" />
<PackageVersion Include="altcover" Version="9.0.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="Bullseye" Version="5.0.0" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="GraphQL.Client" Version="6.0.0" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="ILRepack.FullAuto" Version="1.6.0" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<!-- Keep at exactly 7.0.5 for side by side with V2 -->
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.5" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
<PackageVersion Include="Open.ChannelExtensions" Version="9.0.0" />
<PackageVersion Include="Polly" Version="7.2.3" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="Speckle.Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="Speckle.DoubleNumerics" Version="4.0.1" />
<PackageVersion Include="SimpleExec" Version="12.0.0" />
<PackageVersion Include="System.Threading.Channels" Version="9.0.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<GlobalPackageReference Include="PolySharp" Version="1.15.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="GitVersion.MsBuild" Version="5.12.0" />
Expand Down
5 changes: 5 additions & 0 deletions src/Speckle.Sdk.Dependencies/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ public static class Collections
public static IReadOnlyDictionary<TKey, TValue> Freeze<TKey, TValue>(this IDictionary<TKey, TValue> source)
where TKey : notnull => source.ToFrozenDictionary();
}

public static class EnumerableExtensions
{
public static IEnumerable<int> RangeFrom(int from, int to) => Enumerable.Range(from, to - from + 1);
}
3 changes: 3 additions & 0 deletions tests/Speckle.Objects.Tests.Unit/Assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
109 changes: 50 additions & 59 deletions tests/Speckle.Objects.Tests.Unit/Geometry/ArcTests.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,78 @@
using NUnit.Framework;
using FluentAssertions;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Arc))]
public class ArcTests
{
private Plane TestPlaneCounterClockwise
{
get
private Plane TestPlaneCounterClockwise =>
new()
{
const string UNITS = Units.Meters;
return new()
{
origin = new Point(0, 0, 0, UNITS),
normal = new Vector(0, 0, 1, UNITS),
xdir = new Vector(1, 0, 0, UNITS),
ydir = new Vector(0, 1, 0, UNITS),
units = UNITS,
};
}
}
origin = new Point(0, 0, 0, Units.Meters),
normal = new Vector(0, 0, 1, Units.Meters),
xdir = new Vector(1, 0, 0, Units.Meters),
ydir = new Vector(0, 1, 0, Units.Meters),
units = Units.Meters,
};

private Plane TestPlaneClockwise
{
get
private Plane TestPlaneClockwise =>
new()
{
const string UNITS = Units.Meters;
return new()
{
origin = new Point(0, 0, 0, UNITS),
normal = new Vector(0, 0, -1, UNITS),
xdir = new Vector(-1, 0, 0, UNITS),
ydir = new Vector(0, 1, 0, UNITS),
units = UNITS,
};
}
}
origin = new Point(0, 0, 0, Units.Meters),
normal = new Vector(0, 0, -1, Units.Meters),
xdir = new Vector(-1, 0, 0, Units.Meters),
ydir = new Vector(0, 1, 0, Units.Meters),
units = Units.Meters,
};

[Test]
[Fact]
public void CanCreateArc_HalfCircle_CounterClockwise()
{
const string UNITS = Units.Meters;
var counterClockwiseArc = new Arc()
{
plane = TestPlaneCounterClockwise,
startPoint = new Point(1, 0, 0, UNITS),
endPoint = new Point(-1, 0, 0, UNITS),
midPoint = new Point(0, 1, 0, UNITS),
units = UNITS,
startPoint = new Point(1, 0, 0, Units.Meters),
endPoint = new Point(-1, 0, 0, Units.Meters),
midPoint = new Point(0, 1, 0, Units.Meters),
units = Units.Meters,
};

Assert.That(Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, UNITS)), Is.EqualTo(0).Within(0.0001));
Assert.That(
Point.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, UNITS)),
Is.EqualTo(0).Within(0.0001)
);
Assert.That(counterClockwiseArc.measure - Math.PI, Is.EqualTo(0).Within(0.0001));
Assert.That(counterClockwiseArc.radius, Is.EqualTo(1).Within(0.0001));
Assert.That(counterClockwiseArc.length, Is.EqualTo(Math.PI).Within(0.0001));
Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, Units.Meters)).Should().BeApproximately(0, 0.0001);

Point
.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, Units.Meters))
.Should()
.BeApproximately(0, 0.0001);

(counterClockwiseArc.measure - Math.PI).Should().BeApproximately(0, 0.0001);

counterClockwiseArc.radius.Should().BeApproximately(1, 0.0001);

counterClockwiseArc.length.Should().BeApproximately(Math.PI, 0.0001);
}

[Test]
[Fact]
public void CanCreateArc_HalfCircle_Clockwise()
{
const string UNITS = Units.Meters;
var counterClockwiseArc = new Arc()
var clockwiseArc = new Arc()
{
plane = TestPlaneClockwise,
endPoint = new Point(1, 0, 0, UNITS),
startPoint = new Point(-1, 0, 0, UNITS),
midPoint = new Point(0, 1, 0, UNITS),
units = UNITS,
endPoint = new Point(1, 0, 0, Units.Meters),
startPoint = new Point(-1, 0, 0, Units.Meters),
midPoint = new Point(0, 1, 0, Units.Meters),
units = Units.Meters,
};

Assert.That(Point.Distance(counterClockwiseArc.midPoint, new Point(0, 1, 0, UNITS)), Is.EqualTo(0).Within(0.0001));
Assert.That(
Point.Distance(counterClockwiseArc.plane.origin, new Point(0, 0, 0, UNITS)),
Is.EqualTo(0).Within(0.0001)
);
Assert.That(counterClockwiseArc.measure - Math.PI, Is.EqualTo(0).Within(0.0001));
Assert.That(counterClockwiseArc.radius, Is.EqualTo(1).Within(0.0001));
Assert.That(counterClockwiseArc.length, Is.EqualTo(Math.PI).Within(0.0001));
Point.Distance(clockwiseArc.midPoint, new Point(0, 1, 0, Units.Meters)).Should().BeApproximately(0, 0.0001);

Point.Distance(clockwiseArc.plane.origin, new Point(0, 0, 0, Units.Meters)).Should().BeApproximately(0, 0.0001);

(clockwiseArc.measure - Math.PI).Should().BeApproximately(0, 0.0001);

clockwiseArc.radius.Should().BeApproximately(1, 0.0001);

clockwiseArc.length.Should().BeApproximately(Math.PI, 0.0001);
}
}
35 changes: 16 additions & 19 deletions tests/Speckle.Objects.Tests.Unit/Geometry/BoxTests.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
using NUnit.Framework;
using FluentAssertions;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Box))]
public class BoxTests
{
private Plane TestPlane
{
get
private Plane TestPlane =>
new()
{
const string UNITS = Units.Meters;
return new()
{
origin = new Point(0, 0, 0, UNITS),
normal = new Vector(0, 0, 1, UNITS),
xdir = new Vector(1, 0, 0, UNITS),
ydir = new Vector(0, 1, 0, UNITS),
units = UNITS,
};
}
}
origin = new Point(0, 0, 0, Units.Meters),
normal = new Vector(0, 0, 1, Units.Meters),
xdir = new Vector(1, 0, 0, Units.Meters),
ydir = new Vector(0, 1, 0, Units.Meters),
units = Units.Meters,
};

[Test]
[Fact]
public void CanCreateBox()
{
const string UNITS = Units.Meters;
Expand All @@ -36,7 +30,10 @@ public void CanCreateBox()
units = UNITS,
};

Assert.That(box.area, Is.EqualTo(2 * (2 * 4 + 2 * 6 + 4 * 6)).Within(0.0001));
Assert.That(box.volume, Is.EqualTo(2 * 4 * 6).Within(0.0001));
// Assert area
box.area.Should().BeApproximately(2 * (2 * 4 + 2 * 6 + 4 * 6), 0.0001);

// Assert volume
box.volume.Should().BeApproximately(2 * 4 * 6, 0.0001);
}
}
15 changes: 8 additions & 7 deletions tests/Speckle.Objects.Tests.Unit/Geometry/CircleTests.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using NUnit.Framework;
using FluentAssertions;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Circle))]
public class CircleTests
{
private Plane TestPlane
{
get
{
const string UNITS = Units.Meters;
return new()
return new Plane
{
origin = new Point(0, 0, 0, UNITS),
normal = new Vector(0, 0, 1, UNITS),
Expand All @@ -23,18 +23,19 @@ private Plane TestPlane
}
}

[Test]
[Fact]
public void CanCreateCircle()
{
const string UNITS = Units.Meters;
var circle = new Circle()
var circle = new Circle
{
plane = TestPlane,
radius = 5,
units = UNITS,
};

Assert.That(circle.length, Is.EqualTo(2 * Math.PI * 5).Within(0.0001));
Assert.That(circle.area, Is.EqualTo(Math.PI * 5 * 5).Within(0.0001));
// Use Shouldly assertions
circle.length.Should().BeApproximately(2 * Math.PI * 5, 0.0001);
circle.area.Should().BeApproximately(Math.PI * 5 * 5, 0.0001);
}
}
31 changes: 17 additions & 14 deletions tests/Speckle.Objects.Tests.Unit/Geometry/MeshTests.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
using NUnit.Framework;
using FluentAssertions;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Common;
using Xunit;

namespace Speckle.Objects.Tests.Unit.Geometry;

[TestFixture, TestOf(typeof(Mesh))]
public class MeshTests
{
private static Mesh[] s_testCaseSource = { CreateBlenderStylePolygon(), CreateRhinoStylePolygon() };
private static readonly Mesh[] TestCaseSource = { CreateBlenderStylePolygon(), CreateRhinoStylePolygon() };

[Test, TestCaseSource(nameof(s_testCaseSource))]
[Theory]
[MemberData(nameof(GetTestCaseSource))]
public void CanAlignVertices(Mesh inPolygon)
{
inPolygon.AlignVerticesWithTexCoordsByIndex();

Assert.That(inPolygon.VerticesCount, Is.EqualTo(inPolygon.TextureCoordinatesCount));
inPolygon.VerticesCount.Should().Be(inPolygon.TextureCoordinatesCount);

var expectedPolygon = CreateRhinoStylePolygon();

Assert.That(inPolygon.vertices, Is.EquivalentTo(expectedPolygon.vertices));
Assert.That(inPolygon.faces, Is.EquivalentTo(expectedPolygon.faces));
Assert.That(inPolygon.textureCoordinates, Is.EquivalentTo(expectedPolygon.textureCoordinates));
inPolygon.vertices.Should().BeEquivalentTo(expectedPolygon.vertices);
inPolygon.faces.Should().BeEquivalentTo(expectedPolygon.faces);
inPolygon.textureCoordinates.Should().BeEquivalentTo(expectedPolygon.textureCoordinates);
}

public static IEnumerable<object[]> GetTestCaseSource() => TestCaseSource.Select(mesh => new object[] { mesh });

private static Mesh CreateRhinoStylePolygon()
{
return new Mesh
{
vertices = [0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0],
faces = [3, 0, 1, 2, 3, 3, 4, 5],
textureCoordinates = [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0],
vertices = new List<double> { 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0 },
faces = new List<int> { 3, 0, 1, 2, 3, 3, 4, 5 },
textureCoordinates = new List<double> { 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 },
units = Units.Meters,
};
}
Expand All @@ -38,9 +41,9 @@ private static Mesh CreateBlenderStylePolygon()
{
return new Mesh
{
vertices = [0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0],
faces = [3, 0, 1, 2, 3, 0, 2, 3],
textureCoordinates = [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0],
vertices = new List<double> { 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0 },
faces = new List<int> { 3, 0, 1, 2, 3, 0, 2, 3 },
textureCoordinates = new List<double> { 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 },
units = Units.Meters,
};
}
Expand Down
Loading

0 comments on commit 14d9598

Please sign in to comment.