Skip to content

Commit

Permalink
test: upgrade testing packages and refactor assertions
Browse files Browse the repository at this point in the history
Upgraded NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk to their latest versions. Refactored all the assertion statements in SpiceDbClientTests.cs to use ClassicAssert instead of Assert for better compatibility with the updated NUnit version.
  • Loading branch information
tanczosm committed Apr 11, 2024
1 parent f4031af commit cac7468
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions SpiceDb.Tests/SpiceDb.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="nunit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
35 changes: 18 additions & 17 deletions SpiceDb.Tests/SpiceDbClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SpiceDb.Enum;
using SpiceDb.Models;
using System.Reflection;
using NUnit.Framework.Legacy;

namespace SpiceDb.Tests;

Expand Down Expand Up @@ -31,7 +32,7 @@ public void SetUp()

if (string.IsNullOrEmpty(serverAddress))
{
Assert.Fail("Unable to load service configuration from environment variables");
ClassicAssert.Fail("Unable to load service configuration from environment variables");
}

_client = new SpiceDbClient(serverAddress!, token!, _prefix);
Expand Down Expand Up @@ -74,7 +75,7 @@ public async Task ReadRelationshipsAsyncTest_FilterOnly()

foreach (var relationship in expected)
{
Assert.IsTrue(relationships.Contains(relationship));
ClassicAssert.IsTrue(relationships.Contains(relationship));
}
}

Expand All @@ -91,7 +92,7 @@ public async Task ReadRelationshipsAsyncTest_FilterSubjectType()

foreach (var relationship in expected)
{
Assert.IsTrue(relationships.Contains(relationship));
ClassicAssert.IsTrue(relationships.Contains(relationship));
}
}

Expand All @@ -113,7 +114,7 @@ public async Task WriteAndDeleteRelationshipsAsyncTest_Upsert()

var stillHasRelationship = _client!.CheckPermission("group:security#owner@user:bart");

Assert.IsTrue(hasRelationship.HasPermission && !stillHasRelationship.HasPermission);
ClassicAssert.IsTrue(hasRelationship.HasPermission && !stillHasRelationship.HasPermission);
}

[Test]
Expand Down Expand Up @@ -149,7 +150,7 @@ await _client.DeleteRelationshipsAsync(new RelationshipFilter
relationships2.Add(response.Relationship.ToString()!);
}

Assert.IsTrue(relationships.Count == 4 && relationships2.Count == 0);
ClassicAssert.IsTrue(relationships.Count == 4 && relationships2.Count == 0);
}


Expand All @@ -163,7 +164,7 @@ public void CheckPermissionAsyncTest()
var p5 = _client!.CheckPermission("group:test#joiners@user:somenewguy");
var p6 = _client!.CheckPermission("group:test#add_manager@user:blackhat");

Assert.IsTrue(p1.HasPermission && p2.HasPermission && p3.HasPermission && p4.HasPermission && !p5.HasPermission && !p6.HasPermission);
ClassicAssert.IsTrue(p1.HasPermission && p2.HasPermission && p3.HasPermission && p4.HasPermission && !p5.HasPermission && !p6.HasPermission);
}

/// This feature isn't currently available in Serverless
Expand All @@ -182,66 +183,66 @@ public async Task CheckBulkPermissionAsyncTest()

var p = await _client!.CheckBulkPermissionsAsync(permissions);

Assert.IsNotNull(p);
Assert.IsTrue(p!.Pairs[0].HasPermission && p!.Pairs[1].HasPermission && p!.Pairs[2].HasPermission && p!.Pairs[3].HasPermission && !p!.Pairs[4].HasPermission && !p!.Pairs[5].HasPermission);
ClassicAssert.IsNotNull(p);
ClassicAssert.IsTrue(p!.Pairs[0].HasPermission && p!.Pairs[1].HasPermission && p!.Pairs[2].HasPermission && p!.Pairs[3].HasPermission && !p!.Pairs[4].HasPermission && !p!.Pairs[5].HasPermission);
}

[Test]
public async Task ExpandPermissionAsyncTest()
{
var response = await _client!.ExpandPermissionAsync(new ResourceReference("group", "test"), "post");

Assert.IsNotNull(response);
ClassicAssert.IsNotNull(response);
}
/*
[Test]
public void AddRelationshipsAsyncTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
[Test]
public void AddRelationshipAsyncTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
[Test]
public void DeleteRelationshipAsyncTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
[Test]
public void LookupSubjectsTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
[Test]
public void LookupResourcesTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
[Test]
public void WatchTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
[Test]
public void GetResourcePermissionsAsyncTest()
{
Assert.Fail();
ClassicAssert.Fail();
}
*/
[Test]
public void ReadSchemaTest()
{
var schema = _client!.ReadSchema();

Assert.IsFalse(string.IsNullOrEmpty(schema));
ClassicAssert.IsFalse(string.IsNullOrEmpty(schema));
}


Expand Down

0 comments on commit cac7468

Please sign in to comment.