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? 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(); } }