This commit is contained in:
John Rommel Estropia
2016-07-21 02:45:42 +09:00
parent 267c21063a
commit a638620858
85 changed files with 1621 additions and 1819 deletions

View File

@@ -36,11 +36,12 @@ class BaseTestCase: XCTestCase {
// MARK: Internal
@nonobjc
func prepareStack<T>(_ configurations: [String?] = [nil], @noescape _ closure: (dataStack: DataStack) -> T) -> T {
@discardableResult
func prepareStack<T>(configurations: [String?] = [nil], _ closure: @noescape (dataStack: DataStack) -> T) -> T {
let stack = DataStack(
modelName: "Model",
bundle: Bundle(forClass: self.dynamicType)
bundle: Bundle(for: self.dynamicType)
)
do {
@@ -48,9 +49,9 @@ class BaseTestCase: XCTestCase {
try stack.addStorageAndWait(
SQLiteStore(
fileURL: SQLiteStore.defaultRootDirectory
.URLByAppendingPathComponent(UUID().UUIDString)
.URLByAppendingPathComponent("\(self.dynamicType)_\(($0 ?? "-null-")).sqlite"),
fileURL: try SQLiteStore.defaultRootDirectory
.appendingPathComponent(UUID().uuidString)
.appendingPathComponent("\(self.dynamicType)_\(($0 ?? "-null-")).sqlite"),
configuration: $0,
localStorageOptions: .recreateStoreOnModelMismatch
)
@@ -65,7 +66,7 @@ class BaseTestCase: XCTestCase {
}
@nonobjc
func expectLogger<T>(_ expectations: [TestLogger.Expectation], @noescape closure: () -> T) -> T {
func expectLogger<T>(_ expectations: [TestLogger.Expectation], closure: @noescape () -> T) -> T {
CoreStore.logger = TestLogger(self.prepareLoggerExpectations(expectations))
defer {
@@ -126,7 +127,7 @@ class BaseTestCase: XCTestCase {
private func deleteStores() {
_ = try? FileManager.defaultManager().removeItemAtURL(SQLiteStore.defaultRootDirectory)
_ = try? FileManager.default.removeItem(at: SQLiteStore.defaultRootDirectory)
}
}
@@ -152,7 +153,7 @@ class TestLogger: CoreStoreLogger {
// MARK: CoreStoreLogger
func log(_ level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
func log(level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
switch level {
@@ -162,12 +163,12 @@ class TestLogger: CoreStoreLogger {
}
}
func log(_ error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
func log(error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
self.fulfill(.logError)
}
func assert(@autoclosure _ condition: () -> Bool, @autoclosure message: () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
func assert(_ condition: @autoclosure () -> Bool, message: @autoclosure () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
if condition() {

View File

@@ -30,9 +30,9 @@ class BaseTestDataTestCase: BaseTestCase {
@nonobjc
func prepareTestDataForStack(_ stack: DataStack, configurations: [String?] = [nil]) {
stack.beginSynchronous { (transaction) in
_ = stack.beginSynchronous { (transaction) in
for (configurationIndex, configuration) in configurations.enumerate() {
for (configurationIndex, configuration) in configurations.enumerated() {
let configurationOrdinal = configurationIndex + 1
if configuration == nil || configuration == "Config1" {
@@ -40,16 +40,16 @@ class BaseTestDataTestCase: BaseTestCase {
for idIndex in 1 ... 5 {
let object = transaction.create(Into<TestEntity1>(configuration))
object.testEntityID = NSNumber(integer: (configurationOrdinal * 100) + idIndex)
object.testEntityID = NSNumber(value: (configurationOrdinal * 100) + idIndex)
object.testNumber = idIndex
object.testDate = self.dateFormatter.dateFromString("2000-\(configurationOrdinal)-\(idIndex)T00:00:00Z")
object.testDate = self.dateFormatter.date(from: "2000-\(configurationOrdinal)-\(idIndex)T00:00:00Z")
object.testBoolean = (idIndex % 2) == 1
object.testDecimal = NSDecimalNumber(string: "\(idIndex)")
let string = "\(configuration ?? "nil"):TestEntity1:\(idIndex)"
object.testString = string
object.testData = (string as NSString).dataUsingEncoding(NSUTF8StringEncoding)
object.testData = (string as NSString).data(using: String.Encoding.utf8.rawValue)
}
}
if configuration == nil || configuration == "Config2" {
@@ -57,16 +57,16 @@ class BaseTestDataTestCase: BaseTestCase {
for idIndex in 1 ... 5 {
let object = transaction.create(Into<TestEntity2>(configuration))
object.testEntityID = NSNumber(integer: (configurationOrdinal * 200) + idIndex)
object.testEntityID = NSNumber(value: (configurationOrdinal * 200) + idIndex)
object.testNumber = idIndex
object.testDate = self.dateFormatter.dateFromString("2000-\(configurationOrdinal)-\(idIndex)T00:00:00Z")
object.testDate = self.dateFormatter.date(from: "2000-\(configurationOrdinal)-\(idIndex)T00:00:00Z")
object.testBoolean = (idIndex % 2) == 1
object.testDecimal = NSDecimalNumber(string: "\(idIndex)")
let string = "\(configuration ?? "nil"):TestEntity2:\(idIndex)"
object.testString = string
object.testData = (string as NSString).dataUsingEncoding(NSUTF8StringEncoding)
object.testData = (string as NSString).data(using: String.Encoding.utf8.rawValue)
}
}
}