-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockNetworkManager.swift
40 lines (33 loc) · 991 Bytes
/
MockNetworkManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// MockNetworkManager.swift
// MVPSwiftTests
//
// Created by David Seca on 15.04.20.
// Copyright © 2020 David Seca. All rights reserved.
//
import XCTest
@testable import MVPSwift
class MockNetworkManager: NetworkManagerProtocol {
func getContent(content: Content, completion: @escaping ((Data?, Bool) -> ())) {
let resource: String
switch(content) {
case .accounts: resource = "accounts-test-data"
}
let json = getJsonFromFile(resource)
return completion(json, true)
}
private func getJsonFromFile(_ resource: String) -> Data? {
let bundle = Bundle(for: type(of: self))
guard let url = bundle.url(forResource: resource, withExtension: "json") else {
XCTFail("Missing file: \(resource).json")
return nil
}
var json = Data()
do {
json = try Data(contentsOf: url)
} catch {
}
print(json)
return json
}
}