Test Coverage (#117)

This commit is contained in:
Jedd Morgan
2024-09-16 08:41:26 +01:00
committed by GitHub
parent ccb4f54550
commit df5b151c90
8 changed files with 89 additions and 17 deletions
+1 -1
View File
@@ -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" />
@@ -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",
@@ -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",
@@ -6,7 +6,7 @@ using Speckle.Sdk.Api.GraphQL.Resources;
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;
@@ -117,4 +117,7 @@ public class SubscriptionResourceTests
Assert.That(subscriptionMessage, Is.Not.Null);
Assert.That(subscriptionMessage!.id, Is.EqualTo(created.id));
}
[OneTimeTearDown]
public void Dispose() => _testUser.Dispose();
}
@@ -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",
@@ -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": {
@@ -43,6 +43,20 @@ public class NotNullTests
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));
@@ -58,4 +72,16 @@ public class NotNullTests
[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))
);
}
@@ -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);
@@ -24,4 +28,43 @@ public class UnitsTest
$"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));
}
}
@@ -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",