Skip to content

Commit

Permalink
Added tests around all combinations of Manager initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Sep 22, 2015
1 parent 744e8e2 commit 24f3868
Showing 1 changed file with 109 additions and 1 deletion.
110 changes: 109 additions & 1 deletion Tests/ManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,117 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Alamofire
@testable import Alamofire
import Foundation
import XCTest

class ManagerTestCase: BaseTestCase {

// MARK: Initialization Tests

func testInitializerWithDefaultArguments() {
// Given, When
let manager = Manager()

// Then
XCTAssertNotNil(manager.session.delegate, "session delegate should not be nil")
XCTAssertTrue(manager.delegate === manager.session.delegate, "manager delegate should equal session delegate")
XCTAssertNil(manager.session.serverTrustPolicyManager, "session server trust policy manager should be nil")
}

func testInitializerWithSpecifiedArguments() {
// Given
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let delegate = Manager.SessionDelegate()
let serverTrustPolicyManager = ServerTrustPolicyManager(policies: [:])

// When
let manager = Manager(
configuration: configuration,
delegate: delegate,
serverTrustPolicyManager: serverTrustPolicyManager
)

// Then
XCTAssertNotNil(manager.session.delegate, "session delegate should not be nil")
XCTAssertTrue(manager.delegate === manager.session.delegate, "manager delegate should equal session delegate")
XCTAssertNotNil(manager.session.serverTrustPolicyManager, "session server trust policy manager should not be nil")
}

func testThatFailableInitializerSucceedsWithDefaultArguments() {
// Given
let delegate = Manager.SessionDelegate()
let session: NSURLSession = {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
return NSURLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)
}()

// When
let manager = Manager(session: session, delegate: delegate)

// Then
if let manager = manager {
XCTAssertTrue(manager.delegate === manager.session.delegate, "manager delegate should equal session delegate")
XCTAssertNil(manager.session.serverTrustPolicyManager, "session server trust policy manager should be nil")
} else {
XCTFail("manager should not be nil")
}
}

func testThatFailableInitializerSucceedsWithSpecifiedArguments() {
// Given
let delegate = Manager.SessionDelegate()
let session: NSURLSession = {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
return NSURLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)
}()

let serverTrustPolicyManager = ServerTrustPolicyManager(policies: [:])

// When
let manager = Manager(session: session, delegate: delegate, serverTrustPolicyManager: serverTrustPolicyManager)

// Then
if let manager = manager {
XCTAssertTrue(manager.delegate === manager.session.delegate, "manager delegate should equal session delegate")
XCTAssertNotNil(manager.session.serverTrustPolicyManager, "session server trust policy manager should not be nil")
} else {
XCTFail("manager should not be nil")
}
}

func testThatFailableInitializerFailsWithWhenDelegateDoesNotEqualSessionDelegate() {
// Given
let delegate = Manager.SessionDelegate()
let session: NSURLSession = {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
return NSURLSession(configuration: configuration, delegate: Manager.SessionDelegate(), delegateQueue: nil)
}()

// When
let manager = Manager(session: session, delegate: delegate)

// Then
XCTAssertNil(manager, "manager should be nil")
}

func testThatFailableInitializerFailsWhenSessionDelegateIsNil() {
// Given
let delegate = Manager.SessionDelegate()
let session: NSURLSession = {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
return NSURLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
}()

// When
let manager = Manager(session: session, delegate: delegate)

// Then
XCTAssertNil(manager, "manager should be nil")
}

// MARK: Start Requests Immediately Tests

func testSetStartRequestsImmediatelyToFalseAndResumeRequest() {
// Given
let manager = Alamofire.Manager()
Expand Down Expand Up @@ -52,6 +158,8 @@ class ManagerTestCase: BaseTestCase {
XCTAssertTrue(response?.statusCode == 200, "response status code should be 200")
}

// MARK: Deinitialization Tests

func testReleasingManagerWithPendingRequestDeinitializesSuccessfully() {
// Given
var manager: Manager? = Alamofire.Manager()
Expand Down

0 comments on commit 24f3868

Please sign in to comment.