Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions sdks/csharp/tests~/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,56 @@ public static void ListstreamWorks()
}
});
}

public class BTreeIndexBaseColumnImplementsIComparableTest
{

public sealed class UserHandle : RemoteTableHandle<EventContext, User>
{
protected override string RemoteTableName => "user";

public sealed class IdentityIndex : BTreeIndexBase<SpacetimeDB.Identity>
{
protected override SpacetimeDB.Identity GetKey(User row) => row.Identity;

public IdentityIndex(UserHandle table) : base(table) { }
}

public readonly IdentityIndex Identity;

internal UserHandle(DbConnection conn) : base(conn)
{
Identity = new(this);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding comment from the other PR:

This code won't catch problems that occur if the code generation changes in the future. To catch such problems, we'd need to write the same test against generated code. For example, we could add an index to the Message.Sender field in quickstart-chat -- these tests have access to the quickstart-chat generated code.

If you want to do that, it would be great; if not, I'm willing to merge this, but would appreciate a comment saying why this class is here. // Copy of generated code for a BTreeIndex; TODO: update if that code changes is messy but at least documents what is going on.


[Fact]
public void Identity_ShouldImplementIComparable()
{
// Arrange
var identityType = typeof(SpacetimeDB.Identity);

// Act
bool implementsIComparable =
typeof(IComparable<>).MakeGenericType(identityType).IsAssignableFrom(identityType);

// Assert
Assert.True(implementsIComparable, $"{identityType} does not implement IComparable<{identityType}>");
}

[Fact]
public void IdentityIndex_ShouldInheritFrom_BTreeIndexBase()
{
// Arrange
var identityIndexType = typeof(UserHandle.IdentityIndex);
var expectedBaseType = typeof(RemoteTableHandle<EventContext, User>.BTreeIndexBase<SpacetimeDB.Identity>);

// Act
bool isCorrectBaseType = expectedBaseType.IsAssignableFrom(identityIndexType.BaseType);

// Assert
Assert.True(isCorrectBaseType,
"IdentityIndex does not correctly inherit from BTreeIndexBase<SpacetimeDB.Identity>");
}
}
}
Loading