File tree Expand file tree Collapse file tree
src/RustPlusBot.Features.Connections/Listening
tests/RustPlusBot.Features.Connections.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using RustPlusApi . Data ;
2+ using RustPlusBot . Abstractions . Connections ;
3+
4+ namespace RustPlusBot . Features . Connections . Listening ;
5+
6+ /// <summary>Maps a Rust+ response outcome to <see cref="DeviceReachability"/>. The ONLY place RustPlusErrorCode is interpreted.</summary>
7+ internal static class ReachabilityMapping
8+ {
9+ /// <summary>Reachable on success; Removed for not_found; NoPrivilege for access_denied; NoResponse otherwise.</summary>
10+ /// <param name="isSuccess">Whether the Rust+ response succeeded.</param>
11+ /// <param name="errorCode">The error code if the response failed, or null.</param>
12+ /// <returns>The mapped <see cref="DeviceReachability"/> state.</returns>
13+ public static DeviceReachability FromResponse ( bool isSuccess , RustPlusErrorCode ? errorCode )
14+ {
15+ if ( isSuccess )
16+ {
17+ return DeviceReachability . Reachable ;
18+ }
19+
20+ return errorCode switch
21+ {
22+ RustPlusErrorCode . NotFound => DeviceReachability . Removed ,
23+ RustPlusErrorCode . AccessDenied => DeviceReachability . NoPrivilege ,
24+ _ => DeviceReachability . NoResponse ,
25+ } ;
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ using RustPlusApi . Data ;
2+ using RustPlusBot . Abstractions . Connections ;
3+ using RustPlusBot . Features . Connections . Listening ;
4+
5+ namespace RustPlusBot . Features . Connections . Tests ;
6+
7+ public sealed class ReachabilityMappingTests
8+ {
9+ [ Fact ]
10+ public void Success_IsReachable ( ) =>
11+ Assert . Equal ( DeviceReachability . Reachable , ReachabilityMapping . FromResponse ( true , null ) ) ;
12+
13+ [ Theory ]
14+ [ InlineData ( RustPlusErrorCode . NotFound , DeviceReachability . Removed ) ]
15+ [ InlineData ( RustPlusErrorCode . AccessDenied , DeviceReachability . NoPrivilege ) ]
16+ [ InlineData ( RustPlusErrorCode . Unknown , DeviceReachability . NoResponse ) ]
17+ [ InlineData ( RustPlusErrorCode . ServerError , DeviceReachability . NoResponse ) ]
18+ [ InlineData ( RustPlusErrorCode . RateLimit , DeviceReachability . NoResponse ) ]
19+ public void Failure_MapsByCode ( RustPlusErrorCode code , DeviceReachability expected ) =>
20+ Assert . Equal ( expected , ReachabilityMapping . FromResponse ( false , code ) ) ;
21+
22+ [ Fact ]
23+ public void Failure_NullCode_IsNoResponse ( ) =>
24+ Assert . Equal ( DeviceReachability . NoResponse , ReachabilityMapping . FromResponse ( false , null ) ) ;
25+ }
You can’t perform that action at this time.
0 commit comments