Release local peer subscriptions when combat sharing stops
This commit is contained in:
parent
23ef606727
commit
55dc989f85
7 changed files with 40 additions and 4 deletions
|
|
@ -8,6 +8,16 @@ namespace OpenAC.MosswartMassacre.Tests.Fakes;
|
|||
/// </summary>
|
||||
public sealed class FakeNetwork : INetworkAutomation
|
||||
{
|
||||
public bool SupportsSubscriptions => true;
|
||||
public List<PluginPeerCapabilities> Requests { get; } = [];
|
||||
public int ActiveLeases { get; private set; }
|
||||
public IDisposable Subscribe(PluginPeerCapabilities capabilities)
|
||||
{ Requests.Add(capabilities); ActiveLeases++; return new Lease(this); }
|
||||
private sealed class Lease(FakeNetwork owner) : IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
public void Dispose() { if (_disposed) return; _disposed = true; owner.ActiveLeases--; }
|
||||
}
|
||||
public bool IsAvailable { get; set; } = true;
|
||||
|
||||
public List<PluginNetworkClient> ImportedClients { get; } = [];
|
||||
|
|
|
|||
|
|
@ -42,6 +42,21 @@ public sealed class VitalSharingTests
|
|||
|
||||
private static VitalSharing Feature(PluginHarness harness) => harness.Feature<VitalSharing>();
|
||||
|
||||
[Fact]
|
||||
public void Local_peer_subscription_exists_only_while_combat_sharing_is_enabled()
|
||||
{
|
||||
using var harness = Sharing();
|
||||
var network = harness.Host.Automation.Network;
|
||||
Assert.Empty(network.Requests);
|
||||
Feature(harness).Start();
|
||||
Feature(harness).Start();
|
||||
Assert.Equal(1, network.ActiveLeases);
|
||||
Assert.Equal(PluginPeerCapabilities.ClientState | PluginPeerCapabilities.Casts, Assert.Single(network.Requests));
|
||||
Feature(harness).OnLogoff();
|
||||
Feature(harness).Dispose();
|
||||
Assert.Equal(0, network.ActiveLeases);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Subscribe_on_start_carries_the_player_id_and_tags()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue