mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-18 23:43:57 +01:00
transaction fetching unit tests
This commit is contained in:
@@ -978,6 +978,951 @@ final class FetchTests: BaseTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchOneFromDefaultConfiguration() {
|
||||
|
||||
let configurations: [String?] = [nil]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testString, "nil:TestEntity1:2")
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From(TestEntity1),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testString, "nil:TestEntity1:3")
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testString, "nil:TestEntity1:2")
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testString, "nil:TestEntity1:3")
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let nilObject1 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject1)
|
||||
|
||||
let nilObject2 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchOneFromSingleConfiguration() {
|
||||
|
||||
let configurations: [String?] = [nil, "Config1", "Config2"]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testNumber, 2) // configuration ambiguous
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From(TestEntity1),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testNumber, 3) // configuration ambiguous
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testString, "nil:TestEntity1:2")
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testString, "nil:TestEntity1:3")
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testString, "Config1:TestEntity1:2")
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testString, "Config1:TestEntity1:3")
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let nilObject1 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config2"),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject1)
|
||||
|
||||
let nilObject2 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config2"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchOneFromMultipleConfigurations() {
|
||||
|
||||
let configurations: [String?] = [nil, "Config1", "Config2"]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testNumber, 2) // configuration is ambiguous
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testNumber, 3) // configuration is ambiguous
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testString, "nil:TestEntity1:2")
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testString, "nil:TestEntity1:3")
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object2 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object2)
|
||||
XCTAssertEqual(object2?.testString, "Config1:TestEntity1:2")
|
||||
|
||||
let object3 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(object3)
|
||||
XCTAssertEqual(object3?.testString, "Config1:TestEntity1:3")
|
||||
|
||||
let nilObject = transaction.fetchOne(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchAllFromDefaultConfiguration() {
|
||||
|
||||
let configurations: [String?] = [nil]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects2to4 = transaction.fetchAll(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to4)
|
||||
XCTAssertEqual(objects2to4?.count, 3)
|
||||
XCTAssertEqual(
|
||||
(objects2to4 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:2",
|
||||
"nil:TestEntity1:3",
|
||||
"nil:TestEntity1:4"
|
||||
]
|
||||
)
|
||||
|
||||
let objects4to2 = transaction.fetchAll(
|
||||
From(TestEntity1),
|
||||
Where("%K < %@", "testNumber", 5),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to2)
|
||||
XCTAssertEqual(objects4to2?.count, 3)
|
||||
XCTAssertEqual(
|
||||
(objects4to2 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:4",
|
||||
"nil:TestEntity1:3",
|
||||
"nil:TestEntity1:2"
|
||||
]
|
||||
)
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects2to4 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to4)
|
||||
XCTAssertEqual(objects2to4?.count, 3)
|
||||
XCTAssertEqual(
|
||||
(objects2to4 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:2",
|
||||
"nil:TestEntity1:3",
|
||||
"nil:TestEntity1:4"
|
||||
]
|
||||
)
|
||||
|
||||
let objects4to2 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K < %@", "testNumber", 5),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to2)
|
||||
XCTAssertEqual(objects4to2?.count, 3)
|
||||
XCTAssertEqual(
|
||||
(objects4to2 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:4",
|
||||
"nil:TestEntity1:3",
|
||||
"nil:TestEntity1:2"
|
||||
]
|
||||
)
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let nilObject1 = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject1)
|
||||
|
||||
let nilObject2 = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("testNumber", isEqualTo: 0),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilObject2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchAllFromSingleConfiguration() {
|
||||
|
||||
let configurations: [String?] = [nil, "Config1", "Config2"]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects4to5 = transaction.fetchAll(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to5)
|
||||
XCTAssertEqual(objects4to5?.count, 3)
|
||||
XCTAssertEqual(
|
||||
Set((objects4to5 ?? []).map { $0.testNumber!.integerValue }),
|
||||
[4, 5] as Set<Int>
|
||||
) // configuration is ambiguous
|
||||
|
||||
let objects2to1 = transaction.fetchAll(
|
||||
From(TestEntity1),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to1)
|
||||
XCTAssertEqual(objects2to1?.count, 3)
|
||||
XCTAssertEqual(
|
||||
Set((objects2to1 ?? []).map { $0.testNumber!.integerValue }),
|
||||
[1, 2] as Set<Int>
|
||||
) // configuration is ambiguous
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects4to5 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to5)
|
||||
XCTAssertEqual(objects4to5?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects4to5 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:4",
|
||||
"nil:TestEntity1:5"
|
||||
]
|
||||
)
|
||||
|
||||
let objects2to1 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to1)
|
||||
XCTAssertEqual(objects2to1?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects2to1 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:2",
|
||||
"nil:TestEntity1:1"
|
||||
]
|
||||
)
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects4to5 = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to5)
|
||||
XCTAssertEqual(objects4to5?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects4to5 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"Config1:TestEntity1:4",
|
||||
"Config1:TestEntity1:5"
|
||||
]
|
||||
)
|
||||
|
||||
let objects2to1 = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to1)
|
||||
XCTAssertEqual(objects2to1?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects2to1 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"Config1:TestEntity1:2",
|
||||
"Config1:TestEntity1:1"
|
||||
]
|
||||
)
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let object1 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config2"),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(object1)
|
||||
|
||||
let object5 = transaction.fetchOne(
|
||||
From<TestEntity1>("Config2"),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(object5)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchAllFromMultipleConfigurations() {
|
||||
|
||||
let configurations: [String?] = [nil, "Config1", "Config2"]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects4to5 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to5)
|
||||
XCTAssertEqual(objects4to5?.count, 3)
|
||||
XCTAssertEqual(
|
||||
Set((objects4to5 ?? []).map { $0.testNumber!.integerValue }),
|
||||
[4, 5] as Set<Int>
|
||||
) // configuration is ambiguous
|
||||
|
||||
let objects2to1 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to1)
|
||||
XCTAssertEqual(objects2to1?.count, 3)
|
||||
XCTAssertEqual(
|
||||
Set((objects2to1 ?? []).map { $0.testNumber!.integerValue }),
|
||||
[1, 2] as Set<Int>
|
||||
) // configuration is ambiguous
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects4to5 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to5)
|
||||
XCTAssertEqual(objects4to5?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects4to5 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:4",
|
||||
"nil:TestEntity1:5"
|
||||
]
|
||||
)
|
||||
|
||||
let objects2to1 = transaction.fetchAll(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to1)
|
||||
XCTAssertEqual(objects2to1?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects2to1 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"nil:TestEntity1:2",
|
||||
"nil:TestEntity1:1"
|
||||
]
|
||||
)
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let objects4to5 = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects4to5)
|
||||
XCTAssertEqual(objects4to5?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects4to5 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"Config1:TestEntity1:4",
|
||||
"Config1:TestEntity1:5"
|
||||
]
|
||||
)
|
||||
|
||||
let objects2to1 = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(objects2to1)
|
||||
XCTAssertEqual(objects2to1?.count, 2)
|
||||
XCTAssertEqual(
|
||||
(objects2to1 ?? []).map { $0.testString ?? "" },
|
||||
[
|
||||
"Config1:TestEntity1:2",
|
||||
"Config1:TestEntity1:1"
|
||||
]
|
||||
)
|
||||
|
||||
let emptyObjects = transaction.fetchAll(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyObjects)
|
||||
XCTAssertEqual(emptyObjects?.count, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchCountFromDefaultConfiguration() {
|
||||
|
||||
let configurations: [String?] = [nil]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count2to4 = transaction.fetchCount(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to4)
|
||||
XCTAssertEqual(count2to4, 3)
|
||||
|
||||
let count4to2 = transaction.fetchCount(
|
||||
From(TestEntity1),
|
||||
Where("%K < %@", "testNumber", 5),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to2)
|
||||
XCTAssertEqual(count4to2, 3)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count2to4 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 1),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to4)
|
||||
XCTAssertEqual(count2to4, 3)
|
||||
|
||||
let count4to2 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K < %@", "testNumber", 5),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to2)
|
||||
XCTAssertEqual(count4to2, 3)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let nilCount1 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilCount1)
|
||||
|
||||
let nilCount2 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("testNumber", isEqualTo: 0),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilCount2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchCountFromSingleConfiguration() {
|
||||
|
||||
let configurations: [String?] = [nil, "Config1", "Config2"]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count4to5 = transaction.fetchCount(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to5)
|
||||
XCTAssertEqual(count4to5, 3)
|
||||
|
||||
let count2to1 = transaction.fetchCount(
|
||||
From(TestEntity1),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to1)
|
||||
XCTAssertEqual(count2to1, 3)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From(TestEntity1),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count4to5 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to5)
|
||||
XCTAssertEqual(count4to5, 2)
|
||||
|
||||
let count2to1 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to1)
|
||||
XCTAssertEqual(count2to1, 2)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From<TestEntity1>(nil),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count4to5 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to5)
|
||||
XCTAssertEqual(count4to5, 2)
|
||||
|
||||
let count2to1 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to1)
|
||||
XCTAssertEqual(count2to1, 2)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let nilCount1 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config2"),
|
||||
Where("%K < %@", "testNumber", 4),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilCount1)
|
||||
|
||||
let nilCount2 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config2"),
|
||||
Where("testNumber", isEqualTo: 0),
|
||||
OrderBy(.Descending("testEntityID"))
|
||||
)
|
||||
XCTAssertNil(nilCount2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatTransactions_CanFetchCountFromMultipleConfigurations() {
|
||||
|
||||
let configurations: [String?] = [nil, "Config1", "Config2"]
|
||||
self.prepareStack(configurations: configurations) { (stack) in
|
||||
|
||||
self.prepareStubsForStack(stack, configurations: configurations)
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count4to5 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to5)
|
||||
XCTAssertEqual(count4to5, 3)
|
||||
|
||||
let count2to1 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to1)
|
||||
XCTAssertEqual(count2to1, 3)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From<TestEntity1>(nil, "Config1"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count4to5 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to5)
|
||||
XCTAssertEqual(count4to5, 2)
|
||||
|
||||
let count2to1 = transaction.fetchCount(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to1)
|
||||
XCTAssertEqual(count2to1, 2)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From<TestEntity1>(nil, "Config2"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
let count4to5 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K > %@", "testNumber", 3),
|
||||
OrderBy(.Ascending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count4to5)
|
||||
XCTAssertEqual(count4to5, 2)
|
||||
|
||||
let count2to1 = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K < %@", "testNumber", 3),
|
||||
OrderBy(.Descending("testEntityID")),
|
||||
Tweak { $0.fetchLimit = 3 }
|
||||
)
|
||||
XCTAssertNotNil(count2to1)
|
||||
XCTAssertEqual(count2to1, 2)
|
||||
|
||||
let emptyCount = transaction.fetchCount(
|
||||
From<TestEntity1>("Config1", "Config2"),
|
||||
Where("%K > %@", "testNumber", 5),
|
||||
OrderBy(.Ascending("testEntityID"))
|
||||
)
|
||||
XCTAssertNotNil(emptyCount)
|
||||
XCTAssertEqual(emptyCount, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ final class GroupByTests: BaseTestCase {
|
||||
let groupBy = GroupBy("testString")
|
||||
|
||||
let request = NSFetchRequest()
|
||||
From(TestEntity1).applyToFetchRequest(request, context: dataStack.mainContext)
|
||||
_ = From(TestEntity1).applyToFetchRequest(request, context: dataStack.mainContext)
|
||||
groupBy.applyToFetchRequest(request)
|
||||
|
||||
XCTAssertNotNil(request.propertiesToGroupBy)
|
||||
|
||||
Reference in New Issue
Block a user