import XCTest
@testable import gattaca

class TMSessionLoader:XCTestCase
{
    private let kWaitExpectation:TimeInterval = 3
    
    func testCreate()
    {
        let sessionExpectation:XCTestExpectation = expectation(
            description:"session created")
        
        guard
            
            let manager:DManager = DManager()
        
        else
        {
            return
        }
        
        XCTAssertNotNil(
            manager,
            "failed creating manager")
        
        let session:MSession = MSession()
        session.create(manager:manager)
        { (session:DSession) in
            
            sessionExpectation.fulfill()
        }
        
        waitForExpectations(timeout:kWaitExpectation)
        { (error:Error?) in
            
            let hasChanges:Bool = manager.managedObjectContext.hasChanges
            
            XCTAssertFalse(
                hasChanges,
                "failed to save changes")
        }
    }
}

import XCTest
@testable import gattaca

class TMSessionLoader:XCTestCase
{
    private let kWaitExpectation:TimeInterval = 3
    
    func testCreate()
    {
        let sessionExpectation:XCTestExpectation = expectation(
            description:"session created")
        
        let manager:DManager? = DManager()
        
        XCTAssertNotNil(
            manager,
            "failed creating manager")
        
        let session:MSession = MSession()
        session.create(manager:manager!)
        { (session:DSession) in
            
            sessionExpectation.fulfill()
        }
        
        waitForExpectations(timeout:kWaitExpectation)
        { (error:Error?) in
            
        }
    }
}

--- 
+++ 
@@ -10,14 +10,21 @@
         let sessionExpectation:XCTestExpectation = expectation(
             description:"session created")
         
-        let manager:DManager? = DManager()
+        guard
+            
+            let manager:DManager = DManager()
+        
+        else
+        {
+            return
+        }
         
         XCTAssertNotNil(
             manager,
             "failed creating manager")
         
         let session:MSession = MSession()
-        session.create(manager:manager!)
+        session.create(manager:manager)
         { (session:DSession) in
             
             sessionExpectation.fulfill()
@@ -26,6 +33,11 @@
         waitForExpectations(timeout:kWaitExpectation)
         { (error:Error?) in
             
+            let hasChanges:Bool = manager.managedObjectContext.hasChanges
+            
+            XCTAssertFalse(
+                hasChanges,
+                "failed to save changes")
         }
     }
 }
Test manager is saved on create
