diff --git a/README.md b/README.md index a9bef351..21f595e1 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ public class MyConnection : PersistentConnection #import "SignalR.h" //Client -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite/echo"]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite/echo"]; // Register for connection lifecycle events [connection setStarted:^{ @@ -131,7 +131,7 @@ public class Chat : Hub #import "SignalR.h" // Connect to the service -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite"]; // Create a proxy to the chat service SRHubProxy *chat = [hubConnection createHubProxy:@"chat"]; [chat on:@"addMessage" perform:self selector:@selector(addMessage:)]; @@ -176,7 +176,7 @@ id qs = @{ @"param1": @1, @"param2": @"another" }; -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite" queryString:qs]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite" queryString:qs]; ``` #### Hub Connections @@ -185,7 +185,7 @@ id qs = @{ @"param1": @1, @"param2": @"another" }; -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite" queryString:qs]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite" queryString:qs]; ``` ### Customizing Request Headers @@ -196,11 +196,11 @@ id headers = @{ @"param1": @1, @"param2": @"another" }; -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite"]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite"]; [connection setHeaders:headers]; //Alternative Usage -SRConnection *connection = [SRConnection connectionWithURL:@"http://localhost/mysite"]; +SRConnection *connection = [SRConnection connectionWithURLString:@"http://localhost/mysite"]; [connection addValue:@"1" forHTTPHeaderField:@"param1"]; [connection addValue:@"another" forHTTPHeaderField:@"param2"]; ``` @@ -211,11 +211,11 @@ id headers = @{ @"param1": @1, @"param2": @"another" }; -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite"]; [hubConnection setHeaders:headers]; //Alternative Usage -SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://localhost/mysite"]; +SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"http://localhost/mysite"]; [hubConnection addValue:@"1" forHTTPHeaderField:@"param1"]; [hubConnection addValue:@"another" forHTTPHeaderField:@"param2"]; ``` diff --git a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme index b1053ddb..626fc679 100644 --- a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme +++ b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.OSX.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme index 767bf913..5f51ca77 100644 --- a/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme +++ b/SignalR.Client.ObjC/SignalR.Client.ObjC.xcodeproj/xcshareddata/xcschemes/SignalR.Client.iOS.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/SignalR.Client/Hubs/SRHubResult.h b/SignalR.Client/Hubs/SRHubResult.h index 996962a1..2ff67e30 100644 --- a/SignalR.Client/Hubs/SRHubResult.h +++ b/SignalR.Client/Hubs/SRHubResult.h @@ -42,7 +42,7 @@ @property (assign, nonatomic, readwrite, getter = isHubException) BOOL hubException; /** - * An `NSString` represnting an error received from the server + * An `NSString` representing an error received from the server */ @property (strong, nonatomic, readwrite) NSString *error; @@ -52,7 +52,7 @@ @property (strong, nonatomic, readwrite) id errorData; /** - * An `NSDictionary` represnting a server state object + * An `NSDictionary` representing a server state object */ @property (strong, nonatomic, readwrite) NSDictionary *state; diff --git a/SignalR.Client/SRConnection.m b/SignalR.Client/SRConnection.m index 01d98072..fcd23734 100644 --- a/SignalR.Client/SRConnection.m +++ b/SignalR.Client/SRConnection.m @@ -153,7 +153,7 @@ - (void)negotiate:(id)transport { } else { SRLogConnectionError(@"negotiation failed %@", error); [strongSelf didReceiveError:error]; - [strongSelf didClose]; + [strongSelf stopButDoNotCallServer]; } }]; } @@ -182,7 +182,7 @@ - (void)startTransport { } else { SRLogConnectionError(@"start transport failed %@",error); [strongSelf didReceiveError:error]; - [strongSelf didClose]; + [strongSelf stopButDoNotCallServer]; } }]; } diff --git a/SignalR.Client/SRLog.h b/SignalR.Client/SRLog.h index cd9c3ade..b9b6da84 100644 --- a/SignalR.Client/SRLog.h +++ b/SignalR.Client/SRLog.h @@ -50,7 +50,7 @@ static const int ddLogLevel = LOG_LEVEL_VERBOSE; #define SRLogPrefixedWarn(type, frmt, ...) SRLogWarn(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); #define SRLogPrefixedInfo(type, frmt, ...) SRLogInfo(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); #define SRLogPrefixedDebug(type, frmt, ...) SRLogDebug(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); -#define SRLogPrefixedVerbose(type, frmt, ...) SRLogVerboase(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); +#define SRLogPrefixedVerbose(type, frmt, ...) SRLogVerbose(@"%@:\t%@", type, [NSString stringWithFormat:frmt, ##__VA_ARGS__]); #define SRLogConnectionError(frmt, ...) SRLogPrefixedError(@"CONNECTION", frmt, ##__VA_ARGS__); #define SRLogConnectionWarn(frmt, ...) SRLogPrefixedWarn(@"CONNECTION", frmt, ##__VA_ARGS__); diff --git a/Tests/Tests/SRConnectionTests.m b/Tests/Tests/SRConnectionTests.m index 45ae95b8..8f312e67 100644 --- a/Tests/Tests/SRConnectionTests.m +++ b/Tests/Tests/SRConnectionTests.m @@ -116,4 +116,44 @@ - (void) testTransportNegotiateCausesClosed }]; } +- (void)testConnectionCanRestartAfterNegotiateError { + id failingTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [SRMockClientTransport negotiateForMockTransport:failingTransport statusCode:@400 error:[NSError errorWithDomain:@"UNIT TEST" code:NSURLErrorTimedOut userInfo:nil]]; + + id successTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [[successTransport expect] negotiate:[OCMArg any] connectionData:[OCMArg any] completionHandler:[OCMArg any]]; + + SRConnection* connection = [[SRConnection alloc] initWithURLString:@"http://localhost:0000"]; + [connection start: failingTransport]; + XCTAssertEqual(connection.state, disconnected); + [connection start: successTransport]; + XCTAssertEqual(connection.state, connecting); + [successTransport verify]; + +} + +- (void)testConnectionCanRestartAfterStartError { + id failingTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [SRMockClientTransport startForMockTransport:failingTransport statusCode:@400 error:[[NSError alloc]initWithDomain:@"Expected" code:42 userInfo:nil]]; + id json = @{ + @"ConnectionId": @"10101", + @"ConnectionToken": @"10101010101", + @"DisconnectTimeout": @30, + @"ProtocolVersion": @"1.3.0.0" + }; + [SRMockClientTransport negotiateForMockTransport:failingTransport statusCode:@200 json:json]; + + id successTransport = [OCMockObject niceMockForProtocol:@protocol(SRClientTransportInterface)]; + [SRMockClientTransport negotiateForMockTransport:successTransport statusCode:@200 json:json]; + [[successTransport expect] start:[OCMArg any] connectionData:[OCMArg any] completionHandler:[OCMArg any]]; + + SRConnection* connection = [[SRConnection alloc] initWithURLString:@"http://localhost:0000"]; + [connection start: failingTransport]; + XCTAssertEqual(connection.state, disconnected); + [connection start: successTransport]; + XCTAssertEqual(connection.state, connecting); + [successTransport verify]; + +} + @end