// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AutoRestParameterizedCustomHostTest
import AzureCore
import XCTest

class AutoRestParameterizedCustomHostTest: XCTestCase {
    var client: AutoRestParameterizedCustomHostTestClient!

    override func setUpWithError() throws {
        guard let endpoint = URL(string: "http://local") else {
            fatalError("Can't creat a base URL")
        }
        client = try AutoRestParameterizedCustomHostTestClient(
            subscriptionId: "test12",
            dnsSuffix: "host:3000",
            endpoint: endpoint,
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestParameterizedCustomHostTestClientOptions()
        )
    }

    func test_getEmpty200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getEmpty")

        let options = GetEmptyOptions(
            keyVersion: "v1"
        )

        client.paths.getEmpty(
            vault: "http://lo",
            secret: "cal",
            keyName: "key1",
            withOptions: options
        ) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getEmpty failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import Foundation

import AutoRestUrlMutliCollectionFormatTest
import AzureCore
import XCTest

class AutoRestUrlMutliCollectionFormatTest: XCTestCase {
    var client: AutoRestUrlMutliCollectionFormatTestClient!

    override func setUpWithError() throws {
        client = try AutoRestUrlMutliCollectionFormatTestClient(
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestUrlMutliCollectionFormatTestClientOptions()
        )
    }

    func test_queries_arrayStringMultiNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringMultiNull")

        client.queries.arrayStringMultiNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringMultiNull failed error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_queries_arrayStringMultiEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringMultiEmpty")

        let options = ArrayStringMultiEmptyOptions(
            arrayQuery: []
        )

