@@ -2743,6 +2743,63 @@ public void noConnectionIdWhenSkippingNegotiate() {
27432743 assertNull (hubConnection .getConnectionId ());
27442744 }
27452745
2746+ @ Test
2747+ public void SkippingNegotiateDoesNotNegotiate () {
2748+ try (TestLogger logger = new TestLogger (WebSocketTransport .class .getName ())) {
2749+ AtomicBoolean negotiateCalled = new AtomicBoolean (false );
2750+ TestHttpClient client = new TestHttpClient ().on ("POST" , "http://example.com/negotiate?negotiateVersion=1" ,
2751+ (req ) -> {
2752+ negotiateCalled .set (true );
2753+ return Single .just (new HttpResponse (200 , "" ,
2754+ TestUtils .stringToByteBuffer ("{\" connectionId\" :\" bVOiRPG8-6YiJ6d7ZcTOVQ\" ,\" "
2755+ + "availableTransports\" :[{\" transport\" :\" WebSockets\" ,\" transferFormats\" :[\" Text\" ,\" Binary\" ]}]}" )));
2756+ });
2757+
2758+ HubConnection hubConnection = HubConnectionBuilder
2759+ .create ("http://example" )
2760+ .withTransport (TransportEnum .WEBSOCKETS )
2761+ .shouldSkipNegotiate (true )
2762+ .withHttpClient (client )
2763+ .build ();
2764+
2765+ try {
2766+ hubConnection .start ().timeout (30 , TimeUnit .SECONDS ).blockingAwait ();
2767+ } catch (Exception e ) {
2768+ assertEquals ("WebSockets isn't supported in testing currently." , e .getMessage ());
2769+ }
2770+ assertEquals (HubConnectionState .DISCONNECTED , hubConnection .getConnectionState ());
2771+ assertFalse (negotiateCalled .get ());
2772+
2773+ logger .assertLog ("Starting Websocket connection." );
2774+ }
2775+ }
2776+
2777+ @ Test
2778+ public void ThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets () {
2779+ AtomicBoolean negotiateCalled = new AtomicBoolean (false );
2780+ TestHttpClient client = new TestHttpClient ().on ("POST" , "http://example.com/negotiate?negotiateVersion=1" ,
2781+ (req ) -> {
2782+ negotiateCalled .set (true );
2783+ return Single .just (new HttpResponse (200 , "" ,
2784+ TestUtils .stringToByteBuffer ("{\" connectionId\" :\" bVOiRPG8-6YiJ6d7ZcTOVQ\" ,\" "
2785+ + "availableTransports\" :[{\" transport\" :\" WebSockets\" ,\" transferFormats\" :[\" Text\" ,\" Binary\" ]}]}" )));
2786+ });
2787+
2788+ HubConnection hubConnection = HubConnectionBuilder
2789+ .create ("http://example" )
2790+ .shouldSkipNegotiate (true )
2791+ .withHttpClient (client )
2792+ .build ();
2793+
2794+ try {
2795+ hubConnection .start ().timeout (30 , TimeUnit .SECONDS ).blockingAwait ();
2796+ } catch (Exception e ) {
2797+ assertEquals ("Negotiation can only be skipped when using the WebSocket transport directly with '.withTransport(TransportEnum.WEBSOCKETS)' on the 'HubConnectionBuilder'." , e .getMessage ());
2798+ }
2799+ assertEquals (HubConnectionState .DISCONNECTED , hubConnection .getConnectionState ());
2800+ assertFalse (negotiateCalled .get ());
2801+ }
2802+
27462803 @ Test
27472804 public void connectionIdIsAvailableAfterStart () {
27482805 TestHttpClient client = new TestHttpClient ().on ("POST" , "http://example.com/negotiate?negotiateVersion=1" ,
0 commit comments