2019-10-19 08:21:02 +11:00
|
|
|
//
|
|
|
|
// FeedlyCheckpointOperationTests.swift
|
|
|
|
// AccountTests
|
|
|
|
//
|
|
|
|
// Created by Kiel Gillard on 25/10/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
@testable import Account
|
2020-01-15 22:10:06 -08:00
|
|
|
import RSCore
|
2019-10-19 08:21:02 +11:00
|
|
|
|
|
|
|
class FeedlyCheckpointOperationTests: XCTestCase {
|
|
|
|
|
|
|
|
class TestDelegate: FeedlyCheckpointOperationDelegate {
|
|
|
|
|
|
|
|
var didReachCheckpointExpectation: XCTestExpectation?
|
|
|
|
|
|
|
|
func feedlyCheckpointOperationDidReachCheckpoint(_ operation: FeedlyCheckpointOperation) {
|
|
|
|
didReachCheckpointExpectation?.fulfill()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCallback() {
|
|
|
|
let delegate = TestDelegate()
|
|
|
|
delegate.didReachCheckpointExpectation = expectation(description: "Did Reach Checkpoint")
|
|
|
|
|
|
|
|
let operation = FeedlyCheckpointOperation()
|
|
|
|
operation.checkpointDelegate = delegate
|
|
|
|
|
|
|
|
let didFinishExpectation = expectation(description: "Did Finish")
|
2020-01-15 22:10:06 -08:00
|
|
|
operation.completionBlock = { _ in
|
2019-10-19 08:21:02 +11:00
|
|
|
didFinishExpectation.fulfill()
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:37:43 -08:00
|
|
|
MainThreadOperationQueue.shared.add(operation)
|
2019-10-19 08:21:02 +11:00
|
|
|
|
|
|
|
waitForExpectations(timeout: 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCancellation() {
|
|
|
|
let didReachCheckpointExpectation = expectation(description: "Did Reach Checkpoint")
|
|
|
|
didReachCheckpointExpectation.isInverted = true
|
|
|
|
|
|
|
|
let delegate = TestDelegate()
|
|
|
|
delegate.didReachCheckpointExpectation = didReachCheckpointExpectation
|
|
|
|
|
|
|
|
let operation = FeedlyCheckpointOperation()
|
|
|
|
operation.checkpointDelegate = delegate
|
|
|
|
|
|
|
|
let didFinishExpectation = expectation(description: "Did Finish")
|
2020-01-15 22:10:06 -08:00
|
|
|
operation.completionBlock = { _ in
|
2019-10-19 08:21:02 +11:00
|
|
|
didFinishExpectation.fulfill()
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:37:43 -08:00
|
|
|
MainThreadOperationQueue.shared.add(operation)
|
2019-10-19 08:21:02 +11:00
|
|
|
|
2020-01-17 08:27:20 +11:00
|
|
|
MainThreadOperationQueue.shared.cancelOperations([operation])
|
2019-10-19 08:21:02 +11:00
|
|
|
|
|
|
|
waitForExpectations(timeout: 1)
|
|
|
|
}
|
|
|
|
}
|