 import Cocoa
 import CoreData
 import XCTest
-import PersistentStoreMigrationKit
+@testable import PersistentStoreMigrationKit
 
 class PersistentStoreMigrationKitTests: XCTestCase {
 	private var models = [NSManagedObjectModel]()

	
	private func initializeStoreAtURL(storeURL: NSURL) throws {
		let initialPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: models.first!)
		let _ = try initialPersistentStoreCoordinator.addPersistentStoreWithType(storeType, configuration: nil, URL: storeURL, options: nil)
	}
    
    func testManualStoreMigration() throws {
		let storeURL = workingDirectoryURL.URLByAppendingPathComponent("Manually Migrated Store", isDirectory: false)
		do {
			try initializeStoreAtURL(storeURL)
		} catch let error as NSError {
			XCTFail("Could not initialize persistent store: \(error)")
			throw error
		}
		
		for newerModel in models[1..<models.endIndex] {
			let existingStoreMetadata: [String: AnyObject]
			do {
				existingStoreMetadata = try NSPersistentStoreCoordinator.metadataForPersistentStoreOfType(storeType, URL: storeURL)
			} catch let error as NSError {
				XCTFail("Could not retrieve store metadata: \(error)")
				throw error
			}
			let existingStoreVersionHashes = existingStoreMetadata[NSStoreModelVersionHashesKey] as! [NSObject: AnyObject]!
			XCTAssertNotNil(existingStoreVersionHashes, "Could not retrieve version hashes from \(storeURL).")

		workingDirectoryURL = temporaryDirectoryURL.URLByAppendingPathComponent(NSProcessInfo.processInfo().globallyUniqueString)
		do {
			try NSFileManager.defaultManager().createDirectoryAtURL(workingDirectoryURL, withIntermediateDirectories: true, attributes: nil)
		} catch {
			XCTFail("Could not create working directory: \(error)")
		}
    }
