// --------------------------------------------------------------------------
//
// 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 AutoRestIntegerTest
import AzureCore
import XCTest

class AutoRestIntegerTest: XCTestCase {
    var client: AutoRestIntegerTestClient!

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

    func test_BodyInteger_getNull200() throws {
        let expectation = XCTestExpectation(description: "Call getNull")

        client.intOperation.getNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, nil)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getNull failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getInvalid200() throws {
        let expectation = XCTestExpectation(description: "Call getInvalid")

        client.intOperation.getInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getInvalid failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssert(error.message.contains("Decoding error."))
                if let data = httpResponse?.data,
                    let dataStr = String(data: data, encoding: .utf8) {
                    XCTAssert(dataStr == "123jkl")
                } else {
                    XCTFail("Call getInvalid failed.")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getOverflowInt32_200() throws {
        let expectation = XCTestExpectation(description: "Call getOverflowInt32")

        client.intOperation.getOverflowInt32 { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getOverflowInt32 failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssert(error.message.contains("Decoding error."))
                if let data = httpResponse?.data,
                    let dataStr = String(data: data, encoding: .utf8) {
                    XCTAssert(dataStr == "2147483656")
                } else {
                    XCTFail("Call getOverflowInt32 failed.")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getUnderflowInt32_200() throws {
        let expectation = XCTestExpectation(description: "Call getOverflowInt32")

        client.intOperation.getUnderflowInt32 { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getOverflowInt32 failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssert(error.message.contains("Decoding error."))
                if let data = httpResponse?.data,
                    let dataStr = String(data: data, encoding: .utf8) {
                    XCTAssert(dataStr == "-2147483656")

                } else {
                    XCTFail("Call getOverflowInt32 failed.")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getOverflowInt64_200() throws {
        let expectation = XCTestExpectation(description: "Call getOverflowInt64")

        client.intOperation.getOverflowInt64 { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getOverflowInt64 failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssert(error.message.contains("Decoding error."))
                if let data = httpResponse?.data,
                    let dataStr = String(data: data, encoding: .utf8) {
                    XCTAssert(dataStr == "9223372036854775910")
                    expectation.fulfill()
                } else {
                    XCTFail("Call getOverflowInt64 failed.")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getUnderflowInt64_200() throws {
        let expectation = XCTestExpectation(description: "Call getOverflowInt32")

        client.intOperation.getUnderflowInt64 { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getOverflowInt32 failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssert(error.message.contains("Decoding error."))
                if let data = httpResponse?.data,
                    let dataStr = String(data: data, encoding: .utf8) {
                    XCTAssert(dataStr == "-9223372036854775910")
                } else {
                    XCTFail("Call getOverflowInt32 failed.")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getUnixTime_200() throws {
        let expectation = XCTestExpectation(description: "Call getUnixTime")

        client.intOperation.getUnixTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)

                let expectedDate = Iso8601Date(string: "2016-04-13T00:00:00Z")!
                XCTAssertEqual(expectedDate.value, data.value)
            case .failure:
                XCTFail("Call getUnixTime failed.")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getInvalidUnixTime_200() throws {
        let expectation = XCTestExpectation(description: "Call getInvalidUnixTime")

        client.intOperation.getInvalidUnixTime { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getInvalidUnixTime failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssert(error.message.contains("Decoding error."))
                if let data = httpResponse?.data,
                    let dataStr = String(data: data, encoding: .utf8) {
                    XCTAssert(dataStr == "123jkl")
                } else {
                    XCTFail("Call getInvalidUnixTime failed.")
                }
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_getNullUnixTime_200() throws {
        let expectation = XCTestExpectation(description: "Call getNullUnixTime")

        client.intOperation.getNullUnixTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, nil)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getNullUnixTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_putMax32_200() throws {
        let expectation = XCTestExpectation(description: "Call putMax32")

        client.intOperation.put(max32: Int32.max) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putMax32 failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_putMax64_200() throws {
        let expectation = XCTestExpectation(description: "Call putMax64")

        client.intOperation.put(max64: Int64.max) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putMax64 failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_putMin32_200() throws {
        let expectation = XCTestExpectation(description: "Call putMin32")

        client.intOperation.put(min32: Int32.min) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putMin32 failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_putMin64_200() throws {
        let expectation = XCTestExpectation(description: "Call putMin64")

        client.intOperation.put(min64: Int64.min) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                expectation.fulfill()
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putMax64 failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_BodyInteger_putUnixtime_200() throws {
        let expectation = XCTestExpectation(description: "Call putUnixTime")
        let decoded = UnixTime(timeIntervalSince1970: 1_460_505_600.0)

        client.intOperation.put(unixTimeDate: decoded) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putUnixTime 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 AutoRestDateTest
import AzureCore
import XCTest

class AutoRestDateTest: XCTestCase {
    var client: AutoRestDateTestClient!

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

    func test_getNull200() throws {
        let expectation = XCTestExpectation(description: "Call date.getNull")

        client.dateOperation.getNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertNil(data)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getNull failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalidDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.getInvalidDate")

        client.dateOperation.getInvalidDate { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getInvalid expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getOverflowDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.getOverflowDate")

        client.dateOperation.getOverflowDate { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getOverflowDate expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUnderflowDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.getUnderflowDate")

        client.dateOperation.getUnderflowDate { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getUnderflowDate expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putMaxDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.putMaxDate")
        let dateString = "9999-12-31"
        let date = SimpleDate(string: dateString)!
        client.dateOperation.put(maxDate: 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 date.putMaxDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getMaxDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.getMaxDate")
        let dateString = "9999-12-31"
        let expectedDate = SimpleDate(string: dateString)!
        client.dateOperation.getMaxDate { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate.value)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getMaxDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putMinDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.putMinDate")
        let dateString = "0001-01-01"
        let expectedDate = SimpleDate(string: dateString)!
        client.dateOperation.put(minDate: expectedDate) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.putMinDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getMinDate200() throws {
        let expectation = XCTestExpectation(description: "Call date.getMinDate")
        let dateString = "0001-01-01"
        let date = SimpleDate(string: dateString)!
        client.dateOperation.getMinDate { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, date.value)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getMinDate 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 AutoRestRfC1123DateTimeTest
import AzureCore
import XCTest

class AutoRestRfC1123DateTimeTest: XCTestCase {
    var client: AutoRestRfC1123DateTimeTestClient!

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

    func test_getNull200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.getNull")
        client.datetimerfc1123.getNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertNil(data)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetimerfc1123.getNull failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalidDate200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.getInvalid")
        client.datetimerfc1123.getInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getInvalid expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getOverflow200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.getOverflow")
        client.datetimerfc1123.getOverflow { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetimerfc1123.getOverflow failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUnderflow200() throws {
        let expectation = XCTestExpectation(description: "Call date.getUnderflow")
        client.datetimerfc1123.getUnderflow { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getUnderflowDate expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putMaxDate200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.putMaxDate")
        let date = Rfc1123Date(string: "Fri, 31 Dec 9999 23:59:59 GMT")!
        client.datetimerfc1123.put(utcMaxDateTime: 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 date.putMaxDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUtcUppercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.getUtcUppercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = Rfc1123Date(string: "Fri, 31 Dec 9999 23:59:59 GMT")!

        client.datetimerfc1123.getUtcUppercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetimerfc1123.getUtcUppercaseMaxDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putUtcMinDate200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.putUtcMinDate")
        let date = Rfc1123Date(string: "Mon, 01 Jan 0001 00:00:00 GMT")!
        client.datetimerfc1123.put(utcMinDateTime: 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 datetimerfc1123.putUtcMinDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUtcMinDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.getUtcMinDateTime")
        let expectedDate = Rfc1123Date(string: "Mon, 01 Jan 0001 00:00:00 GMT")!
        client.datetimerfc1123.getUtcMinDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetimerfc1123.getUtcMinDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUtcLowercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetimerfc1123.getUtcLowercaseMaxDateTime")
        let expectedDate = Rfc1123Date(string: "fri, 31 dec 9999 23:59:59 gmt".capitalized)!
        client.datetimerfc1123.getUtcLowercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetimerfc1123.getUtcLowercaseMaxDateTime 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 AutoRestDateTimeTest
import AzureCore
import XCTest

class AutoRestDateTimeTest: XCTestCase {
    var client: AutoRestDateTimeTestClient!

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

    func test_getNull200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getNull")
        client.datetime.getNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertNil(data)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetime.getNull failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalidDate200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getInvalid")
        client.datetime.getInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getInvalid expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getOverflow200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getOverflow")
        client.datetime.getOverflow { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetime.getOverflow failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUnderflow200() throws {
        let expectation = XCTestExpectation(description: "Call date.getUnderflow")
        client.datetime.getUnderflow { result, httpResponse in
            switch result {
            case .success:
                XCTFail("date.getUnderflowDate expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putMaxDate200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.putMaxDate")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let date = iso8601DateFormatter.date(from: "9999-12-31T23:59:59.999Z")!
        let isoDate = Iso8601Date(date)!
        client.datetime.put(utcMaxDateTime: isoDate) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.putMaxDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUtcUppercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getUtcUppercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = iso8601DateFormatter.date(from: "9999-12-31T23:59:59.999Z")!
        client.datetime.getUtcUppercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getUtcUppercaseMaxDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putMinDate200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.putMinDate")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let date = iso8601DateFormatter.date(from: "0001-01-01T00:00:00.000Z")!
        let isoDate = Iso8601Date(date)!
        client.datetime.put(utcMinDateTime: isoDate) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call datetime.putMinDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUtcMinDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getUtcMinDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime]
        let expectedDate = iso8601DateFormatter.date(from: "0001-01-01T00:00:00Z")!
        client.datetime.getUtcMinDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getUtcMinDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalPositiveOffsetUppercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalPositiveOffsetUppercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = iso8601DateFormatter.date(from: "9999-12-31T23:59:59.999+14:00")!
        client.datetime.getLocalPositiveOffsetUppercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getLocalPositiveOffsetUppercaseMaxDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalPositiveOffsetMinDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalPositiveOffsetMinDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime]
        let expectedDate = iso8601DateFormatter.date(from: "0001-01-01T00:00:00+14:00")!
        client.datetime.getLocalPositiveOffsetMinDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getLocalPositiveOffsetMinDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalNegativeOffsetUppercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalNegativeOffsetUppercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = iso8601DateFormatter.date(from: "9999-12-31T23:59:59.999-14:00")!
        client.datetime.getLocalNegativeOffsetUppercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getLocalNegativeOffsetUppercaseMaxDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalNegativeOffsetLowercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalNegativeOffsetLowercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = iso8601DateFormatter.date(from: "9999-12-31t23:59:59.999-14:00".capitalized)!
        client.datetime.getLocalNegativeOffsetLowercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getDateTimeRfc1123MaxUtcLowercase failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalPositiveOffsetLowercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalPositiveOffsetLowercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = iso8601DateFormatter.date(from: "9999-12-31t23:59:59.999+14:00".capitalized)!
        client.datetime.getLocalPositiveOffsetLowercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getLocalPositiveOffsetLowercaseMaxDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalNoOffsetMinDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalNoOffsetMinDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime]
        let expectedDate = iso8601DateFormatter.date(from: "0001-01-01T00:00:00Z")!
        client.datetime.getLocalNoOffsetMinDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getLocalNoOffsetMinDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getUtcLowercaseMaxDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getUtcLowercaseMaxDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
        let expectedDate = iso8601DateFormatter.date(from: "9999-12-31t23:59:59.999z".capitalized)!
        client.datetime.getUtcLowercaseMaxDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getUtcLowercaseMaxDateTime failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getLocalNegativeOffsetMinDateTime200() throws {
        let expectation = XCTestExpectation(description: "Call datetime.getLocalNegativeOffsetMinDateTime")
        let iso8601DateFormatter = ISO8601DateFormatter()
        iso8601DateFormatter.formatOptions = [.withInternetDateTime]
        let expectedDate = iso8601DateFormatter.date(from: "0001-01-01T00:00:00-14:00Z")!
        client.datetime.getLocalNegativeOffsetMinDateTime { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.value, expectedDate)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call date.getLocalNegativeOffsetMinDateTime 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 AutoRestDurationTest
import AzureCore
import XCTest

// swiftlint:disable type_body_length file_length
class AutoRestDurationTest: XCTestCase {
    var client: AutoRestDurationTestClient!

    let defaultTimeout = 5.0

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

    func test_getNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.duration.getNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertNil(data)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. Error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getInvalid() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.duration.getInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call \(#function) succeeded but should have failed.")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssert(details.contains("Decoding error"), "Error: \(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getPositiveDuration() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let expected = Iso8601Duration(string: "P3Y6M4DT12H30M5S")!

        client.duration.getPositiveDuration { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, expected)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. Error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putPositiveDuration() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let expected = Iso8601Duration(string: "P123DT22H14M12.011S")!

        client.duration.put(positiveDuration: expected) { result, httpResponse in
            switch result {
            case .success:
                break
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssert(details.contains("Decoding error"), "Error: \(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }
}


// --------------------------------------------------------------------------
//
// 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 PetStoreInc
import XCTest

class AutoRestEnumExtensibleTest: XCTestCase {
    var client: PetStoreIncClient!

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

    func test_getByPetId() throws {
        let testValues = [
            ("tommy", "Monday", "1"),
            ("casper", "Weekend", "2"),
            ("scooby", "Thursday", "2.1")
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")
        expectation.expectedFulfillmentCount = testValues.count
        for item in testValues {
            client.petOperation.getByPetId(petId: item.0) { result, httpResponse in
                switch result {
                case let .success(data):
                    XCTAssertEqual(data.daysOfWeek?.requestString, item.1)
                    XCTAssertEqual(data.intEnum.requestString, item.2)
                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_addPet() throws {
        let pet = Pet(
            name: "Retriever",
            daysOfWeek: .friday,
            intEnum: .three
        )
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.petOperation.add(pet: pet) { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.daysOfWeek?.requestString, "Friday")
                XCTAssertEqual(data.intEnum.requestString, "3")
                XCTAssertEqual(data.name, "Retriever")
            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)
    }
}


// --------------------------------------------------------------------------
//
// 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 AutoRestHeadTest
import AzureCore
import XCTest

class AutoRestHeadTest: XCTestCase {
    var client: AutoRestHeadTestClient!

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

    func test_Head_success200() throws {
        let expectation = XCTestExpectation(description: "Call head200")

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

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

    func test_Head_success204() throws {
        let expectation = XCTestExpectation(description: "Call head204")

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

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

    func test_Head_success404() throws {
        let expectation = XCTestExpectation(description: "Call head404")

        client.httpSuccess.head404 { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 404)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call head404 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 AutoRestNumberTest
import AzureCore
import XCTest

class AutoRestNumberTest: XCTestCase {
    var client: AutoRestNumberTestClient!

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

    func test_getnull200() throws {
        let expectation = XCTestExpectation(description: "Call number.getNull")

        client.number.getNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertNil(data)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getNull failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalidFloat200() throws {
        let expectation = XCTestExpectation(description: "Call number.getInvalidFloat")

        client.number.getInvalidFloat { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getInvalidFloat should failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(error.message.contains("Decoding error."))
                XCTAssertEqual(details.data, "2147483656.090096789909j")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalidDouble200() throws {
        let expectation = XCTestExpectation(description: "Call number.getInvalidDouble")

        client.number.getInvalidDouble { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getInvalidDouble should failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(error.message.contains("Decoding error."))
                XCTAssertEqual(details.data, "9223372036854775910.980089k")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalidDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getInvalidDecimal")

        client.number.getInvalidDecimal { result, httpResponse in
            switch result {
            case .success:
                XCTFail("Call getInvalidDouble should failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(error.message.contains("Decoding error."))
                XCTAssertEqual(details.data, "9223372036854775910.980089k")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putBigDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.putBigDecimal")

        client.number.put(bigDecimal: Decimal(2.5976931e+101)) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putBigDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getBigDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigDecimal")

        client.number.getBigDecimal { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Decimal(2.5976931e+101))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putBigDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    // Need to add support to encode Decimal constant into String before we can enable this test case
    /*
     func test_putBigDecimalPositiveDecimal200() throws {
         let expectation = XCTestExpectation(description: "Call number.putBigDecimalPositiveDecimal")

         client.number.putBigDecimalPositiveDecimal { result, httpResponse in
             switch result {
             case .success:
                 XCTAssertEqual(httpResponse?.statusCode, 200)
             case let .failure(error):
                 let details = errorDetails(for: error, withResponse: httpResponse)
                 XCTFail("Call putBigDecimalPositiveDecimal failed. error=\(details)")
             }
             expectation.fulfill()
         }
         wait(for: [expectation], timeout: 5.0)
     }
     */

    func test_getBigDecimalPositiveDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigDecimalPositiveDecimal")

        client.number.getBigDecimalPositiveDecimal { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Decimal(99_999_999.99))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putBigDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    // Need to add support to encode Decimal constant into String before we can enable this test case
    /*
     func test_putBigDecimalNegativeDecimal200() throws {
         let expectation = XCTestExpectation(description: "Call number.putBigDecimalNegativeDecimal")

         client.number.putBigDecimalNegativeDecimal { result, httpResponse in
             switch result {
             case .success:
                 XCTAssertEqual(httpResponse?.statusCode, 200)
             case let .failure(error):
                 let details = errorDetails(for: error, withResponse: httpResponse)
                 XCTFail("Call putBigDecimal failed. error=\(details)")
             }
             expectation.fulfill()
         }
         wait(for: [expectation], timeout: 5.0)
     }
     */

    func test_getBigDecimalNegativeDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigDecimalPositiveDecimal")

        client.number.getBigDecimalNegativeDecimal { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Decimal(-99_999_999.99))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getBigDecimalPositiveDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putSmallFloat200() throws {
        let expectation = XCTestExpectation(description: "Call number.putSmallFloat")

        client.number.put(smallFloat: Float(3.402823e-20)) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putSmallFloat failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getSmallFloat200() throws {
        let expectation = XCTestExpectation(description: "Call number.getSmallFloat")

        client.number.getSmallFloat { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Double(3.402823e-20))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getSmallFloat failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putSmallDouble200() throws {
        let expectation = XCTestExpectation(description: "Call number.putSsmallDouble")

        client.number.put(smallDouble: Double(2.5976931e-101)) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putSsmallDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getSmallDouble200() throws {
        let expectation = XCTestExpectation(description: "Call number.getSmallDouble")

        client.number.getSmallDouble { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Double(2.5976931e-101))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getSmallDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putSmallDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.putSmallDecimal")

        client.number.put(smallDecimal: Decimal(2.5976931e-101)) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putSmallDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getSmallDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getSmallDecimal")

        client.number.getSmallDecimal { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Decimal(2.5976931e-101))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getSmallDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putBigDouble200() throws {
        let expectation = XCTestExpectation(description: "Call number.putBigDouble")

        client.number.put(bigDouble: Double(2.5976931e+101)) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putBigDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getBigDouble200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigDouble")

        client.number.getBigDouble { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Double(2.5976931e+101))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getBigDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putBigDoublePositiveDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.BigDoublePositiveDecimal")

        client.number.putBigDoublePositiveDecimal { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putBigDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getBigDoublePositiveDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigDoublePositiveDecimal")

        client.number.getBigDoublePositiveDecimal { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Double(99_999_999.99))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getBigDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putDoubleBigNegativeDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.putBigDoubleNegativeDecimal")

        client.number.putBigDoubleNegativeDecimal { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call putBigDoubleNegativeDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getDoubleBigNegativeDecimal200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigDoubleNegativeDecimal")

        client.number.getBigDoubleNegativeDecimal { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Double(-99_999_999.99))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getBigDoubleNegativeDecimal failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_bigFloat200() throws {
        let expectation = XCTestExpectation(description: "Call number.bigFloat")

        client.number.put(bigFloat: Float(3.402823e+20)) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getBigFloat200() throws {
        let expectation = XCTestExpectation(description: "Call number.getBigFloat")

        client.number.getBigFloat { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, Float(3.402823e+20))
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getBigFloat 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 AutoRestPagingTest
import AzureCore
import XCTest

class AutoRestPagingTest: XCTestCase {
    var client: AutoRestPagingTestClient!

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

    func test_listNoItemNamePages200() throws {
        let expectation = XCTestExpectation(description: "Call paging.listNoItemNamePages")

        client.paging.listNoItemNamePages { result, httpResponse in
            switch result {
            case let .success(pagedCollection):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(pagedCollection.underestimatedCount, 1)

                var allProducts: [Product] = []

                pagedCollection.nextItem { result in
                    switch result {
                    case let .success(product):
                        allProducts.append(product)
                    case .failure:
                        XCTFail("\(expectation.description) failed in nextItem")
                    }
                }

                XCTAssertEqual(allProducts.count, 1)
                XCTAssertEqual(allProducts[0].properties?.name, "Product")
                XCTAssertEqual(allProducts[0].properties?.id, 1)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_listNullNextLinkNamePages200() throws {
        let expectation = XCTestExpectation(description: "Call paging.listNullNextLinkNamePages")

        client.paging.listNullNextLinkNamePages { result, httpResponse in
            switch result {
            case let .success(pagedCollection):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(pagedCollection.underestimatedCount, 1)
                var allProducts: [Product] = []

                pagedCollection.nextItem { result in
                    switch result {
                    case let .success(product):
                        allProducts.append(product)
                    case .failure:
                        XCTFail("\(expectation.description) failed in nextItem")
                    }
                }

                XCTAssertEqual(allProducts.count, 1)
                XCTAssertEqual(allProducts[0].properties?.name, "Product")
                XCTAssertEqual(allProducts[0].properties?.id, 1)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_listSinglePages200() throws {
        let expectation = XCTestExpectation(description: "Call paging.listSinglePages")

        client.paging.listSinglePages { result, httpResponse in
            switch result {
            case let .success(pagedCollection):
                XCTAssertEqual(httpResponse?.statusCode, 200)

                var noOfPages = 1
                pagedCollection.forEachPage { _ in
                    noOfPages += 1

                    if pagedCollection.isExhausted {
                        XCTAssertEqual(noOfPages, 1)
                        return false
                    } else {
                        return true
                    }
                }

                if pagedCollection.isExhausted {
                    XCTAssertEqual(noOfPages, 1)
                }
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_listMultiplePages200() throws {
        let expectation = XCTestExpectation(description: "Call paging.listMultiplePages")

        client.paging.listMultiplePages { result, httpResponse in
            switch result {
            case let .success(pagedCollection):
                XCTAssertEqual(httpResponse?.statusCode, 200)

                var noOfPages = 1
                pagedCollection.forEachPage { _ in
                    noOfPages += 1

                    if pagedCollection.isExhausted {
                        XCTAssertEqual(noOfPages, 10)
                        return false
                    } else {
                        return true
                    }
                }
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    // FIXME: Causes excessive calls to testserver
//    func test_listWithQueryParams200() throws {
//        let expectation = XCTestExpectation(description: "Call paging.listWithQueryParams")
//
//        client.paging.listWithQueryParams(requiredQueryParameter: 100) { result, httpResponse in
//            switch result {
//            case let .success(pagedCollection):
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//
//                var noOfPages = 1
//                pagedCollection.forEachPage { _ in
//                    noOfPages += 1
//
//                    if pagedCollection.isExhausted {
//                        XCTAssertEqual(noOfPages, 2)
//                        return false
//                    } else {
//                        return true
//                    }
//                }
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                XCTFail("\(expectation.description). error=\(details)")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    func test_getMultiplePagesWithOffset200() throws {
        let expectation = XCTestExpectation(description: "Call paging.getMultiplePagesWithOffset")

        client.paging.listMultiplePagesWithOffset(offset: 100) { result, httpResponse in
            switch result {
            case let .success(pagedCollection):
                XCTAssertEqual(httpResponse?.statusCode, 200)

                var noOfPages = 1
                var allProducts: [Product] = []
                pagedCollection.forEachPage { products in
                    noOfPages += 1

                    allProducts.append(contentsOf: products)

                    if pagedCollection.isExhausted {
                        XCTAssertEqual(noOfPages, 10)
                        let product = allProducts[allProducts.count - 1]
                        XCTAssertEqual(product.properties?.id, 110)
                        return false
                    } else {
                        return true
                    }
                }
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_listOdataMultiplePages200() throws {
        let expectation = XCTestExpectation(description: "Call paging.listOdataMultiplePages")

        client.paging.listOdataMultiplePages { result, httpResponse in
            switch result {
            case let .success(pagedCollection):
                XCTAssertEqual(httpResponse?.statusCode, 200)

                var noOfPages = 1
                pagedCollection.forEachPage { _ in
                    noOfPages += 1

                    if pagedCollection.isExhausted {
                        XCTAssertEqual(noOfPages, 10)
                        return false
                    } else {
                        return true
                    }
                }
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). 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 AutoRestParameterizedHostTest
import AzureCore
import XCTest

class AutoRestParameterizedHostTest: XCTestCase {
    var client: AutoRestParameterizedHostTestClient!

    override func setUpWithError() throws {
        guard let endpoint = URL(string: "http://wronghost") else {
            fatalError("Can't creat a base URL")
        }
        client = try AutoRestParameterizedHostTestClient(
            host: "host:3000",
            endpoint: endpoint,
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestParameterizedHostTestClientOptions()
        )
    }

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

        client.paths.getEmpty(accountName: "local") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                print("test failed. error=\(error.message)")
                XCTFail("Call paths.getEmpty failed")
            }
            expectation.fulfill()
        }

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

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_get_emptyFailed() throws {
//        let expectation = XCTestExpectation(description: "Call paths.getEmpty")
//
//        client.paths.getEmpty(accountName: "bad") { result, httpResponse in
//            switch result {
//            case .success:
//                XCTFail("Call paths.getEmptyFailed should failed")
//            case .failure:
//                XCTAssertNil(httpResponse?.statusCode)
//            }
//            expectation.fulfill()
//        }
//
//        wait(for: [expectation], timeout: 120.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 AutoRestRequiredOptionalTest
import AzureCore
import XCTest

class AutoRestRequiredOptionalTest: XCTestCase {
    var client: AutoRestRequiredOptionalTestClient!

    override func setUpWithError() throws {
        client = try AutoRestRequiredOptionalTestClient(
            requiredGlobalPath: "required_path",
            requiredGlobalQuery: "required_query",
            authPolicy: AnonymousAccessPolicy(),
            withOptions: AutoRestRequiredOptionalTestClientOptions()
        )
    }

    func test_implicit_putOptionalQuery200() throws {
        let expectation = XCTestExpectation(description: "Call implicit.putOptionalQuery")

        client.implicit.putOptionalQuery { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_implicit_putOptionalBody200() throws {
        let expectation = XCTestExpectation(description: "Call implicit.putOptionalBody")

        client.implicit.put(optionalBody: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_implicit_getOptionalGlobalQuery200() throws {
        let expectation = XCTestExpectation(description: "Call implicit.getOptionalGlobalQuery")

        client.implicit.getOptionalGlobalQuery { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalIntegerParameter200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalIntegerParameter")

        client.explicit.post(optionalIntegerParameter: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalIntegerHeader200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalIntegerHeader")

        client.explicit.postOptionalIntegerHeader { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalStringParameter200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalStringParameter")

        client.explicit.post(optionalStringParameter: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalStringProperty200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalStringProperty")

        client.explicit.post(optionalStringProperty: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalStringHeader200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalStringHeader")

        client.explicit.postOptionalStringHeader { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalClassParameter200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalClassParameter")

        client.explicit.post(optionalClassParameter: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalClassProperty200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalClassProperty")

        client.explicit.post(optionalClassProperty: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalArrayParameter200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalArrayParameter")

        client.explicit.post(optionalArrayParameter: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalArrayProperty200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalArrayProperty")

        client.explicit.post(optionalArrayProperty: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalArrayHeader200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalArrayHeader")

        client.explicit.postOptionalArrayHeader { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_explicit_postOptionalIntegerProperty200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.postOptionalIntegerProperty")

        client.explicit.post(optionalIntegerProperty: nil) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_implicit_putOptionalHeader200() throws {
        let expectation = XCTestExpectation(description: "Call explicit.putOptionalHeader")

        client.implicit.putOptionalHeader { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description). error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }
}