mas/MasKitTests/Errors/MASErrorTestCase.swift

112 lines
3 KiB
Swift
Raw Normal View History

2018-02-11 22:41:21 +00:00
//
// MASErrorTestCase.swift
// mas-tests
//
// Created by Ben Chatelain on 2/11/18.
// Copyright © 2018 Andrew Naylor. All rights reserved.
//
@testable import MasKit
2018-02-11 22:41:21 +00:00
import XCTest
import Foundation
class MASErrorTestCase: XCTestCase {
2018-02-11 23:11:09 +00:00
private let errorDomain = "MAS"
2018-02-11 22:41:21 +00:00
var error: MASError!
2018-02-11 23:11:09 +00:00
var nserror: NSError!
/// Convenience property for setting the value which will be use for the localized description
/// value of the next NSError created. Only used when the NSError does not have a user info
/// entry for localized description.
var localizedDescription: String {
get { return "dummy value" }
set {
NSError.setUserInfoValueProvider(forDomain: errorDomain) { (error: Error, userInfoKey: String) -> Any? in
return newValue
}
}
}
2018-02-11 22:41:21 +00:00
override func setUp() {
super.setUp()
2018-02-11 23:18:57 +00:00
nserror = NSError(domain: errorDomain, code: 999)
localizedDescription = "foo"
2018-02-11 22:41:21 +00:00
}
override func tearDown() {
2018-02-11 23:11:09 +00:00
nserror = nil
error = nil
2018-02-11 22:41:21 +00:00
super.tearDown()
}
func testNotSignedIn() {
error = .notSignedIn
XCTAssertEqual(error.description, "Not signed in")
}
2018-02-11 23:11:09 +00:00
func testSignInFailed() {
error = .signInFailed(error: nil)
XCTAssertEqual(error.description, "Sign in failed")
}
func testSignInFailedError() {
error = .signInFailed(error: nserror)
2018-02-11 23:18:57 +00:00
XCTAssertEqual(error.description, "Sign in failed: foo")
}
func testAlreadySignedIn() {
error = .alreadySignedIn
XCTAssertEqual(error.description, "Already signed in")
}
func testPurchaseFailed() {
error = .purchaseFailed(error: nil)
XCTAssertEqual(error.description, "Download request failed")
}
func testPurchaseFailedError() {
error = .purchaseFailed(error: nserror)
XCTAssertEqual(error.description, "Download request failed: foo")
}
func testDownloadFailed() {
error = .downloadFailed(error: nil)
XCTAssertEqual(error.description, "Download failed")
}
func testDownloadFailedError() {
error = .downloadFailed(error: nserror)
XCTAssertEqual(error.description, "Download failed: foo")
}
func testNoDownloads() {
error = .noDownloads
XCTAssertEqual(error.description, "No downloads began")
}
func testCancelled() {
error = .cancelled
XCTAssertEqual(error.description, "Download cancelled")
}
func testSearchFailed() {
error = .searchFailed
XCTAssertEqual(error.description, "Search failed")
}
func testNoSearchResultsFound() {
error = .noSearchResultsFound
XCTAssertEqual(error.description, "No results found")
2018-02-11 23:11:09 +00:00
}
2018-12-27 21:50:38 +00:00
func testNotInstalled() {
error = .notInstalled
XCTAssertEqual(error.description, "Not installed")
}
func testUninstallFailed() {
error = .uninstallFailed
XCTAssertEqual(error.description, "Uninstall failed")
}
2018-02-11 22:41:21 +00:00
}