ソースを参照

Added initialization tests for downloads with and without custom headers.

Christian Noon 10 年 前
コミット
a89e4d831d
1 ファイル変更41 行追加0 行削除
  1. 41 0
      Tests/DownloadTests.swift

+ 41 - 0
Tests/DownloadTests.swift

@@ -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