From b1010b7bd5733bc5e83a00eb2db9024fe3f3576f Mon Sep 17 00:00:00 2001
From: Andrew Stanton-Nurse <andrew@stanton-nurse.com>
Date: Wed, 2 May 2018 14:34:23 -0700
Subject: [PATCH] fix #2171 by adding HttpTransportType.None (#2172)

---
 .../ts/signalr/spec/HttpConnection.spec.ts    | 28 ++++++++++++-------
 clients/ts/signalr/src/ITransport.ts          |  9 ++++--
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/clients/ts/signalr/spec/HttpConnection.spec.ts b/clients/ts/signalr/spec/HttpConnection.spec.ts
index 853faf739cd..3c5f7d4771b 100644
--- a/clients/ts/signalr/spec/HttpConnection.spec.ts
+++ b/clients/ts/signalr/spec/HttpConnection.spec.ts
@@ -223,27 +223,35 @@ describe("HttpConnection", () => {
     });
 
     eachTransport((requestedTransport: HttpTransportType) => {
-        // OPTIONS is not sent when WebSockets transport is explicitly requested
-        if (requestedTransport === HttpTransportType.WebSockets) {
-            return;
-        }
-        it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async (done) => {
+        it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async () => {
+            const negotiateResponse = {
+                availableTransports: [
+                    { transport: "WebSockets", transferFormats: [ "Text", "Binary" ] },
+                    { transport: "ServerSentEvents", transferFormats: [ "Text" ] },
+                    { transport: "LongPolling", transferFormats: [ "Text", "Binary" ] },
+                ],
+                connectionId: "abc123",
+            };
+
+            // Remove the requested transport from the response
+            negotiateResponse.availableTransports = negotiateResponse.availableTransports
+                .filter((f) => f.transport !== HttpTransportType[requestedTransport]);
+
             const options: IHttpConnectionOptions = {
                 ...commonOptions,
                 httpClient: new TestHttpClient()
-                    .on("POST", (r) => ({ connectionId: "42", availableTransports: [] }))
-                    .on("GET", (r) => ""),
+                    .on("POST", (r) => negotiateResponse)
+                    .on("GET", (r) => new HttpResponse(204)),
                 transport: requestedTransport,
             } as IHttpConnectionOptions;
 
             const connection = new HttpConnection("http://tempuri.org", options);
+
             try {
                 await connection.start(TransferFormat.Text);
-                fail();
-                done();
+                fail("Expected connection.start to throw!");
             } catch (e) {
                 expect(e.message).toBe("Unable to initialize any of the available transports.");
-                done();
             }
         });
     });
diff --git a/clients/ts/signalr/src/ITransport.ts b/clients/ts/signalr/src/ITransport.ts
index b5c4fb1654d..936bcb420a8 100644
--- a/clients/ts/signalr/src/ITransport.ts
+++ b/clients/ts/signalr/src/ITransport.ts
@@ -1,14 +1,17 @@
 // Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
+// This will be treated as a bit flag in the future, so we keep it using power-of-two values.
 /** Specifies a specific HTTP transport type. */
 export enum HttpTransportType {
+    /** Specifies no transport preference. */
+    None = 0,
     /** Specifies the WebSockets transport. */
-    WebSockets,
+    WebSockets = 1,
     /** Specifies the Server-Sent Events transport. */
-    ServerSentEvents,
+    ServerSentEvents = 2,
     /** Specifies the Long Polling transport. */
-    LongPolling,
+    LongPolling = 4,
 }
 
 /** Specifies the transfer format for a connection. */
-- 
GitLab