|
|
@@ -24,6 +24,47 @@ import Alamofire
|
|
|
import Foundation
|
|
|
import XCTest
|
|
|
|
|
|
+class DownloadInitializationTestCase: BaseTestCase {
|
|
|
+ let searchPathDirectory: NSSearchPathDirectory = .CachesDirectory
|
|
|
+ let searchPathDomain: NSSearchPathDomainMask = .UserDomainMask
|
|
|
+
|
|
|
+ func testDownloadClassMethodWithMethodURLAndDestination() {
|
|
|
+ // Given
|
|
|
+ let URLString = "http://httpbin.org/"
|
|
|
+ let destination = Request.suggestedDownloadDestination(directory: searchPathDirectory, domain: searchPathDomain)
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = Alamofire.download(.GET, URLString, destination: destination)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertNotNil(request.request, "request should not be nil")
|
|
|
+ XCTAssertEqual(request.request.HTTPMethod ?? "", "GET", "request HTTP method should be GET")
|
|
|
+ XCTAssertEqual(request.request.URL!, NSURL(string: URLString)!, "request URL should be equal")
|
|
|
+ XCTAssertNil(request.response, "response should be nil")
|
|
|
+ }
|
|
|
+
|
|
|
+ func testDownloadClassMethodWithMethodURLHeadersAndDestination() {
|
|
|
+ // Given
|
|
|
+ let URLString = "http://httpbin.org/"
|
|
|
+ let destination = Request.suggestedDownloadDestination(directory: searchPathDirectory, domain: searchPathDomain)
|
|
|
+
|
|
|
+ // When
|
|
|
+ let request = Alamofire.download(.GET, URLString, headers: ["Authorization": "123456"], destination: destination)
|
|
|
+
|
|
|
+ // Then
|
|
|
+ XCTAssertNotNil(request.request, "request should not be nil")
|
|
|
+ XCTAssertEqual(request.request.HTTPMethod ?? "", "GET", "request HTTP method should be GET")
|
|
|
+ XCTAssertEqual(request.request.URL!, NSURL(string: URLString)!, "request URL should be equal")
|
|
|
+
|
|
|
+ let authorizationHeader = request.request.valueForHTTPHeaderField("Authorization") ?? ""
|
|
|
+ XCTAssertEqual(authorizationHeader, "123456", "Authorization header is incorrect")
|
|
|
+
|
|
|
+ XCTAssertNil(request.response, "response should be nil")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: -
|
|
|
+
|
|
|
class DownloadResponseTestCase: BaseTestCase {
|
|
|
// MARK: - Properties
|
|
|
|