Skip to content

Instantly share code, notes, and snippets.

@MarcoSantarossa
Last active July 27, 2017 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoSantarossa/4a8ef480bf362a5d6be112473a55c08a to your computer and use it in GitHub Desktop.
Save MarcoSantarossa/4a8ef480bf362a5d6be112473a55c08a to your computer and use it in GitHub Desktop.
import Foundation
import StorageKit
import RealmSwift
final class SpyStorageContext: StorageContext {
fileprivate(set) var createCalledCount = 0
fileprivate(set) var createTypes = [Object.Type]()
fileprivate(set) var addCalledCount = 0
fileprivate(set) var addEntityArguments = [StorageEntityType]()
}
extension SpyStorageContext {
func create<T: StorageEntityType>() throws -> T? {
guard let entityToCreate = T.self as? Object.Type else { return nil }
createCalledCount += 1
createTypes.append(entityToCreate)
return entityToCreate.init() as? T
}
func add<T: StorageEntityType>(_ entity: T) throws {
addCalledCount += 1
addEntityArguments.append(entity)
}
func add<T>(_ entities: [T]) throws where T : StorageEntityType {}
}
extension SpyStorageContext {
func update(transform: @escaping () -> Void) throws {}
}
extension SpyStorageContext {
func fetch<T: StorageEntityType>(predicate: NSPredicate?, sortDescriptors: [SortDescriptor]?, completion: @escaping FetchCompletionClosure<T>) {}
}
extension SpyStorageContext {
func delete<T: StorageEntityType>(_ entity: T) throws {}
func delete<T: StorageEntityType>(_ entities: [T]) throws {}
func deleteAll<T: StorageEntityType>(_ entityType: T.Type) throws {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment