22using NSubstitute ;
33using RustPlusBot . Abstractions . Connections ;
44using RustPlusBot . Abstractions . Events ;
5- using RustPlusBot . Domain . Connections ;
65using RustPlusBot . Domain . Switches ;
76using RustPlusBot . Features . Switches . Posting ;
87using RustPlusBot . Features . Switches . Relaying ;
98using RustPlusBot . Features . Switches . Rendering ;
109using RustPlusBot . Features . Workspace . Locating ;
1110using RustPlusBot . Localization ;
12- using RustPlusBot . Persistence . Connections ;
1311using RustPlusBot . Persistence . Switches ;
1412using RustPlusBot . Persistence . Workspace ;
1513
@@ -20,13 +18,11 @@ public sealed class SwitchStateRelayTests
2018 private static Harness Create ( )
2119 {
2220 var store = Substitute . For < ISwitchStore > ( ) ;
23- var connections = Substitute . For < IConnectionStore > ( ) ;
2421 var workspace = Substitute . For < IWorkspaceStore > ( ) ;
2522 workspace . GetCultureAsync ( Arg . Any < ulong > ( ) , Arg . Any < CancellationToken > ( ) ) . Returns ( "en" ) ;
2623
2724 var services = new ServiceCollection ( ) ;
2825 services . AddScoped ( _ => store ) ;
29- services . AddScoped ( _ => connections ) ;
3026 services . AddScoped ( _ => workspace ) ;
3127 var provider = services . BuildServiceProvider ( ) ;
3228
@@ -39,7 +35,7 @@ private static Harness Create()
3935
4036 var relay = new SwitchStateRelay ( provider . GetRequiredService < IServiceScopeFactory > ( ) , locator , poster ,
4137 renderer ) ;
42- return new Harness ( relay , store , poster , connections ) ;
38+ return new Harness ( relay , store , poster ) ;
4339 }
4440
4541 [ Fact ]
@@ -70,11 +66,6 @@ public async Task ConnectionStatus_not_connected_marks_switches_unreachable()
7066 {
7167 var h = Create ( ) ;
7268 var serverId = Guid . NewGuid ( ) ;
73- h . Connections . GetStateAsync ( 10UL , serverId , Arg . Any < CancellationToken > ( ) )
74- . Returns ( new ConnectionState
75- {
76- GuildId = 10UL , RustServerId = serverId , Status = ConnectionStatus . Unreachable
77- } ) ;
7869 h . Store . ListByServerAsync ( 10UL , serverId , Arg . Any < CancellationToken > ( ) )
7970 . Returns (
8071 [
@@ -101,11 +92,6 @@ public async Task ConnectionStatus_connected_does_nothing()
10192 {
10293 var h = Create ( ) ;
10394 var serverId = Guid . NewGuid ( ) ;
104- h . Connections . GetStateAsync ( 10UL , serverId , Arg . Any < CancellationToken > ( ) )
105- . Returns ( new ConnectionState
106- {
107- GuildId = 10UL , RustServerId = serverId , Status = ConnectionStatus . Connected
108- } ) ;
10995
11096 await h . Relay . HandleConnectionStatusAsync (
11197 new ConnectionStatusChangedEvent ( 10UL , serverId , IsConnected : true , WasConnected : true ) ,
@@ -116,6 +102,34 @@ await h.Poster.DidNotReceive().EnsureAsync(Arg.Any<ulong>(), Arg.Any<ulong?>(),
116102 Arg . Any < global ::Discord . MessageComponent > ( ) , Arg . Any < CancellationToken > ( ) ) ;
117103 }
118104
105+ /// <summary>Boot/reconnect-loop statuses (never Connected in this process) must not sweep — embeds keep their last-run state until the prime republishes.</summary>
106+ [ Fact ]
107+ public async Task ConnectionStatus_boot_without_prior_connection_does_not_sweep ( )
108+ {
109+ var h = Create ( ) ;
110+ var serverId = Guid . NewGuid ( ) ;
111+ h . Store . ListByServerAsync ( 10UL , serverId , Arg . Any < CancellationToken > ( ) )
112+ . Returns (
113+ [
114+ new SmartSwitch
115+ {
116+ GuildId = 10UL ,
117+ ServerId = serverId ,
118+ EntityId = 42UL ,
119+ Name = "G" ,
120+ MessageId = 900UL
121+ }
122+ ] ) ;
123+
124+ await h . Relay . HandleConnectionStatusAsync (
125+ new ConnectionStatusChangedEvent ( 10UL , serverId , IsConnected : false , WasConnected : false ) ,
126+ CancellationToken . None ) ;
127+
128+ await h . Poster . DidNotReceive ( ) . EnsureAsync ( Arg . Any < ulong > ( ) , Arg . Any < ulong ? > ( ) ,
129+ Arg . Any < global ::Discord . Embed > ( ) ,
130+ Arg . Any < global ::Discord . MessageComponent > ( ) , Arg . Any < CancellationToken > ( ) ) ;
131+ }
132+
119133 [ Fact ]
120134 public async Task DeviceTriggered_managed_switch_updates_store_and_rerenders ( )
121135 {
@@ -205,6 +219,5 @@ await h.Poster.Received(1).EnsureAsync(777UL, 900UL, Arg.Any<global::Discord.Emb
205219 private sealed record Harness (
206220 SwitchStateRelay Relay ,
207221 ISwitchStore Store ,
208- ISwitchChannelPoster Poster ,
209- IConnectionStore Connections ) ;
222+ ISwitchChannelPoster Poster ) ;
210223}
0 commit comments