Skip to content

Commit

Permalink
Test Coverage (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan authored Sep 16, 2024
1 parent ccb4f54 commit df5b151
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<ItemGroup>
<PackageVersion Include="altcover" Version="8.8.74" />
<PackageVersion Include="altcover" Version="8.8.173" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="Bullseye" Version="5.0.0" />
<PackageVersion Include="GraphQL.Client" Version="6.0.0" />
Expand Down
6 changes: 3 additions & 3 deletions tests/Speckle.Objects.Tests.Unit/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net8.0": {
"altcover": {
"type": "Direct",
"requested": "[8.8.74, )",
"resolved": "8.8.74",
"contentHash": "e8RZNE0vZnuBk/gOAWu9K5wm3S7dOrOlZje3PHI9PJUHqvP1cxVJD1eXAAmddFVlixowB7C7/zvC16GnunC2LQ=="
"requested": "[8.8.173, )",
"resolved": "8.8.173",
"contentHash": "iejmqWdC9H9ShTtsT7vSLpZ74RG4sDhheW7wllczXWl6WZAaCqGXMFGRRHi8TZGCzV/7Ah5gjXZ4GRlfAef4Eg=="
},
"GitVersion.MsBuild": {
"type": "Direct",
Expand Down
6 changes: 3 additions & 3 deletions tests/Speckle.Sdk.Serialization.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net8.0": {
"altcover": {
"type": "Direct",
"requested": "[8.8.74, )",
"resolved": "8.8.74",
"contentHash": "e8RZNE0vZnuBk/gOAWu9K5wm3S7dOrOlZje3PHI9PJUHqvP1cxVJD1eXAAmddFVlixowB7C7/zvC16GnunC2LQ=="
"requested": "[8.8.173, )",
"resolved": "8.8.173",
"contentHash": "iejmqWdC9H9ShTtsT7vSLpZ74RG4sDhheW7wllczXWl6WZAaCqGXMFGRRHi8TZGCzV/7Ah5gjXZ4GRlfAef4Eg=="
},
"GitVersion.MsBuild": {
"type": "Direct",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;

[TestOf(typeof(SubscriptionResource))]
public class SubscriptionResourceTests
public class SubscriptionResourceTests : IDisposable
{
private const int WAIT_PERIOD = 300;
private Client _testUser;
Expand Down Expand Up @@ -117,4 +117,7 @@ public async Task ProjectCommentsUpdated_SubscriptionIsCalled()
Assert.That(subscriptionMessage, Is.Not.Null);
Assert.That(subscriptionMessage!.id, Is.EqualTo(created.id));
}

[OneTimeTearDown]
public void Dispose() => _testUser.Dispose();
}
8 changes: 4 additions & 4 deletions tests/Speckle.Sdk.Tests.Integration/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net8.0": {
"altcover": {
"type": "Direct",
"requested": "[8.8.74, )",
"resolved": "8.8.74",
"contentHash": "e8RZNE0vZnuBk/gOAWu9K5wm3S7dOrOlZje3PHI9PJUHqvP1cxVJD1eXAAmddFVlixowB7C7/zvC16GnunC2LQ=="
"requested": "[8.8.173, )",
"resolved": "8.8.173",
"contentHash": "iejmqWdC9H9ShTtsT7vSLpZ74RG4sDhheW7wllczXWl6WZAaCqGXMFGRRHi8TZGCzV/7Ah5gjXZ4GRlfAef4Eg=="
},
"GitVersion.MsBuild": {
"type": "Direct",
Expand Down Expand Up @@ -233,7 +233,7 @@
"Shouldly": "[4.2.1, )",
"Speckle.DoubleNumerics": "[4.0.1, )",
"Speckle.Sdk": "[1.0.0, )",
"altcover": "[8.8.74, )"
"altcover": "[8.8.173, )"
}
},
"GraphQL.Client": {
Expand Down
26 changes: 26 additions & 0 deletions tests/Speckle.Sdk.Tests.Unit/Common/NotNullTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public async Task NotNullStruct_Task()
t.ShouldBe(2);
}

[Test]
public async Task NotNullClass_ValueTask()
{
var t = await NotNullExtensions.NotNull(ValueTask.FromResult<string?>("test"));
t.ShouldNotBeNull().ShouldBe("test");
}

[Test]
public async Task NotNullStruct_ValueTask()
{
var t = await NotNullExtensions.NotNull(ValueTask.FromResult<int?>(2));
t.ShouldBe(2);
}

[Test]
public void NotNullClass_Exception() =>
Assert.Throws<ArgumentNullException>(() => NotNullExtensions.NotNull((string?)null));
Expand All @@ -58,4 +72,16 @@ public void NotNullClass_Task_Exception() =>
[Test]
public void NotNullStruct_Task_Exception() =>
Assert.ThrowsAsync<ArgumentNullException>(() => NotNullExtensions.NotNull(Task.FromResult((int?)null)));

[Test]
public void NotNullClass_ValueTask_Exception() =>
Assert.ThrowsAsync<ArgumentNullException>(
async () => await NotNullExtensions.NotNull(ValueTask.FromResult((string?)null))
);

[Test]
public void NotNullStruct_ValueTask_Exception() =>
Assert.ThrowsAsync<ArgumentNullException>(
async () => await NotNullExtensions.NotNull(ValueTask.FromResult((int?)null))
);
}
47 changes: 45 additions & 2 deletions tests/Speckle.Sdk.Tests.Unit/Common/UnitsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ public class UnitsTest
{
private const double EPS = 0.00022;

public static List<string> OfficiallySupportedUnits => Units.SupportedUnits;
public static List<string> NotSupportedUnits => ["feeters", "liters", "us_ft"];
public static List<string?> ConversionSupport => [.. Units.SupportedUnits, null];

[Test, Combinatorial]
[DefaultFloatingPointTolerance(EPS)]
public void TestUnitConversion(
[ValueSource(typeof(Units), nameof(Units.SupportedUnits))] string from,
[ValueSource(typeof(Units), nameof(Units.SupportedUnits))] string to
[ValueSource(nameof(ConversionSupport))] string? from,
[ValueSource(nameof(ConversionSupport))] string? to
)
{
var forwards = Units.GetConversionFactor(from, to);
Expand All @@ -24,4 +28,43 @@ public void TestUnitConversion(
$"Behaviour says that 1{from} == {forwards}{to}, and 1{to} == {backwards}{from}"
);
}

[TestCaseSource(nameof(OfficiallySupportedUnits))]
public void IsUnitSupported_ReturnsTrue_AllSupportedUnits(string unit)
{
bool res = Units.IsUnitSupported(unit);
Assert.That(res, Is.True);
}

[TestCaseSource(nameof(NotSupportedUnits))]
public void IsUnitSupported_ReturnsFalse_NotSupportedUnits(string unit)
{
bool res = Units.IsUnitSupported(unit);
Assert.That(res, Is.False);
}

[TestCaseSource(nameof(OfficiallySupportedUnits))]
public void GetUnitsFromString_ReturnsSupported(string unit)
{
var lower = Units.GetUnitsFromString(unit);
var upper = Units.GetUnitsFromString(unit?.ToUpperInvariant());

Assert.That(lower, Is.EqualTo(unit));
Assert.That(upper, Is.EqualTo(unit));
}

[TestCaseSource(nameof(NotSupportedUnits))]
public void GetUnitsFromString_ThrowsUnSupported(string unit)
{
Assert.Throws<ArgumentOutOfRangeException>(() => _ = Units.GetUnitsFromString(unit));
}

[TestCaseSource(nameof(OfficiallySupportedUnits))]
public void UnitEncoding_RoundTrip(string unit)
{
var encoded = Units.GetEncodingFromUnit(unit);
var res = Units.GetUnitFromEncoding(encoded);

Assert.That(res, Is.EqualTo(unit));
}
}
6 changes: 3 additions & 3 deletions tests/Speckle.Sdk.Tests.Unit/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net8.0": {
"altcover": {
"type": "Direct",
"requested": "[8.8.74, )",
"resolved": "8.8.74",
"contentHash": "e8RZNE0vZnuBk/gOAWu9K5wm3S7dOrOlZje3PHI9PJUHqvP1cxVJD1eXAAmddFVlixowB7C7/zvC16GnunC2LQ=="
"requested": "[8.8.173, )",
"resolved": "8.8.173",
"contentHash": "iejmqWdC9H9ShTtsT7vSLpZ74RG4sDhheW7wllczXWl6WZAaCqGXMFGRRHi8TZGCzV/7Ah5gjXZ4GRlfAef4Eg=="
},
"GitVersion.MsBuild": {
"type": "Direct",
Expand Down

0 comments on commit df5b151

Please sign in to comment.