-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from popei69/develop
Update unit tests for mocked data
- Loading branch information
Showing
7 changed files
with
92 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// File.swift | ||
// TemplateProject | ||
// | ||
// Created by Benoit PASQUIER on 02/02/2019. | ||
// Copyright © 2019 Benoit PASQUIER. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
final class FileDataService : CurrencyServiceProtocol { | ||
|
||
func fetchConverter(_ completion: @escaping ((Result<Converter, ErrorResult>) -> Void)) { | ||
|
||
// giving a sample json file | ||
guard let data = FileManager.readJson(forResource: "sample") else { | ||
completion(Result.failure(ErrorResult.custom(string: "No file or data"))) | ||
return | ||
} | ||
|
||
ParserHelper.parse(data: data, completion: completion) | ||
} | ||
} | ||
|
||
|
||
extension FileManager { | ||
|
||
static func readJson(forResource fileName: String ) -> Data? { | ||
|
||
let bundle = Bundle(for: FileDataService.self) | ||
if let path = bundle.path(forResource: fileName, ofType: "json") { | ||
do { | ||
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) | ||
return data | ||
} catch { | ||
// handle error | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters