             print("GET on /userMiddleware - received header \(middleware.header)")
             respondWith(user, nil)
         }
-        
-        
+
         buildServerTest(router, timeout: 30)
             .request("get", path: "/userMiddleware", headers: ["TestHeader": "Hello"])
             .hasStatus(.OK)
             .hasContentType(withPrefix: "application/json")
             .hasData(user)
-            
+
             .request("get", path: "/userMiddleware")
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testMultipleMiddlewareGetSingleton() {
         let user = User(id: 5, name: "Neil")
-        
+
         router.get("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, respondWith: (User?, RequestError?) -> Void) in
             print("GET on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
             respondWith(user, nil)
         }
-        
-        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
-        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
-        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
-        
+
+        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
+        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
+        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
+
         buildServerTest(router, timeout: 30)
             // Test that handler is invoked successfully when all middlewares are satisfied
             .request("get", path: "/userMultiMiddleware", headers: goodHeaders)
             .hasStatus(.OK)
             .hasContentType(withPrefix: "application/json")
             .hasData(user)
-            
+
             // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
             .request("get", path: "/userMultiMiddleware", headers: missing2ndHeader)
             .hasStatus(.notAcceptable)
             .hasNoData()
-            
+
             // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
             .request("get", path: "/userMultiMiddleware", headers: missing3rdHeader)
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testSingleMiddlewareGetArray() {
         let userArray = [User(id: 1, name: "Andy"), User(id: 2, name: "Dave")]
-        
+
         router.get("/userMiddleware") { (middleware: UserMiddleware, respondWith: ([User]?, RequestError?) -> Void) in
             print("GET on /userMiddleware - received header \(middleware.header)")
             respondWith(userArray, nil)
         }
-        
-        
+
         buildServerTest(router, timeout: 30)
             .request("get", path: "/userMiddleware", headers: ["TestHeader": "Hello"])
             .hasStatus(.OK)
             .hasContentType(withPrefix: "application/json")
             .hasData(userArray)
-            
+
             .request("get", path: "/userMiddleware")
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testMultipleMiddlewareGetArray() {
         let userArray = [User(id: 1, name: "Andy"), User(id: 2, name: "Dave")]
 

            .hasNoData()
            .has { _ in XCTAssertNil(self.userStore[1]) }

            
            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("delete", path: "/userMultiMiddleware/1", headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()
            
            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("delete", path: "/userMultiMiddleware/1", headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()
            
            .run()
    }
    
    func testSingleMiddlewareDeleteParameters() {
        
        router.delete("/userMiddleware") { (middleware: UserMiddleware, query: MyQuery, respondWith: (RequestError?) -> Void) in
            print("DELETE on /userMiddleware - received header \(middleware.header)")
            guard let _ = self.userStore.removeValue(forKey: query.id) else {
                respondWith(.notFound)
                return
            }
            respondWith(nil)
        }
        
        
        buildServerTest(router, timeout: 30)
            .request("delete", path: "/userMiddleware?id=1", headers: ["TestHeader": "Hello"])
            .hasStatus(.noContent)
            .hasNoData()
            .has { _ in XCTAssertNil(self.userStore[1]) }
            
            .request("delete", path: "/userMiddleware?id=1")
            .hasStatus(.badRequest)
            .hasNoData()
            
            .run()
    }
    
    func testMultipleMiddlewareDeleteParameters() {
        
        router.delete("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, query: MyQuery,  respondWith: (RequestError?) -> Void) in
            print("DELETE on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            guard let _ = self.userStore.removeValue(forKey: query.id) else {
                respondWith(.notFound)
                return
            }
            respondWith(nil)
        }
        
        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
        
        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("delete", path: "/userMultiMiddleware?id=1", headers: goodHeaders)
            .hasStatus(.noContent)
            .hasNoData()
            .has { _ in XCTAssertNil(self.userStore[1]) }
            
            
            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("delete", path: "/userMultiMiddleware?id=1", headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()
            
            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("delete", path: "/userMultiMiddleware?id=1", headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()
            
            .run()
    }
    
    func testSingleMiddlewarePost() {
        router.post("/userMiddleware") { (middleware: UserMiddleware, user: User, respondWith: (User?, RequestError?) -> Void) in
            print("POST on /userMiddleware for user \(user) - received header \(middleware.header)")

            print("GET on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            respondWith(userArray, nil)
        }

        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]

        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("get", path: "/userMultiMiddleware", headers: goodHeaders)
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(userArray)

            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("get", path: "/userMultiMiddleware", headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()

            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("get", path: "/userMultiMiddleware", headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testSingleMiddlewareGetIdentifier() {
        // Expected user: User(id: 1, name: "Andy")
        guard let user = userStore[1] else {
            XCTFail("no value found for userStore[1]")
            return
        }

        router.get("/userMiddleware") { (middleware: UserMiddleware, id: Int, respondWith: (User?, RequestError?) -> Void) in
            print("GET with identifier on /userMiddleware - received header \(middleware.header)")
            let user = self.userStore[id]
            respondWith(user, nil)
        }

        buildServerTest(router, timeout: 30)
            .request("get", path: "/userMiddleware/1", headers: ["TestHeader": "Hello"])
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)

            .request("get", path: "/userMiddleware/1")
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testMultipleMiddlewareGetIdentifier() {
        // Expected user: User(id: 1, name: "Andy")
        guard let user = userStore[1] else {
            XCTFail("no value found for userStore[1]")
            return
        }

        router.get("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, id: Int, respondWith: (User?, RequestError?) -> Void) in
            print("GET with identifier: \(id) on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            respondWith(user, nil)
        }

        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]

        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("get", path: "/userMultiMiddleware/1", headers: goodHeaders)
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)

            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("get", path: "/userMultiMiddleware/1", headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()

            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("get", path: "/userMultiMiddleware/1", headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testSingleMiddlewareGetIdentifierCodableArray() {
        // Expected tuples [[1: User(id: 1, name: "Andy")], [2: User(id: 2, name: "Dave")], [3: User(id: 3, name: "Ian")]]
        var intTuple = [(Int, User)]()
        self.userStore.forEach { intTuple.append(($0.0, $0.1)) }
        let expectedIntData: [[String: User]] = intTuple.map({ [$0.value: $1] })

        router.get("/userMiddleware") { (middleware: UserMiddleware, respondWith: ([(Int, User)]?, RequestError?) -> Void) in
            print("GET Identifier Codable tuple on /userMiddleware - received header \(middleware.header)")
            var intTuple = [(Int, User)]()
            self.userStore.forEach { intTuple.append(($0.0, $0.1)) }
            respondWith(intTuple, nil)
        }

        buildServerTest(router, timeout: 30)
            .request("get", path: "/userMiddleware", headers: ["TestHeader": "Hello"])
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(expectedIntData)

            .request("get", path: "/userMiddleware")
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testMultipleMiddlewareGetIdentifierCodableArray() {
        // Expected tuples [[1: User(id: 1, name: "Andy")], [2: User(id: 2, name: "Dave")], [3: User(id: 3, name: "Ian")]]
        var intTuple = [(Int, User)]()
        self.userStore.forEach { intTuple.append(($0.0, $0.1)) }
        let expectedIntData: [[String: User]] = intTuple.map({ [$0.value: $1] })

        router.get("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, respondWith: ([(Int, User)]?, RequestError?) -> Void) in
            print("GET Identifier Codable on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            var intTuple = [(Int, User)]()
            self.userStore.forEach { intTuple.append(($0.0, $0.1)) }
            respondWith(intTuple, nil)
        }

        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]

        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("get", path: "/userMultiMiddleware", headers: goodHeaders)
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(expectedIntData)

            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("get", path: "/userMultiMiddleware", headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()

            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("get", path: "/userMultiMiddleware", headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testSingleMiddlewareGetSingletonParameters() {
        // Expected user: User(id: 1, name: "Andy")
        guard let user = userStore[1] else {
            XCTFail("no value found for userStore[1]")
            return
        }

        router.get("/userMiddleware") { (middleware: UserMiddleware, query: MyQuery, respondWith: (User?, RequestError?) -> Void) in
            print("GET single with parameters on /userMiddleware - received header \(middleware.header)")
            let user = self.userStore[query.id]
            respondWith(user, nil)
        }

        buildServerTest(router, timeout: 30)
            .request("get", path: "/userMiddleware?id=1", headers: ["TestHeader": "Hello"])
            .hasStatus(.OK)