        client.queries.arrayStringMultiEmpty(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringMultiEmpty failed error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_queries_arrayStringMultiValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringMultiValid")

        let options = ArrayStringMultiValidOptions(
            arrayQuery: ["ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""]
        )

        client.queries.arrayStringMultiValid(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringMultiValid failed error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AutoRestUrlTest
import AzureCore
import XCTest

// swiftlint:disable function_body_length
// swiftlint:disable type_body_length
// swiftlint:disable file_length

class AutoRestUrlPathItemsTest: XCTestCase {
    var client: AutoRestUrlTestClient!

    override func setUpWithError() throws {
        client = try AutoRestUrlTestClient(
            globalStringPath: "globalStringPath",
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestUrlTestClientOptions()
        )
    }

    func test_Pathitems_getGlobalQueryNull_200() throws {
        let expectation = XCTestExpectation(description: "Call pathitems_getGlobalQueryNull")

        let options = GetGlobalQueryNullOptions(
            pathItemStringQuery: "pathItemStringQuery",
            localStringQuery: "localStringQuery"
        )
        client.pathItems.getGlobalQueryNull(
            pathItemStringPath: "pathItemStringPath",
            localStringPath: "localStringPath",
            withOptions: options
        ) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call pathitems_getGlobalQueryNull failed error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Pathitems_getGlobalAndLocalQueryNull_200() throws {
        let expectation = XCTestExpectation(description: "Call pathitems.getGlobalAndLocalQueryNull")

        let options = GetGlobalAndLocalQueryNullOptions(pathItemStringQuery: "pathItemStringQuery")
        client.pathItems.getGlobalAndLocalQueryNull(
            pathItemStringPath: "pathItemStringPath",
            localStringPath: "localStringPath",
            withOptions: options
        ) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call pathitems.getGlobalAndLocalQueryNull failed error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Pathitems_getLocalPathItemQueryNull_200() throws {
        let expectation = XCTestExpectation(description: "Call pathitems_getLocalPathItemQueryNull")
        client.globalStringQuery = "globalStringQuery"
        client.pathItems.getLocalPathItemQueryNull(
            pathItemStringPath: "pathItemStringPath",
            localStringPath: "localStringPath"
        ) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call pathitems_getLocalPathItemQueryNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Pathitems_listAllWithValues_200() throws {
        let expectation = XCTestExpectation(description: "Call pathitems_listAllWithValues")
        client.globalStringQuery = "globalStringQuery"
        let options = GetAllWithValuesOptions(
            pathItemStringQuery: "pathItemStringQuery",
            localStringQuery: "localStringQuery"
        )
        client.pathItems.getAllWithValues(
            pathItemStringPath: "pathItemStringPath",
            localStringPath: "localStringPath",
            withOptions: options
        ) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call pathitems_listAllWithValues failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AutoRestUrlTest
import AzureCore
import XCTest

// swiftlint:disable function_body_length
// swiftlint:disable type_body_length
// swiftlint:disable file_length

class AutoRestUrlPathsTest: XCTestCase {
    var client: AutoRestUrlTestClient!

    override func setUpWithError() throws {
        client = try AutoRestUrlTestClient(
            globalStringPath: "globalStringPath",
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestUrlTestClientOptions()
        )
    }

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_Paths_byteNull_404() throws {
//        let expectation = XCTestExpectation(description: "Call paths.byteNull")
//
//        client.paths.byteNull(bytePath: Data()) { result, httpResponse in
//            switch result {
//            case .success:
//                XCTFail("Call paths.byteNull failed")
//            case .failure:
//                XCTAssertEqual(httpResponse?.statusCode, 404)
//            }
//            expectation.fulfill()
//        }
//
//        wait(for: [expectation], timeout: 10.0)
//    }

    func test_Paths_byteEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.byteEmpty")

        client.paths.byteEmpty { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case .failure:
                XCTFail("Call paths.byteEmpty failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_byteMultiByte_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.byteMultiByte")

        guard let bytePath = "å•Šé½„ä¸‚ç‹›ç‹œï§±ï¤¬ï§±ï¨Œï¨©".data(using: .utf8)?.base64EncodedData() else {
            return
        }
        client.paths.byteMultiByte(bytePath: bytePath) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case .failure:
                XCTFail("Call paths.byteMultiByte failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_getBooleanTrue_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getBooleanTrue")

        client.paths.getBooleanTrue { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getBooleanTrue failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_getBooleanFalse_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getBooleanFalse")

        client.paths.getBooleanFalse { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getBooleanFalse failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_enumValid_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.enumValid")

        client.paths.enumValid(enumPath: .greenColor) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.enumValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_dateValid_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.dateValid")

        client.paths.dateValid { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.dateValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_dateTimeValid_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.dateTimeValid succeed")

        client.paths.dateTimeValid { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.dateTimeValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_getIntOneMillion_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getIntOneMillion succeed")

        client.paths.getIntOneMillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getIntOneMillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_getIntNegativeOneMillion_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getIntNegativeOneMillion")

        client.paths.getIntNegativeOneMillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getIntNegativeOneMillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_getTenBillion_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getTenBillion")

        client.paths.getTenBillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getTenBillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_getNegativeTenBillion_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.getNegativeTenBillion")

        client.paths.getNegativeTenBillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getNegativeTenBillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_doubleDecimalPositive_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.doubleDecimalPositive")

        client.paths.doubleDecimalPositive { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.doubleDecimalPositive failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_doubleDecimalNegative_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.doubleDecimalNegative")

        client.paths.doubleDecimalNegative { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.doubleDecimalNegative failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_floatScientificPositive_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.floatScientificPositive")

        client.paths.floatScientificPositive { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.floatScientificPositive failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_floatScientificNegative_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.floatScientificNegative")

        client.paths.floatScientificNegative { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.floatScientificNegative failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_stringEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.stringEmpty")

        client.paths.stringEmpty { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.stringEmpty failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_stringUrlEncoded_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.stringUrlEncoded")

        client.paths.stringUrlEncoded { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.stringUrlEncoded failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_stringUnicode_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.stringUnicode")

        client.paths.stringUnicode { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.stringUnicode failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_arrayStringCsvValid_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.arrayStringCsvValid")

        client.paths
            .arrayCsvInPath(arrayPath: ["ArrayPath1", "begin!*'();:@ &=+$,/?#[]end", "", ""]) { result, httpResponse in
                switch result {
                case .success:
                    XCTAssertEqual(httpResponse?.statusCode, 200)
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTFail("Call paths.arrayStringCsvValid failed. error=\(details)")
                }
                expectation.fulfill()
            }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_base64Url_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.base64Url")

        client.paths.base64Url(base64UrlPath: "lorem") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.base64Url failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_stringUrlNonEncoded_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.stringUrlNonEncoded")

        client.paths.stringUrlNonEncoded { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getTenBillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Paths_unixTimeUrl_200() throws {
        let expectation = XCTestExpectation(description: "Call paths.unixTimeUrl")

        guard let date = ISO8601DateFormatter().date(from: "2016-04-13T00:00:00Z") else {
            XCTFail("Input is not a date")
            return
        }

        client.paths.unixTimeUrl(unixTimeUrlPath: UnixTime(date)!) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.unixTimeUrl failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AutoRestUrlTest
import AzureCore
import XCTest

// swiftlint:disable function_body_length
// swiftlint:disable type_body_length
// swiftlint:disable file_length

class AutoRestUrlQuriesTest: XCTestCase {
    var client: AutoRestUrlTestClient!

    override func setUpWithError() throws {
        client = try AutoRestUrlTestClient(
            globalStringPath: "globalStringPath",
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestUrlTestClientOptions()
        )
    }

    func test_Queries_byteNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.byteNull")

        client.queries.byteNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case .failure:
                XCTFail("Call queries.byteNull failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_byteEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.byteEmpty")

        client.queries.byteEmpty { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case .failure:
                XCTFail("Call queries.byteEmpty failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_byteMultiByte_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.byteMultiByte")

        guard let byteQuery = "å•Šé½„ä¸‚ç‹›ç‹œï§±ï¤¬ï§±ï¨Œï¨©".data(using: .utf8)?.base64EncodedData() else {
            return
        }
        let options = ByteMultiByteOptions(byteQuery: byteQuery)
        client.queries.byteMultiByte(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case .failure:
                XCTFail("Call queries.byteMultiByte failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getBooleanNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getBooleanNull")

        client.queries.getBooleanNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case .failure:
                XCTFail("Call queries.byteMultiByte failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getBooleanTrue_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getBooleanTrue")

        client.queries.getBooleanTrue { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getBooleanTrue failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getBooleanFalse_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getBooleanFalse")

        client.queries.getBooleanFalse { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getBooleanFalse failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_enumValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.enumValid")

        let options = EnumValidOptions(enumQuery: .greenColor)
        client.queries.enumValid(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.enumValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_dateValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.dateValid")

        client.queries.dateValid { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.dateValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_dateTimeValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.dateTimeValid")

        client.queries.dateTimeValid { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.dateTimeValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getIntOneMillion_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getIntOneMillion")

        client.queries.getIntOneMillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getIntOneMillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getIntNegativeOneMillion_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getIntNegativeOneMillion")

        client.queries.getIntNegativeOneMillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call paths.getTenBillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getTenBillion_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getTenBillion")

        client.queries.getTenBillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getTenBillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getNegativeTenBillion_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getNegativeTenBillion")

        client.queries.getNegativeTenBillion { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getNegativeTenBillion failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_doubleDecimalPositive_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.doubleDecimalPositive")

        client.queries.doubleDecimalPositive { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.doubleDecimalPositive failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_doubleDecimalNegative_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.doubleDecimalNegative")

        client.queries.doubleDecimalNegative { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.doubleDecimalNegative failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_floatScientificNegative_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.floatScientificNegative")

        client.queries.floatScientificNegative { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.floatScientificNegative failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_enumNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.enumNull")

        client.queries.enumNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.enumNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_dateNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.dateNull")

        client.queries.dateNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.dateNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_dateTimeNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.dateTimeNull")

        client.queries.dateTimeNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.dateTimeNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getIntNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getIntNull")

        client.queries.getIntNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getIntNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_getLongNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.getLongNull")

        client.queries.getLongNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.getLongNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_stringEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.stringEmpty")

        client.queries.stringEmpty { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.stringEmpty failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_stringNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.stringNull")

        client.queries.stringNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.stringNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_floatNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.floatNull")

        client.queries.floatNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.floatNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_doubleNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.doubleNull")

        client.queries.doubleNull { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call  queries.doubleNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringCsvValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringCsvValid")

        let options = ArrayStringCsvValidOptions(
            arrayQuery: ["ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""]
        )

        client.queries.arrayStringCsvValid(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringCsvValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringPipesValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringPipesValid")

        let options = ArrayStringPipesValidOptions(
            arrayQuery: ["ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""]
        )

        client.queries.arrayStringPipesValid(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringPipesValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringSsvValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringSsvValid")

        let options = ArrayStringSsvValidOptions(
            arrayQuery: ["ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""]
        )

        client.queries.arrayStringSsvValid(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringSsvValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringTsvValid_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringTsvValid")

        let options = ArrayStringTsvValidOptions(
            arrayQuery: ["ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""]
        )

        client.queries.arrayStringTsvValid(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringTsvValid failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringNoCollectionFormatEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringNoCollectionFormatEmpty")

        let options = ArrayStringNoCollectionFormatEmptyOptions(
            arrayQuery: ["hello", "nihao", "bonjour"]
        )

        client.queries.arrayStringNoCollectionFormatEmpty(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringNoCollectionFormatEmpty failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringCsvEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringCsvEmpty")

        let options = ArrayStringCsvEmptyOptions(
            arrayQuery: []
        )

        client.queries.arrayStringCsvEmpty(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringCsvEmpty failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_arrayStringCsvNull_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.arrayStringCsvNull")

        let options = ArrayStringCsvNullOptions(
            arrayQuery: nil
        )

        client.queries.arrayStringCsvNull(withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.arrayStringCsvNull failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_stringUrlEncoded_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.stringUrlEncoded")

        client.queries.stringUrlEncoded { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.stringUrlEncoded failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_stringUnicoded_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.stringUnicode")

        client.queries.stringUnicode { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.stringUnicode failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_Queries_floatScientificPositive_200() throws {
        let expectation = XCTestExpectation(description: "Call queries.floatScientificPositive")

        client.queries.floatScientificPositive { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call queries.floatScientificPositive failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AutoRestValidationTest
import AzureCore
import XCTest

// swiftlint:disable force_try
class AutoRestValidationTest: XCTestCase {
    private func getClient(
        apiVersion: AutoRestValidationTestClientOptions
            .ApiVersion? = nil
    ) -> AutoRestValidationTestClient {
        let options = AutoRestValidationTestClientOptions(apiVersion: apiVersion ?? .custom("12-34-5678"))
        return try! AutoRestValidationTestClient(
            subscriptionId: "abc123", url: URL(string: "http://localhost:3000")!,
            authPolicy: AnonymousAccessPolicy(),
            withOptions: options
        )
    }

    private func getBody(displayNames: [String]? = nil, capacity: Int32? = nil) -> Product {
        return Product(
            displayNames: displayNames,
            capacity: capacity,
            image: nil,
            child: ChildProduct(),
            constChild: ConstantProduct()
        )
    }

    func test_get_withConstantInPath() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest.getWithConstantInPath { result, httpResponse in
            switch result {
            case .success:
                break
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_post_withConstantInBody() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        let constantBody = getBody()
        client.autoRestValidationTest.post(withConstantInBody: constantBody) { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertNotNil(data)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_minLengthValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest
            .validationOfMethodParameters(resourceGroupName: "1", id: 100) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("resourceGroupName: minLength 3"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_maxLengthValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest
            .validationOfMethodParameters(resourceGroupName: "1234567890A", id: 100) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("resourceGroupName: maxLength 10"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_patternValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest
            .validationOfMethodParameters(resourceGroupName: "!@#$", id: 100) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("resourceGroupName: pattern"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_multipleValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest
            .validationOfMethodParameters(resourceGroupName: "123", id: 105) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("id: multipleOf 10"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_minimumValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest
            .validationOfMethodParameters(resourceGroupName: "123", id: 0) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("id: >= 100"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_maximumValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        client.autoRestValidationTest
            .validationOfMethodParameters(resourceGroupName: "123", id: 2000) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("id: <= 1000"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_minimumExValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        let constantBody = getBody(capacity: 0)
        client.autoRestValidationTest
            .validation(ofBody: constantBody, resourceGroupName: "123", id: 150) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("capacity: > 0"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_maximumExValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        let constantBody = getBody(capacity: 100)
        client.autoRestValidationTest
            .validation(ofBody: constantBody, resourceGroupName: "123", id: 150) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("capacity: < 100"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_maxItemsValidation() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let client = getClient()
        let constantBody = getBody(displayNames: ["item1", "item2", "item3", "item4", "item5", "item6", "item7"])
        client.autoRestValidationTest
            .validation(ofBody: constantBody, resourceGroupName: "123", id: 150) { result, httpResponse in
                switch result {
                case .success:
                    XCTFail("Call \(#function) succeeded. Expected failure.")
                case let .failure(error):
                    let details = errorDetails(for: error, withResponse: httpResponse)
                    XCTAssert(details.contains("displayNames: maxItems 6"), "Error: \(details)")
                }
                expectation.fulfill()
            }
        wait(for: [expectation], timeout: 5.0)
    }

    // FIXME: autorest does not correctly expose the apiVersion pattern in the code model
//    func test_apiVersionValidation() throws {
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//        let client = getClient(apiVersion: .custom("abc"))
//        client.autoRestValidationTest
//            .validationOfMethodParameters(resourceGroupName: "123", id: 150) { result, httpResponse in
//                switch result {
//                case .success:
//                    XCTFail("Call \(#function) succeeded. Expected failure.")
//                case let .failure(error):
//                    let details = errorDetails(for: error, withResponse: httpResponse)
//                    XCTAssert(details.contains("apiVersion: pattern"), "Error: \(details)")
//                }
//                expectation.fulfill()
//            }
//        wait(for: [expectation], timeout: 5.0)
//    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import Foundation

extension Dictionary {
    func difference(from other: Dictionary) -> Dictionary {
        let thisKeys = Set(keys)
        let otherKeys = Set(other.keys)
        let differentKeys = thisKeys.symmetricDifference(otherKeys)
        return filter { differentKeys.contains($0.key) }
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AzureCore
import Foundation

private let allFormatOptions: [ISO8601DateFormatter.Options] = [
    [.withInternetDateTime, .withFractionalSeconds],
    [.withInternetDateTime]
]

struct ErrorDetails {
    let data: String
    let message: String

    func contains(_ value: String) -> Bool {
        return data.contains(value) || message.contains(value)
    }
}

func errorDetails(for error: AzureError, withResponse response: HTTPResponse?) -> ErrorDetails {
    var details: ErrorDetails
    if let data = response?.data {
        details = ErrorDetails(data: String(data: data, encoding: .utf8)!, message: error.message)
    } else {
        details = ErrorDetails(data: "", message: error.message)
    }
    return details
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AzureCore
import XCTest
import XmsErrorResponseExtensions

class XmsErrorResponseExtensionsTest: XCTestCase {
    var client: XmsErrorResponseExtensionsClient!

    override func setUpWithError() throws {
        guard let baseUrl = URL(string: "http://localhost:3000") else {
            fatalError("Unable to form base URL")
        }

        client = try XmsErrorResponseExtensionsClient(
            url: baseUrl,
            authPolicy: AnonymousAccessPolicy(),
            withOptions: XmsErrorResponseExtensionsClientOptions()
        )
    }

    func test_XmsErrorResponseExtensions_getPetById200() throws {
        let expectation = XCTestExpectation(description: "Call getPetById with tommy")

        client.petOperation.getPetById(petId: "tommy") { result, httpResponse in
            switch result {
            case let .success(data):
                if let pet = data {
                    XCTAssertEqual(httpResponse?.statusCode, 200)
                    XCTAssertEqual(pet.name, "Tommy Tomson")
                } else {
                    XCTFail("Call getPetById with tommy failed")
                }
            case let .failure(error):
                print("test failed. error=\(error.message)")
                XCTFail("Call getPetById with tommy failed")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_getPetById202() throws {
        let expectation = XCTestExpectation(description: "Call getPetById with django")

        client.petOperation.getPetById(petId: "django") { result, httpResponse in
            switch result {
            case let .success(data):
                if data != nil {
                    XCTFail("Call getPetById with django failed")
                } else {
                    XCTAssertEqual(httpResponse?.statusCode, 202)
                }
            case let .failure(error):
                print("test failed. error=\(error.message)")
                XCTFail("Call getPetById with django failed")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_getPetById404_1() throws {
        let expectation = XCTestExpectation(description: "Call getPetById with coyoteUgly")

        client.petOperation.getPetById(petId: "coyoteUgly") { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getPetById with coyoteUgly failed")

            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 404)
                if case let .service(_, innerError) = error,
                    let notFoundErrorBase = innerError as? NotFoundErrorBase {
                    XCTAssertEqual(notFoundErrorBase.reason, "the type of animal requested is not available")
                    XCTAssertEqual(notFoundErrorBase.whatNotFound, "AnimalNotFound")
                } else {
                    XCTFail("Call getPetById with coyoteUgly failed")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_getPetById404_2() throws {
        let expectation = XCTestExpectation(description: "Call getPetById with weirdAlYankovic")

        client.petOperation.getPetById(petId: "weirdAlYankovic") { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getPetById with weirdAlYankovic failed")

            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 404)
                if case let .service(_, innerError) = error,
                    let notFoundErrorBase = innerError as? NotFoundErrorBase {
                    XCTAssertEqual(notFoundErrorBase.reason, "link to pet not found")
                    XCTAssertEqual(notFoundErrorBase.whatNotFound, "InvalidResourceLink")
                } else {
                    XCTFail("Call getPetById with weirdAlYankovic failed")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_getPetById501() throws {
        let expectation = XCTestExpectation(description: "Call getPetById with alien123")

        client.petOperation.getPetById(petId: "alien123") { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getPetById with alien123 failed")

            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 501)
                if case let .service(_, innerError) = error,
                    let errorNo = innerError as? Int32 {
                    XCTAssertEqual(errorNo, 123)
                } else {
                    XCTFail("Call getPetById with alien123 failed")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_getPetById400() throws {
        let expectation = XCTestExpectation(description: "Call getPetById with ringo")

        client.petOperation.getPetById(petId: "ringo") { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getPetById with ringo failed")

            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 400)
                if case let .service(_, innerError) = error,
                    let errorString = innerError as? String {
                    XCTAssert(errorString.contains("ringo is missing"))
                } else {
                    XCTFail("Call getPetById with ringo failed")
                }
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_doSomething200() throws {
        let expectation = XCTestExpectation(description: "Call doSomething with stay")

        client.petOperation.doSomething(whatAction: "stay") { result, httpResponse in
            switch result {
            case let .success(petAction):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertNil(petAction.actionResponse)
            case .failure:
                XCTFail("Call doSomething with stay failed")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_doSomething500() throws {
        let expectation = XCTestExpectation(description: "Call doSomething with jump")

        client.petOperation.doSomething(whatAction: "jump") { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call doSomething with jump failed")

            case let .failure(error):
                if case let .service(_, innerError) = error,
                    let patActionError = innerError as? PetActionError {
                    XCTAssertEqual(httpResponse?.statusCode, 500)
                    XCTAssertEqual(patActionError.errorType, "PetSadError")
                    XCTAssertEqual(patActionError.errorMessage, "casper aint happy")
                } else {
                    XCTFail("Call doSomething with jump failed")
                }
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_XmsErrorResponseExtensions_doSomething404() throws {
        let expectation = XCTestExpectation(description: "Call doSomething with fetch")

        client.petOperation.doSomething(whatAction: "fetch") { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call doSomething with fetch failed")

            case let .failure(error):
                if case let .service(_, innerError) = error,
                    let patActionError = innerError as? PetActionError {
                    XCTAssertEqual(httpResponse?.statusCode, 404)
                    XCTAssertEqual(patActionError.errorType, "PetHungryOrThirstyError")
                    XCTAssertEqual(patActionError.errorMessage, "scooby is low")
                } else {
                    XCTFail("Call doSomething with fetch failed")
                }
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import AutoRestReport
import AzureCore
import Foundation
import XCTest

class ZZZAutoRestReportTest: XCTestCase {
    var client: AutoRestReportClient!

    // The 4 mobile test swerver swaggers are:
    // 1. custom-baseUrl.json
    // 2. xms-error-response.json
    // 3. body-integer.json
    // 4. url.json
    // The following strings are the prefix of the mobile tests from AutoRest TestServer
    let mobileTestsPrefix = [
        // custom-baseUrl.json, custom-baseUrl-more-options.json
        "CustomBase",
        // xms-error-response.json
        "expected", "animalNotFoundError", "linkNotFoundError", "stringError", "intError",
        // body-integer.json
        "putInteger", "putLong", "putUnixTime", "getInteger", "getLong", "getUnixTime", "getInvalidUnixTime",
        "getNullUnixTime",
        // url.json , url-multi-collectionFormat.json
        "UrlPathItem", "UrlQueries", "UrlPaths"
    ]

    let workingTestsPrefix = [
        // body-date.json
        "getDate", "putDate",
        // body-date-time.json
        "getDateTime", "putDateTime",
        // body-date-time-rfc1123.json
        "putDateTimeRfc1123", "getDateTimeRfc1123",
        // body-string.json
        "putString", "getString",
        // body-byte.json
        "putByte", "getByte",
        // body-array.json
        "putArray", "getArray",
        // body-number.json
        "putFloat", "getFloat",
        "putDouble", "getDouble",
        "putDemical", "getDemical",
        // body-integer.json
        "putInteger", "getInteger",
        "putLong", "getLong"
        // header.json
        // "Header"
    ]

    override func setUpWithError() throws {
        client = try AutoRestReportClient(
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestReportClientOptions()
        )
    }

    // Calculate the nobile test coverage & total test coverage
    // List the mobile tests which passed and failed
    private func printCoverage(for allTests: [String: Int32?], listFailed: Bool = false) {
        let passedTest = allTests.filter { $0.value ?? 0 > 0 }
        let totalCount = allTests.count
        let passedCount = passedTest.count

        guard totalCount > 0 else {
            return
        }

        let coverage: Float = Float(passedCount) / Float(totalCount) * 100

        print("Passed Test=\(passedCount), Total Test=\(totalCount), Coverage=\(String(format: "%.2f", coverage))%")

        if listFailed {
            let failedTest = allTests.filter { $0.value == 0 }

            if failedTest.count > 0 {
                print("Failed tests")
                print("-------------------")
                for test in failedTest { print(test.key) }
            }
        }
    }

    private func printReport(allTests: [String: Int32]) {
        let mobileTests = getMobileTests(with: allTests)
        printCoverage(for: mobileTests)
        printCoverage(for: allTests)
    }

    // Return the list of mobile tests
    private func getMobileTests(with report: [String: Int32?]) -> [String: Int32?] {
        return report.filter {
            for prefix in mobileTestsPrefix {
                if $0.key.hasPrefix(prefix),
                    // test name 'expectedEnum' is from non-string-enum.json, not part of the mobile test
                    $0.key != "expectedEnum" {
                    return true
                }
            }
            return false
        }
    }

    private func getWorkingTests(with report: [String: Int32?]) -> [String: Int32?] {
        return report.filter {
            for prefix in workingTestsPrefix {
                if $0.key.hasPrefix(prefix) {
                    return true
                }
            }
            return false
        }
    }

    func test_ReportFile_getReport() throws {
        let expectation = XCTestExpectation(description: "Call getReport succeed")

        client.autoRestReportService.getReport { result, _ in
            switch result {
            case let .success(allTests):
                XCTAssert(allTests.count > 0)

                let mobileTests = self.getMobileTests(with: allTests)
                print("Mobile Coverage:")
                self.printCoverage(for: mobileTests)

                print("Total Coverage:")
                self.printCoverage(for: allTests)

                // Uncomment below to list the failed test cases in working swagger
//                let workingTests = self.getWorkingTests(with: allTests)
//                print("\n\nWorking Coverage:")
//                // set listFailed to True to print out the name of non passesd tests
//                self.printCoverage(for: workingTests, listFailed: true)
                expectation.fulfill()
            case let .failure(error):
                print("test failed. error=\(error.message)")
                XCTFail("Call getReport failed")
            }
        }

        wait(for: [expectation], timeout: 5.0)
    }

    func test_ReportFile_getOptionalReport() throws {
        let expectation = XCTestExpectation(description: "Call getOptionalReport succeed")

        client.autoRestReportService.getOptionalReport { result, _ in
            switch result {
            case let .success(optionalReport):
                XCTAssert(optionalReport.count > 0)
                print("\n\nOptional Coverage:")
                self.printCoverage(for: optionalReport)
                expectation.fulfill()
            case let .failure(error):
                print("test failed. error=\(error.message)")
                XCTFail("Call getOptionalReport failed")
            }
        }

        wait(for: [expectation], timeout: 5.0)
    }
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import Foundation

/// Error codes thrown during code generation
public enum CodeGenerationError: Error {
    /// A general error has occurred.
    case general(String)
}

/// Errors thrown by `ChannelServer`
public enum ServerError: Error {
    case notReady
    case cantBind
    case timeout
}

/// Errors throw by `ChannelClient`
public enum ClientError: Error {
    case notReady
    case cantBind
    case timeout
    case connectionResetByPeer
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import Foundation

// Should be set to `.warning` normally
let logLevel = LogLevel.warning
let standalone = CommandLine.arguments.first!.contains("DerivedData")

if standalone {
    let yamlFileName = "code-model-v4.yaml"
    guard let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
    else { fatalError("Unable to find Documents directory.") }

    let sourceUrl = documentsUrl.appendingPathComponent(yamlFileName)
    do {
        SharedLogger.set(logger: StdoutLogger(), withLevel: logLevel)
        SharedLogger.info("Mode: STANDALONE")
        try Manager.shared.configure(input: sourceUrl, destination: documentsUrl)
        SharedLogger.info("Autorest Configuration: \(Manager.shared.args.debugDescription)")
        try Manager.shared.run()
    } catch {
        SharedLogger.error("\(error)")
    }
} else {
    // Enable file logging
    SharedLogger.set(logger: FileLogger(withFileName: "autorest-swift-debug.log"), withLevel: logLevel)
    SharedLogger.info("Mode: PLUGIN")
    let plugin = AutorestPlugin()
    plugin.start()
}


// --------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the ""Software""), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// --------------------------------------------------------------------------

import Foundation

/// Common protocol for language code generators.
protocol CodeGenerator {
    // TODO: Promote methods from SwiftGenerator to here for use on something like
    // and ObjectiveC generator.

    var model: CodeModel { get }
}