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

// swiftlint:disable type_body_length file_length
class AutoRestSwaggerBatDictionaryTest: XCTestCase {
    var client: AutoRestSwaggerBatDictionaryClient!
    var testDict = [
        "0": Widget(integer: 1, string: "2"),
        "1": Widget(integer: 3, string: "4"),
        "2": Widget(integer: 5, string: "6")
    ]

    let defaultTimeout = 5.0

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

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

        client.dictionary.getBooleanTfft { result, httpResponse in
            switch result {
            case let .success(data):
                let expected = ["0": true, "1": false, "2": false, "3": true]
                XCTAssertEqual(data, expected)

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

    func test_putBooleanTFFT() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let expected = ["0": true, "1": false, "2": false, "3": true]
        client.dictionary.put(booleanTfft: expected) { result, httpResponse in
            switch result {
            case .success:
                break
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. Error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getBooleanInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid = ["0": true, "1": nil, "2": false]

        client.dictionary.getBooleanInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getBooleanInvalidString() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getBooleanInvalidString { result, _ in
            switch result {
            case .success:
                XCTFail("Call \(#function) succeeded but should have failed.")
            case let .failure(error):
                let details = error.errorDescription!
                XCTAssert(details.contains("Decoding error."))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getIntegerValid() throws {
        let expected: [String: Int32] = ["0": 1, "1": -1, "2": 3, "3": 300]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getIntegerValid { 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_putIntegerValid() throws {
        let expected: [String: Int32] = ["0": 1, "1": -1, "2": 3, "3": 300]
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.put(integerValid: expected) { result, httpResponse in
            switch result {
            case .success:
                break
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. Error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getIntegerInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: Int32?] = ["0": 1, "1": nil, "2": 0]

        client.dictionary.getIntInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getIntegerInvalidString() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getIntInvalidString { result, _ in
            switch result {
            case .success:
                XCTFail("Call \(#function) succeeded but should have failed.")
            case let .failure(error):
                let details = error.errorDescription!
                XCTAssert(details.contains("Decoding error."))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getLongValid() throws {
        let expected: [String: Int64] = ["0": 1, "1": -1, "2": 3, "3": 300]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getLongValid { 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_putLongValid() throws {
        let expected: [String: Int64] = ["0": 1, "1": -1, "2": 3, "3": 300]
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.put(longValid: expected) { result, httpResponse in
            switch result {
            case .success:
                break
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. Error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getLongInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: Int64?] = ["0": 1, "1": nil, "2": 0]

        client.dictionary.getLongInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getLongInvalidString() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getLongInvalidString { result, _ in
            switch result {
            case .success:
                XCTFail("Call \(#function) succeeded but should have failed.")
            case let .failure(error):
                let details = error.errorDescription!
                XCTAssert(details.contains("Decoding error."))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getFloatValid() throws {
        let expected: [String: Float?] = ["0": 0, "1": -0.01, "2": -1.2e20]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getFloatValid { 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)
    }

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_putFloatValid() throws {
//        let expected: [String: Float?] = ["0": 0, "1": -0.01, "2": -1.2e20]
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//
//        // FIXME: Float serialization not accepted by server
//        client.dictionary.put(floatValid: expected) { result, httpResponse in
//            switch result {
//            case .success:
//                break
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                XCTFail("Call \(#function) failed. Error=\(details)")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: defaultTimeout)
//    }

    func test_getFloatInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: Float?] = ["0": 0.0, "1": nil, "2": -1.2e20]

        client.dictionary.getFloatInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getFloatInvalidString() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getFloatInvalidString { result, _ in
            switch result {
            case .success:
                XCTFail("Call \(#function) succeeded but should have failed.")
            case let .failure(error):
                let details = error.errorDescription!
                XCTAssert(details.contains("Decoding error."))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDoubleValid() throws {
        let expected: [String: Double] = ["0": 0, "1": -0.01, "2": -1.2e20]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDoubleValid { 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_putDoubleValid() throws {
        let expected: [String: Double] = ["0": 0, "1": -0.01, "2": -1.2e20]
        let expectation = XCTestExpectation(description: "Call \(#function)")

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

    func test_getDoubleInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: Double?] = ["0": 0.0, "1": nil, "2": -1.2e20]

        client.dictionary.getDoubleInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getDoubleInvalidString() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getDoubleInvalidString { result, _ in
            switch result {
            case .success:
                XCTFail("Call \(#function) succeeded but should have failed.")
            case let .failure(error):
                let details = error.errorDescription!
                XCTAssert(details.contains("Decoding error."))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getStringValid() throws {
        let expected = ["0": "foo1", "1": "foo2", "2": "foo3"]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getStringValid { 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_putStringValid() throws {
        let expected = ["0": "foo1", "1": "foo2", "2": "foo3"]
        let expectation = XCTestExpectation(description: "Call \(#function)")

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

    func test_getStringNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let stringNullDict = ["0": "foo", "1": nil, "2": "foo2"]

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

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_getStringInvalid() throws {
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//        let stringInvalidDict = ["0": "foo", "1": "123", "2": "foo2"]
//
//        // FIXME: Some crazy workaround behavior where autorest should deserialize non-string values
//        // as strings.
//        client.dictionary.getStringWithInvalid { result, httpResponse in
//            switch result {
//            case let .success(data):
//                XCTAssertEqual(data, stringInvalidDict)
//            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_getDateValid() throws {
        let expected: [String: SimpleDate] = [
            "0": SimpleDate(string: "2000-12-01")!,
            "1": SimpleDate(string: "1980-01-02")!,
            "2": SimpleDate(string: "1492-10-12")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDateValid { 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_putDateValid() throws {
        let expected: [String: SimpleDate] = [
            "0": SimpleDate(string: "2000-12-01")!,
            "1": SimpleDate(string: "1980-01-02")!,
            "2": SimpleDate(string: "1492-10-12")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

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

    func test_getDateInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: SimpleDate?] = [
            "0": SimpleDate(string: "2012-01-01")!,
            "1": nil,
            "2": SimpleDate(string: "1776-07-04")!
        ]

        client.dictionary.getDateInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getDateInvalidChars() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDateInvalidChars { 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"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateTimeValid() throws {
        let expected: [String: Iso8601Date] = [
            "0": Iso8601Date(string: "2000-12-01T00:00:01Z")!,
            "1": Iso8601Date(string: "1980-01-02T00:11:35+01:00")!,
            "2": Iso8601Date(string: "1492-10-12T10:15:01-08:00")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDateTimeValid { 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_putDateTimeValid() throws {
        let expected: [String: Iso8601Date] = [
            "0": Iso8601Date(string: "2000-12-01T00:00:01Z")!,
            "1": Iso8601Date(string: "1980-01-02T00:11:35+01:00")!,
            "2": Iso8601Date(string: "1492-10-12T10:15:01-08:00")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.put(dateTimeValid: expected) { result, httpResponse in
            switch result {
            case .success:
                break
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. Error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateTimeInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: Iso8601Date?] = [
            "0": Iso8601Date(string: "2000-12-01T00:00:01Z")!,
            "1": nil
        ]

        client.dictionary.getDateTimeInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getDateTimeInvalidChars() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDateTimeInvalidChars { 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"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateTimeRfc1123Valid() throws {
        let expected: [String: Rfc1123Date] = [
            "0": Rfc1123Date(Iso8601Date(string: "2000-12-01T00:00:01Z")!.value)!,
            "1": Rfc1123Date(Iso8601Date(string: "1980-01-02T00:11:35Z")!.value)!,
            "2": Rfc1123Date(Iso8601Date(string: "1492-10-12T10:15:01Z")!.value)!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDateTimeRfc1123Valid { 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)
    }

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_putDateTimeRfc1123Valid() throws {
//        let expected: [String: Rfc1123Date] = [
//            "0": Rfc1123Date(Iso8601Date(string: "2000-12-01T00:00:01Z")!.value)!,
//            "1": Rfc1123Date(Iso8601Date(string: "1980-01-02T00:11:35Z")!.value)!,
//            "2": Rfc1123Date(Iso8601Date(string: "1492-10-12T10:15:01Z")!.value)!
//        ]
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//
//        // FIXME: Server not accepting the datetime serialization
//        client.dictionary.put(dateTimeRfc1123Valid: expected) { result, httpResponse in
//            switch result {
//            case .success:
//                break
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                XCTFail("Call \(#function) failed. Error=\(details)")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: defaultTimeout)
//    }

    func test_getDurationValid() throws {
        let expected: [String: Iso8601Duration] = [
            "0": Iso8601Duration(string: "P123DT22H14M12.011S")!,
            "1": Iso8601Duration(string: "P5DT1H")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDurationValid { 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_putDurationValid() throws {
        let expected: [String: Iso8601Duration] = [
            "0": Iso8601Duration(string: "P123DT22H14M12.011S")!,
            "1": Iso8601Duration(string: "P5DT1H")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

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

    func test_getBytesValid() throws {
        let expected: [String: Data] = [
            "0": Data([0x0FF, 0x0FF, 0x0FF, 0x0FA]),
            "1": Data([0x01, 0x02, 0x03]),
            "2": Data([0x025, 0x029, 0x043])
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getByteValid { 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_putBytesValid() throws {
        let expected: [String: Data] = [
            "0": Data([0x0FF, 0x0FF, 0x0FF, 0x0FA]),
            "1": Data([0x01, 0x02, 0x03]),
            "2": Data([0x025, 0x029, 0x043])
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

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

    func test_getByteInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let invalid: [String: Data?] = [
            "0": Data([0x0AB, 0x0AC, 0x0AD]),
            "1": nil
        ]

        client.dictionary.getByteInvalidNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, invalid)
            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_getBase64Url() throws {
        let expected: [String: String] = [
            "0": "a string that gets encoded with base64url".base64EncodedString(trimmingEquals: true),
            "1": "test string".base64EncodedString(trimmingEquals: true),
            "2": "Lorem ipsum".base64EncodedString(trimmingEquals: true)
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getBase64Url { 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_getEmpty() throws {
        let expected = [String: Int32]()
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getEmpty { 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_putEmpty() throws {
        let expected = [String: Int32]()
        let expectation = XCTestExpectation(description: "Call \(#function)")

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

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_getNull() throws {
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//
//        // FIXME: Not valid JSON. Domain Code=3840 No Value
//        client.dictionary.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.dictionary.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"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getNullKey() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getNullKey { 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"), "\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getNullValue() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getNullValue { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, ["key1": nil])
            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_getEmptyStringKey() throws {
        let expected = ["": "val1"]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getEmptyStringKey { 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_getComplexNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getComplexNull { 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_getComplexEmpty() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getComplexEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.requestString, [String: Widget]().requestString)
            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_complexValid() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.put(complexValid: testDict) { result, httpResponse in
            switch result {
            case .success:

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

    func test_getArrayValid() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let listDict = [
            "0": ["1", "2", "3"],
            "1": ["4", "5", "6"],
            "2": ["7", "8", "9"]
        ]

        client.dictionary.getArrayValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, listDict)
            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_putArrayValid() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let listDict = [
            "0": ["1", "2", "3"],
            "1": ["4", "5", "6"],
            "2": ["7", "8", "9"]
        ]

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

    func test_getDictionaryValid() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let dictDict: [String: [String: String?]?] = [
            "0": ["1": "one", "2": "two", "3": "three"],
            "1": ["4": "four", "5": "five", "6": "six"],
            "2": ["7": "seven", "8": "eight", "9": "nine"]
        ]

        client.dictionary.getDictionaryValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, dictDict)
            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_putDictionaryValid() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let dictDict: [String: [String: String?]?] = [
            "0": ["1": "one", "2": "two", "3": "three"],
            "1": ["4": "four", "5": "five", "6": "six"],
            "2": ["7": "seven", "8": "eight", "9": "nine"]
        ]

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

    func test_getComplexItemNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let testDictNull = ["0": testDict["0"], "1": nil, "2": testDict["2"]]

        client.dictionary.getComplexItemNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.requestString, testDictNull.requestString)
            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_getComplexItemEmpty() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let testDictEmpty = ["0": testDict["0"], "1": Widget(), "2": testDict["2"]]
        client.dictionary.getComplexItemEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.requestString, testDictEmpty.requestString)
            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_getArrayNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getArrayNull { 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_getArrayEmpty() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        client.dictionary.getArrayEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [String: [String]]())
            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_getArrayItemNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let listDict = [
            "0": ["1", "2", "3"],
            "1": nil,
            "2": ["7", "8", "9"]
        ]

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

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_getArrayItemEmpty() throws {
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//        let listDict = [
//            "0": ["1", "2", "3"],
//            "1": nil,
//            "2": ["7", "8", "9"]
//        ]
//        client.dictionary.getArrayItemEmpty { result, httpResponse in
//            switch result {
//            case let .success(data):
//                XCTAssertEqual(data.requestString, listDict.requestString)
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                XCTFail("Call \(#function) failed. Error=\(details)")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: defaultTimeout)
//    }

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_getDictionaryNull() throws {
//        let expectation = XCTestExpectation(description: "Call \(#function)")
//
//        client.dictionary.getDictionaryNull { 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_getDictionaryEmpty() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.dictionary.getDictionaryEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [String: [String: String]]())
            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_dictionaryItemNull() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let dictDictNull: [String: [String: String?]?] = [
            "0": ["1": "one", "2": "two", "3": "three"],
            "1": nil,
            "2": ["7": "seven", "8": "eight", "9": "nine"]
        ]

        client.dictionary.getDictionaryItemNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.requestString, dictDictNull.requestString)
            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_dictionaryItemEmpty() throws {
        let expectation = XCTestExpectation(description: "Call \(#function)")
        let dictDictEmpty: [String: [String: String?]?] = [
            "0": ["1": "one", "2": "two", "3": "three"],
            "1": [String: String?](),
            "2": ["7": "seven", "8": "eight", "9": "nine"]
        ]

        client.dictionary.getDictionaryItemEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, dictDictEmpty)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call \(#function) failed. 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 AutoRestSwaggerBatFile
import AzureCore
import Foundation
import XCTest

class AutoRestSwaggerBatFileTest: XCTestCase {
    var client: AutoRestSwaggerBatFileClient!

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

    func test_BodyFile_getFile() throws {
        let expectation = XCTestExpectation(description: "Call getFile")

        client.files.getFile { result, httpResponse in
            switch result {
            case .success:
                guard let data = httpResponse?.data else {
                    XCTFail("Call getFile failed")
                    return
                }
                XCTAssertEqual(data.count, 8725)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getFile failed. error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_BodyFile_getEmptyFile() throws {
        let expectation = XCTestExpectation(description: "Call getEmptyFile")

        client.files.getEmptyFile { result, httpResponse in
            switch result {
            case .success:
                guard let data = httpResponse?.data else {
                    XCTFail("Call getEmptyFile failed")
                    return
                }
                XCTAssertTrue(data.isEmpty)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getEmptyFile failed. error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_BodyFile_getFileLarge() throws {
        let expectation = XCTestExpectation(description: "Call getFileLarge")

        client.files.getFileLarge { result, httpResponse in
            switch result {
            case .success:
                guard let data = httpResponse?.data else {
                    XCTFail("Call getFileLarge failed")
                    return
                }
                XCTAssertEqual(data.count, 3000 * 1024 * 1024)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getFileLarge failed. error=\(details)")
            }
            expectation.fulfill()
        }

        wait(for: [expectation], timeout: 30.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 AutoRestSwaggerBatHeader
import AzureCore
import XCTest

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length
// swiftlint:disable cyclomatic_complexity
// swiftlint:disable function_body_length
// swiftlint:disable type_body_length
class AutoRestSwaggerBatHeaderTest: XCTestCase {
    var client: AutoRestSwaggerBatHeaderClient!

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

    func test_header_paramProtectedKey200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramProtectedKey")

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

    func test_header_paramInteger200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramInteger")

        client.header.paramInteger(scenario: "positive", value: 1) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramInteger failed. error=\(details)")
            }
        }

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

    func test_header_responseInteger200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramInteger")

        client.header.responseInteger(scenario: "positive") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "1")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramInteger failed. error=\(details)")
            }
        }

        client.header.responseInteger(scenario: "negative") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "-2")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramInteger failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramLong200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramLong")

        client.header.paramLong(scenario: "positive", value: 105) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramLong failed. error=\(details)")
            }
        }

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

    func test_header_responseLong200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseLong")

        client.header.responseLong(scenario: "positive") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "105")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.responseLong failed. error=\(details)")
            }
        }

        client.header.responseLong(scenario: "negative") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "-2")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.responseLong failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramFloat200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramFloat")

        client.header.paramFloat(scenario: "positive", value: 0.07) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramFloat failed. error=\(details)")
            }
        }

        client.header.paramFloat(scenario: "negative", value: -3.0) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramFloat failed. error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_header_responseFloat200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseFloat")

        client.header.responseFloat(scenario: "positive") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "0.07")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.responseFloat failed. error=\(details)")
            }
        }

        client.header.responseFloat(scenario: "negative") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "-3")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.responseFloat failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramDouble200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramDouble")

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

    func test_header_responseDouble200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseDouble")

        client.header.responseDouble(scenario: "negative") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "-3")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.responseDouble failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramBool200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramBool")

        client.header.paramBool(scenario: "true", value: true) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramBool failed. error=\(details)")
            }
        }

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

    func test_header_responseBool200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseBool")

        client.header.responseBool(scenario: "true") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "true")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.responseBool failed. error=\(details)")
            }
        }

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

    func test_header_paramString200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramString")

        let options = ParamStringOptions(
            value: "The quick brown fox jumps over the lazy dog"
        )

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

        let emptyOptions = ParamStringOptions(
            value: ""
        )
        client.header.paramString(scenario: "empty", withOptions: emptyOptions) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramString failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_responseString200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseString")

        client.header.responseString(scenario: "valid") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "The quick brown fox jumps over the lazy dog")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_header_paramDate200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramDate")
        let dateString = "2010-01-01"
        let minDateString = "0001-01-01"
        let date = SimpleDate(string: dateString)!
        let minDate = SimpleDate(string: minDateString)!
        client.header.paramDate(scenario: "valid", value: 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 header.paramDate failed. error=\(details)")
            }
        }

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

    func test_header_responseDate200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseDate")

        client.header.responseDate(scenario: "valid") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "2010-01-01")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
        }

        client.header.responseDate(scenario: "min") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "0001-01-01")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramDatetime200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramDatetime")

        let dateString = "2010-01-01T12:34:56Z"
        let date = Iso8601Date(string: dateString)!
        let minDateString = "0001-01-01T00:00:00Z"
        let minDate = Iso8601Date(string: minDateString)!
        client.header.paramDatetime(scenario: "valid", value: 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 header.paramDatetime failed. error=\(details)")
            }
        }

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

    func test_header_responseDatetime200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseDatetime")

        client.header.responseDatetime(scenario: "valid") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "2010-01-01T12:34:56Z")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
        }

        client.header.responseDatetime(scenario: "min") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "0001-01-01T00:00:00Z")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramDatetimeRfc1123200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramDatetimeRfc1123")

        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss z"

        let dateString = "Wed, 01 Jan 2010 12:34:56 GMT"
        let date = Rfc1123Date(string: dateString)!
        let options = ParamDatetimeRfc1123Options(
            value: date
        )
        client.header.paramDatetimeRfc1123(scenario: "valid", withOptions: options) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDatetimeRfc1123 failed. error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_header_responseDatetimeRfc1123_200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseDatetimeRfc1123")

        client.header.responseDatetimeRfc1123(scenario: "valid") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "Fri, 01 Jan 2010 12:34:56 GMT")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
        }
        client.header.responseDatetimeRfc1123(scenario: "min") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "Mon, 01 Jan 0001 00:00:00 GMT")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramEnum200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramEnum")

        let options = ParamEnumOptions(
            value: .grey
        )

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

    func test_header_responseEnum200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseEnum")

        client.header.responseEnum(scenario: "valid") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "GREY")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_paramByte200() throws {
        let expectation = XCTestExpectation(description: "Call header.paramByte")

        client.header.paramByte(
            scenario: "valid",
            value: "5ZWK6b2E5LiC54ub54uc76ex76Ss76ex76iM76ip".data(using: .utf8)!
        ) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramEnum failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_header_responseByte200() throws {
        let expectation = XCTestExpectation(description: "Call header.responseByte")

        client.header.responseByte(scenario: "valid") { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(httpResponse?.headers["value"], "5ZWK6b2E5LiC54ub54uc76ex76Ss76ex76iM76ip")
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call header.paramDate 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 AutoRestSwaggerBat
import AzureCore
import XCTest

class AutoRestSwaggerBatTest: XCTestCase {
    var client: AutoRestSwaggerBatClient!

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

    func test_string_getNull_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getNull")

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

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

    func test_string_putNull_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.putNull")

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

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

    func test_string_getEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getEmpty")

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

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

    func test_string_putEmpty_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.putEmpty")

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

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

    func test_string_getMbcs_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getMbcs")

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

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

    func test_string_putMbcs_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.putMbcs")

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

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

    func test_string_getWhitespace_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getWhitespace")

        client.stringOperation.getWhitespace { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(
                    data,
                    "\"    Now is the time for all good men to come to the aid of their country    \""
                )
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call stringOperation.getWhitespace failed error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_string_putWhitespace_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.putWhitespace")

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

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

    func test_string_getNotProvided_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getNotProvided")

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

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

    func test_string_getBase64Encoded_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getBase64Encoded")

        client.stringOperation.getBase64Encoded { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(
                    String(decoding: data, as: UTF8.self),
                    "\"YSBzdHJpbmcgdGhhdCBnZXRzIGVuY29kZWQgd2l0aCBiYXNlNjQ=\""
                )
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getNotProvided.getBase64Encoded failed error=\(details)")
            }
            expectation.fulfill()
        }

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

    func test_string_getBase64UrlEncoded_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getBase64UrlEncoded")

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

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

    func test_string_getNullBase64UrlEncoded_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.getNullBase64UrlEncoded")

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

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

    func test_string_putBase64UrlEncoded_200() throws {
        let expectation = XCTestExpectation(description: "Call stringOperation.putBase64UrlEncoded")
        let data = "\"YSBzdHJpbmcgdGhhdCBnZXRzIGVuY29kZWQgd2l0aCBiYXNlNjR1cmw\""
        client.stringOperation.put(base64UrlEncoded: data) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getNotProvided.getBase64UrlEncoded failed error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_enum_getNotExpandable_200() throws {
        let expectation = XCTestExpectation(description: "Call enumOperation.getNotExpandable")

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

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

    func test_enum_putNotExpandable_200() throws {
        let expectation = XCTestExpectation(description: "Call enumOperation.putNotExpandable")

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

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

    func test_enum_getReferenced_200() throws {
        let expectation = XCTestExpectation(description: "Call enumOperation.getReferenced")

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

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

    func test_enum_putReferenced_200() throws {
        let expectation = XCTestExpectation(description: "Call enumOperation.putReferenced")

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

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

    func test_enum_getReferencedConstant_200() throws {
        let expectation = XCTestExpectation(description: "Call enumOperation.getReferencedConstant")

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

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

    func test_enum_putReferencedConstant_200() throws {
        let expectation = XCTestExpectation(description: "Call enumOperation.putReferencedConstant")

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

class AutoRestSwaggerBatTimeTest: XCTestCase {
    var client: AutoRestTimeTestClient!

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

    func test_get200() throws {
        let expectation = XCTestExpectation(description: "Call time.get")
        let expectedTime = SimpleTime(string: "11:34:56")!
        client.time.get { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, expectedTime)
                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_put200() throws {
        let expectation = XCTestExpectation(description: "Call time.put")
        let timeInput = SimpleTime(string: "08:07:56")!
        client.time.put(timeBody: timeInput) { 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)
    }
}