Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 5, 2018
1 parent bae4020 commit e8b89b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 38 additions & 1 deletion Sources/CoreModel/InMemoryStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,36 @@ public final class InMemoryStore: StoreProtocol {
/// Fetch managed objects.
public func fetch(_ fetchRequest: FetchRequest) throws -> [ManagedObject] {

fatalError()
var identifiers = data.keys.filter { $0.entity == fetchRequest.entity }

if fetchRequest.fetchOffset > 0 {

identifiers = Array(identifiers.suffix(fetchRequest.fetchOffset))
}

if fetchRequest.fetchLimit > 0 {

identifiers = Array(identifiers.prefix(fetchRequest.fetchLimit))
}

var managedObjects = identifiers.map { ManagedObject(identifier: $0, store: self) }

if let predicate = fetchRequest.predicate {

managedObjects = try managedObjects.filter {
try $0.evaluate(with: predicate)
}
}

if fetchRequest.sortDescriptors.isEmpty == false {

for sort in fetchRequest.sortDescriptors.reversed() {

//managedObjects.sort(by: { $0. })
}
}

return managedObjects
}

/// Create new managed object.
Expand Down Expand Up @@ -275,3 +304,11 @@ private extension InMemoryStore {
case toMany(Set<Identifier>)
}
}

extension InMemoryStore.ManagedObject: PredicateEvaluatable {

public func evaluate(with predicate: Predicate) throws -> Bool {


}
}
3 changes: 3 additions & 0 deletions Tests/CoreModelTests/CoreModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ final class CoreModelTests: XCTestCase {
XCTAssertFalse(person2.isDeleted)
XCTAssertEqual(person1.relationship(for: "events"), .toMany([]))
XCTAssertEqual(person2.relationship(for: "events"), .toMany([]))

XCTAssertEqual(try store.fetch(FetchRequest(entity: "Person")), [person1, person2])
XCTAssertEqual(try store.fetch(FetchRequest(entity: "Event")), [event])
}

catch { XCTFail("\(error)") }
Expand Down

0 comments on commit e8b89b4

Please sign in to comment.