Files
Rendezvous/tests/FinalFactory.Rendezvous.Tests/Browser/SessionBrowserTestData.cs
T
KyuubiYoru 06c4ecf8f3
quality-gate / quality (push) Failing after 1m47s
quality-gate / container (push) Has been skipped
feat(browser): stream bounded live session updates (#26)
2026-07-16 23:25:48 +02:00

83 lines
2.7 KiB
C#

using FinalFactory.Rendezvous.Contracts;
using FinalFactory.Rendezvous.Server.Browser;
using FinalFactory.Rendezvous.Server.State;
using FinalFactory.Rendezvous.Tests.State;
namespace FinalFactory.Rendezvous.Tests.Browser;
internal sealed class SessionBrowserFixture : IDisposable
{
private readonly EphemeralStateFixture _state;
public SessionBrowserFixture()
{
Changes = new(new SessionChangeJournalOptions());
_state = new(changes: Changes);
Cursors = new();
StreamCursors = new();
Browser = new(_state.Store, Cursors, StreamCursors, Changes, _state.Clock);
Streams = new(Changes, StreamCursors, _state.Clock);
}
public InMemoryEphemeralRendezvousStore Store => _state.Store;
public ManualRendezvousClock Clock => _state.Clock;
public SessionBrowserCursorCodec Cursors { get; }
public SessionStreamCursorCodec StreamCursors { get; }
public SessionChangeJournal Changes { get; }
public SessionBrowserService Browser { get; }
public SessionStreamService Streams { get; }
public TenantScope Scope => _state.Scope;
public StoredListing Add(
TenantScope? scope = null,
uint protocolVersion = 7,
RegionId? regionId = null,
ListingVisibility visibility = ListingVisibility.Public,
bool fresh = true,
int currentPlayers = 1,
int maximumPlayers = 8,
IReadOnlyDictionary<string, string>? metadata = null)
{
CreateListingCommand seed = _state.ListingCommand();
CreateListingCommand command = seed with
{
Listing = seed.Listing with
{
Scope = scope ?? Scope,
ProtocolVersion = protocolVersion,
RegionId = regionId ?? seed.Listing.RegionId,
Visibility = visibility,
CurrentPlayers = currentPlayers,
MaximumPlayers = maximumPlayers,
Metadata = metadata ?? seed.Listing.Metadata,
},
};
StoredListing listing = Store.CreateListing(command).Value!;
if (fresh)
{
listing = Store.BindHostPresence(new(
command.Listing.HostPresenceHandle,
command.Listing.HostPresenceFingerprint,
EphemeralStateFixture.PublicEndpoint(40_000),
null)).Value!;
}
return listing;
}
public BrowseSessionsRequest Request(int pageSize = 100) => new()
{
GameId = Scope.GameId,
EnvironmentId = Scope.EnvironmentId,
ProtocolVersion = 7,
RegionId = new("eu-central"),
PageSize = pageSize,
};
public void Dispose()
{
Cursors.Dispose();
StreamCursors.Dispose();
}
}