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

class AutoRestResourceFlatteningTest: XCTestCase {
    var client: AutoRestResourceFlatteningTestClient!

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

    // FIXME: Test
//    func test_resourceFlattening_getArray() throws {
//        let expectation = XCTestExpectation(description: "Call autorestresourceflatteningtestservice.getArray succeed")
//
//        client.autoRestResourceFlatteningTestService.getArray { result, httpResponse in
//            switch result {
//            case let .success(products):
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//                XCTAssertEqual(products.count, 3)
//                XCTAssertEqual(products[0].id, "1")
//                XCTAssertEqual(
//                    products[0].provisioningStateValues,
//                    FlattenedProductPropertiesProvisioningStateValues.oK
//                )
//                XCTAssertEqual(products[0].typePropertiesType, "Flat")
//                XCTAssertEqual(products[0].location, "Building 44")
//                XCTAssertEqual(products[0].name, "Resource1")
//                XCTAssertEqual(products[0].type, "Microsoft.Web/sites")
//                XCTAssertEqual(products[0].tags?["tag1"], "value1")
//                XCTAssertEqual(products[0].tags?["tag2"], "value3")
//                XCTAssertEqual(
//                    products[0].provisioningState,
//                    FlattenedProductPropertiesProvisioningStateValues.succeeded.rawValue
//                )
//                XCTAssertEqual(products[1].id, "2")
//                XCTAssertEqual(products[1].name, "Resource2")
//                XCTAssertEqual(products[1].location, "Building 44")
//                XCTAssertEqual(products[2].id, "3")
//                XCTAssertEqual(products[2].name, "Resource3")
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.getArray failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    func test_resourceFlattening_putArray() throws {
        let expectation =
            XCTestExpectation(
                description: "Call autorestresourceflatteningtestservice.putArray succeed"
            )
        let array = [
            Resource(tags: ["tag1": "value1", "tag2": "value3"], location: "West US"),
            Resource(location: "Building 44")
        ]
        client.autoRestResourceFlatteningTestService.put(array: array) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                print("test failed. error=\(details)")
                XCTFail("Call autorestresourceflatteningtestservice.putArray failed")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    // FIXME: Test
//    func test_resourceFlattening_getDictionary() throws {
//        let expectation =
//            XCTestExpectation(description: "Call autorestresourceflatteningtestservice.getDictionary succeed")
//        client.autoRestResourceFlatteningTestService.getDictionary { result, httpResponse in
//            switch result {
//            case let .success(products):
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//                XCTAssertEqual(products.count, 3)
//                XCTAssertEqual(products["Product1"]?.id, "1")
//                XCTAssertEqual(
//                    products["Product1"]?.provisioningStateValues,
//                    FlattenedProductPropertiesProvisioningStateValues.oK
//                )
//                XCTAssertEqual(products["Product1"]?.typePropertiesType, "Flat")
//                XCTAssertEqual(products["Product1"]?.location, "Building 44")
//                XCTAssertEqual(products["Product1"]?.name, "Resource1")
//                XCTAssertEqual(products["Product1"]?.type, "Microsoft.Web/sites")
//                XCTAssertEqual(products["Product1"]?.tags?["tag1"], "value1")
//                XCTAssertEqual(products["Product1"]?.tags?["tag2"], "value3")
//                XCTAssertEqual(
//                    products["Product1"]?.provisioningState,
//                    FlattenedProductPropertiesProvisioningStateValues.succeeded.rawValue
//                )
//                XCTAssertEqual(products["Product2"]?.id, "2")
//                XCTAssertEqual(products["Product2"]?.name, "Resource2")
//                XCTAssertEqual(products["Product2"]?.location, "Building 44")
//                XCTAssertEqual(products["Product3"]?.id, "3")
//                XCTAssertEqual(products["Product3"]?.name, "Resource3") case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.getDictionary failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    // FIMXE: Test
//    func test_resourceFlattening_putDictionary() throws {
//        let expectation =
//            XCTestExpectation(
//                description: "Call autorestresourceflatteningtestservice.putDictionary succeed"
//            )
//        let dictionary = [
//            "Resource1": FlattenedProduct(
//                pName: "Product1",
//                typePropertiesType: "Flat",
//                tags: ["tag1": "value1", "tag2": "value3"],
//                location: "West US"
//            ),
//            "Resource2": FlattenedProduct(
//                pName: "Product2",
//                typePropertiesType: "Flat",
//                location: "Building 44"
//            )
//        ]
//        client.autoRestResourceFlatteningTestService.put(dictionary: dictionary) { result, httpResponse in
//            switch result {
//            case .success:
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.putDictionary failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

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

    // FIXME: Test
//    func test_resourceFlattening_putResourceCollection() throws {
//        let expectation =
//            XCTestExpectation(
//                description: "Call autorestresourceflatteningtestservice.putResourceCollection succeed"
//            )
//        let collection = ResourceCollection(
//            productresource: FlattenedProduct(
//                pName: "Azure",
//                typePropertiesType: "Flat",
//                location: "India"
//            ),
//            arrayofresources: [
//                FlattenedProduct(
//                    pName: "Product1",
//                    typePropertiesType: "Flat",
//                    tags: ["tag1": "value1", "tag2": "value3"],
//                    location: "West US"
//                )
//            ],
//            dictionaryofresources: [
//                "Resource1": FlattenedProduct(
//                    pName: "Product1",
//                    typePropertiesType: "Flat",
//                    tags: ["tag1": "value1", "tag2": "value3"],
//                    location: "West US"
//                ),
//                "Resource2": FlattenedProduct(
//                    pName: "Product2",
//                    typePropertiesType: "Flat",
//                    location: "Building 44"
//                )
//            ]
//        )
//        client.autoRestResourceFlatteningTestService.put(resourceCollection: collection) { result, httpResponse in
//            switch result {
//            case .success:
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.putResourceCollection failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    // FIXME: Test
//    func test_resourceFlattening_getWrappedArray() throws {
//        let expectation =
//            XCTestExpectation(description: "Call autorestresourceflatteningtestservice.getWrappedArray succeed")
//        // FIXME: Request path must container array, dictionary or resourcecollection
//        client.autoRestResourceFlatteningTestService.getWrappedArray { result, httpResponse in
//            switch result {
//            case .success:
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.getWrappedArray failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    // FIXME: Test
//    func test_resourceFlattening_putWrappedArray() throws {
//        let expectation =
//            XCTestExpectation(
//                description: "Call autorestresourceflatteningtestservice.putWrappedArray succeed"
//            )
//        let wrapped = [
//            WrappedProduct(value: "test")
//        ]
//        // FIXME: Timeout fails
//        client.autoRestResourceFlatteningTestService.put(wrappedArray: wrapped) { result, httpResponse in
//            switch result {
//            case .success:
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.putWrappedArray failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    // FIXME: Test
//    func test_resourceFlattening_putSimpleProduct() throws {
//        let expectation =
//            XCTestExpectation(
//                description: "Call autorestresourceflatteningtestservice.putSimpleProduct succeed"
//            )
//        let product = SimpleProduct(
//            maxProductDisplayName: "max name",
//            odataValue: "http://foo",
//            productId: "123",
//            description: "product description"
//        )
//        // FIXME: Serialization of flattened object to the wire needs fixing
//        client.autoRestResourceFlatteningTestService.put(simpleProduct: product) { result, httpResponse in
//            switch result {
//            case .success:
//                XCTAssertEqual(httpResponse?.statusCode, 200)
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.putSimpleProduct failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }

    // FIXME: Test
//    func test_resourceFlattening_putSimpleProductWithGroupingFlattenParameterGroup() throws {
//        let expectation =
//            XCTestExpectation(
//                description: "Call autorestresourceflatteningtestservice.putSimpleProductWithGroupingFlattenParameterGroup succeed"
//            )
//        let group = FlattenParameterGroup(
//            name: "groupproduct",
//            productId: "123",
//            description: "product description",
//            maxProductDisplayName: "max name",
//            odataValue: "http://foo"
//        )
//        // FIXME: Received body is {} (empty)
//        client.autoRestResourceFlatteningTestService
//            .putSimpleProductWithGrouping(flattenParameterGroup: group) { result, httpResponse in
//                switch result {
//                case .success:
//                    XCTAssertEqual(httpResponse?.statusCode, 200)
//                case let .failure(error):
//                    let details = errorDetails(for: error, withResponse: httpResponse)
//                    print("test failed. error=\(details)")
//                    XCTFail(
//                        "Call autorestresourceflatteningtestservice.putSimpleProductWithGroupingFlattenParameterGroup failed"
//                    )
//                }
//                expectation.fulfill()
//            }
//        wait(for: [expectation], timeout: 5.0)
//    }

    // FIXME: Test
//    func test_resourceFlattening_postFlattenedSimpleProduct() throws {
//        let expectation =
//            XCTestExpectation(
//                description: "Call autorestresourceflatteningtestservice.postFlattenedSimpleProduct succeed"
//            )
//        // FIXME: Serialization of flattened object to the wire needs fixing
//        client.autoRestResourceFlatteningTestService.postFlattenedSimpleProduct(
//            productId: "123",
//            description: "product description",
//            maxProductDisplayName: "max name",
//            odataValue: "http://foo"
//        ) { result, httpResponse in
//            switch result {
//            case .success:
//                expectation.fulfill()
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                print("test failed. error=\(details)")
//                XCTFail("Call autorestresourceflatteningtestservice.postFlattenedSimpleProduct failed")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: 5.0)
//    }
}


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

    let defaultTimeout = 5.0

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

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

        client.arrayOperation.getNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to failed.")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getInvalid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getInvalid")

        client.arrayOperation.getInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to failed.")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getBase64Url200() throws {
        let expected: [String] = [
            "a string that gets encoded with base64url".base64EncodedString(trimmingEquals: true),
            "test string".base64EncodedString(trimmingEquals: true),
            "Lorem ipsum".base64EncodedString(trimmingEquals: true)
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.arrayOperation.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_getEmpty200() throws {
        let expectation = XCTestExpectation(description: "Call array.getEmpty")

        client.arrayOperation.getEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data.count, 0)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putEmpty200() throws {
        let expectation = XCTestExpectation(description: "Call array.putEmpty")

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

    func test_getBooleanTfft200() throws {
        let expectation = XCTestExpectation(description: "Call array.getBooleanTfft")

        client.arrayOperation.getBooleanTfft { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [true, false, false, true])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putBooleanTfft200() throws {
        let expectation = XCTestExpectation(description: "Call array.putBooleanTfft")

        client.arrayOperation.put(booleanTfft: [true, false, false, true]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getBooleanInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getBooleanInvalidNull")

        client.arrayOperation.getBooleanInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertEqual(details.data, "[ true, null, false ]")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getBooleanInvalidString200() throws {
        let expectation = XCTestExpectation(description: "Call array.getBooleanInvalidString")

        client.arrayOperation.getBooleanInvalidString { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to failed.")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertEqual(details.data, "[true, \"boolean\", false]")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getIntegerValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getIntegerValid")

        client.arrayOperation.getIntegerValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [1, -1, 3, 300])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putIntegerValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putIntegerValid")

        client.arrayOperation.put(integerValid: [1, -1, 3, 300]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getIntInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getIntInvalidNull")

        client.arrayOperation.getIntInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("1, null, 0"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getIntInvalidString200() throws {
        let expectation = XCTestExpectation(description: "Call array.getFloatWithString")

        client.arrayOperation.getIntInvalidString { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("1, \"integer\", 0"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getLongValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getLongValid")

        client.arrayOperation.getLongValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [1, -1, 3, 300])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putLongValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putLongValid")

        client.arrayOperation.put(longValid: [1, -1, 3, 300]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getLongInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getLongInvalidNull")

        client.arrayOperation.getLongInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("1, null, 0"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getLongInvalidString200() throws {
        let expectation = XCTestExpectation(description: "Call array.getLongInvalidString")

        client.arrayOperation.getLongInvalidString { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("1, \"integer\", 0"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getFloatValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getFloatValid")

        client.arrayOperation.getFloatValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [0, -0.01, -1.2e20])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    // FIXME: See https://github.com/Azure/autorest.swift/issues/291
//    func test_putFloatValid200() throws {
//        let expectation = XCTestExpectation(description: "Call array.getFloatValid")
//        let expected: [Float] = [0, -0.01, -1.2e20]
//        client.arrayOperation.put(floatValid: expected) { result, httpResponse in
//            switch result {
//            case .success:
//                break
//            case let .failure(error):
//                let details = errorDetails(for: error, withResponse: httpResponse)
//                XCTFail("\(expectation.description) failed. error=\(details)")
//            }
//            expectation.fulfill()
//        }
//        wait(for: [expectation], timeout: defaultTimeout)
//    }

    func test_getFloatInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getFloatInvalidNull")

        client.arrayOperation.getFloatInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("0.0, null, -1.2e20"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getFloatWithString200() throws {
        let expectation = XCTestExpectation(description: "Call array.getFloatWithString")

        client.arrayOperation.getFloatInvalidString { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("1, \"number\", 0"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDoubleValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDoubleValid")

        client.arrayOperation.getDoubleValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [0, -0.01, -1.2e20])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putDoubleValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putDoubleValid")

        client.arrayOperation.put(doubleValid: [0, -0.01, -1.2e20]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDoubleInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDoubleInvalidNull")

        client.arrayOperation.getDoubleInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("0.0, null, -1.2e20"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDoubleInvalidString200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDoubleInvalidString")

        client.arrayOperation.getDoubleInvalidString { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("1, \"number\", 0"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getStringValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getStringValid")

        client.arrayOperation.getStringValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, ["foo1", "foo2", "foo3"])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putStringValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putStringValid")

        client.arrayOperation.put(stringValid: ["foo1", "foo2", "foo3"]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getStringWithInvalid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getStringWithInvalid")

        client.arrayOperation.getStringWithInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("\"foo\", 123, \"foo2\""))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getStringWithNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getStringWithNull")

        let expectedData = ["foo", nil, "foo2"]
        client.arrayOperation.getStringWithNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                for i in 0 ..< data.count {
                    if let item = data[i] {
                        XCTAssertEqual(item, expectedData[i])
                    } else {
                        XCTAssertNil(expectedData[i])
                    }
                }
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getEnumValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getEnumValid")

        client.arrayOperation.getEnumValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [FooEnum.foo1, FooEnum.foo2, FooEnum.foo3])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putEnumValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putEnumValid")

        client.arrayOperation.put(enumValid: [FooEnum.foo1, FooEnum.foo2, FooEnum.foo3]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getStringEnumValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getStringEnumValid")

        client.arrayOperation.getStringEnumValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, [Enum0.foo1, Enum0.foo2, Enum0.foo3])
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putStringEnumValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putStringEnumValid")

        client.arrayOperation.put(stringEnumValid: [Enum1.foo1, Enum1.foo2, Enum1.foo3]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getUuidValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getUuidValid")

        client.arrayOperation.getUuidValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(
                    data,
                    [
                        "6dcc7237-45fe-45c4-8a6b-3a8a3f625652",
                        "d1399005-30f7-40d6-8da6-dd7c89ad34db",
                        "f42f6aa1-a5bc-4ddf-907e-5f915de43205"
                    ]
                )
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putUuidValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putUuidValid")

        client.arrayOperation.put(uuidValid: [
            "6dcc7237-45fe-45c4-8a6b-3a8a3f625652",
            "d1399005-30f7-40d6-8da6-dd7c89ad34db",
            "f42f6aa1-a5bc-4ddf-907e-5f915de43205"
        ]) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func getDateInvalidNull() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateInvalidNull")

        client.arrayOperation.getDateInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("\"foo\", null, \"foo2\""))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateInvalidChars200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateInvalidChars")

        client.arrayOperation.getDateInvalidChars { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("[\"2011-03-22\", \"date\"]"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateValid")
        let expectedDates = [
            SimpleDate(string: "2000-12-01")!,
            SimpleDate(string: "1980-01-02")!,
            SimpleDate(string: "1492-10-12")!
        ]

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

    func test_getDateTimeInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateTimeInvalidNull")

        client.arrayOperation.getDateTimeInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("\"2000-12-01t00:00:01z\", null"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateTimeInvalidChars200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateTimeInvalidChars")

        client.arrayOperation.getDateTimeInvalidChars { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail")
            case let .failure(error):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTAssertTrue(details.contains("date-time"))
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDateTimeValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateTimeValid")

        let expectedDates = [
            Iso8601Date(string: "2000-12-01t00:00:01z")!,
            Iso8601Date(string: "1980-01-02T01:11:35+01:00")!,
            Iso8601Date(string: "1492-10-12T02:15:01-08:00")!
        ]

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

    func test_getDateTimeRfc1123Valid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDateTimeRfc1123Valid")
        let expectedDates = [
            Rfc1123Date(string: "Fri, 01 Dec 2000 00:00:01 GMT")!,
            Rfc1123Date(string: "Wed, 02 Jan 1980 00:11:35 GMT")!,
            Rfc1123Date(string: "Wed, 12 Oct 1492 10:15:01 GMT")!
        ]
        client.arrayOperation.getDateTimeRfc1123Valid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(data, expectedDates)
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putDateValid() throws {
        let expectation = XCTestExpectation(description: "Call array.putDateValid")
        let expectedDates = [
            SimpleDate(string: "2000-12-01")!,
            SimpleDate(string: "1980-01-02")!,
            SimpleDate(string: "1492-10-12")!
        ]
        client.arrayOperation.put(dateValid: expectedDates) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getByteValid() throws {
        let expectation = XCTestExpectation(description: "Call array.getByteValid")

        let expectedData = [
            Data([255, 255, 255, 250]),
            Data([1, 2, 3]),
            Data([37, 41, 67])
        ]
        client.arrayOperation.getByteValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, expectedData)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getByteInvalidNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getByteInvalidNull")

        client.arrayOperation.getByteInvalidNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail.")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_puttByteValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.puttByteValid")

        let data = [
            Data([255, 255, 255, 250]),
            Data([1, 2, 3]),
            Data([37, 41, 67])
        ]
        client.arrayOperation.put(byteValid: data) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getArrayValid() throws {
        let expectation = XCTestExpectation(description: "Call array.getArrayValid")

        client.arrayOperation.getArrayValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]])
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putArrayValid() throws {
        let expectation = XCTestExpectation(description: "Call array.putArrayValid")

        let data = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]

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

    func test_getArrayEmpty() throws {
        let expectation = XCTestExpectation(description: "Call array.getArrayEmpty")

        client.arrayOperation.getArrayEmpty { 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("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getArrayNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getArrayNull")

        client.arrayOperation.getArrayNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail.")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getArrayItemEmpty() throws {
        let expectation = XCTestExpectation(description: "Call array.getArrayItemEmpty")

        client.arrayOperation.getArrayItemEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, [["1", "2", "3"], [], ["7", "8", "9"]])
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getArraygetArrayItemNull() throws {
        let expectation = XCTestExpectation(description: "Call array.getArrayItemNull")

        client.arrayOperation.getArrayItemNull { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, [["1", "2", "3"], nil, ["7", "8", "9"]])
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getComplexValid() throws {
        let expectation = XCTestExpectation(description: "Call array.getComplexValid")

        let expectedData: [Product] = [
            Product(integer: 1, string: "2"),
            Product(integer: 3, string: "4"),
            Product(integer: 5, string: "6")
        ]
        client.arrayOperation.getComplexValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)

                for i in 0 ..< data.count {
                    XCTAssertEqual(data[i].integer, expectedData[i].integer)
                }

            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getComplexEmpty200() throws {
        let expectation = XCTestExpectation(description: "Call array.getComplexEmpty")

        client.arrayOperation.getComplexEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data.count, 0)

            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putComplexValid() throws {
        let expectation = XCTestExpectation(description: "Call array.putComplexValid")

        let data: [Product] = [
            Product(integer: 1, string: "2"),
            Product(integer: 3, string: "4"),
            Product(integer: 5, string: "6")
        ]
        client.arrayOperation.put(complexValid: data) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getComplexNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getComplexNull")

        client.arrayOperation.getComplexNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail.")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDictionaryValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDictionaryValid")

        let expectedData: [[String: String]] = [
            ["1": "one", "2": "two", "3": "three"],
            ["4": "four", "5": "five", "6": "six"],
            ["7": "seven", "8": "eight", "9": "nine"]
        ]
        client.arrayOperation.getDictionaryValid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, expectedData)

            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDictionaryEmpty200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDictionaryEmpty")

        client.arrayOperation.getDictionaryEmpty { 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("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDictionaryItemEmpty() throws {
        let expectation = XCTestExpectation(description: "Call array.getDictionaryItemEmpty")

        let expectedData: [[String: String]] = [
            ["1": "one", "2": "two", "3": "three"],
            [:],
            ["7": "seven", "8": "eight", "9": "nine"]
        ]
        client.arrayOperation.getDictionaryItemEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(httpResponse?.statusCode, 200)
                XCTAssertEqual(data, expectedData)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_getDictionaryItemNull() throws {
        let expectation = XCTestExpectation(description: "Call array.getDictionaryItemNull")

        let expectedData: [[String: String]?] = [
            ["1": "one", "2": "two", "3": "three"],
            nil,
            ["7": "seven", "8": "eight", "9": "nine"]
        ]

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

    func test_getDictionaryNull200() throws {
        let expectation = XCTestExpectation(description: "Call array.getDictionaryNull")

        client.arrayOperation.getDictionaryNull { result, httpResponse in
            switch result {
            case .success:
                XCTFail("\(expectation.description) expected to fail.")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

    func test_putDictionaryValid200() throws {
        let expectation = XCTestExpectation(description: "Call array.putDictionaryValid")

        let data: [[String: String]] = [
            ["1": "one", "2": "two", "3": "three"],
            ["4": "four", "5": "five", "6": "six"],
            ["7": "seven", "8": "eight", "9": "nine"]
        ]
        client.arrayOperation.put(dictionaryValid: data) { result, httpResponse in
            switch result {
            case .success:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("\(expectation.description) failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: defaultTimeout)
    }

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

        client.arrayOperation.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: [Iso8601Duration] = [
            Iso8601Duration(string: "P123DT22H14M12.011S")!,
            Iso8601Duration(string: "P5DT1H")!
        ]
        let expectation = XCTestExpectation(description: "Call \(#function)")

        client.arrayOperation.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)
    }
}


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

class AutoRestSwaggerBatBoolTest: XCTestCase {
    var client: AutoRestBoolTestClient!

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

    func test_getTrue200() throws {
        let expectation = XCTestExpectation(description: "Call bool.getTrue")

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

    func test_putTrue200() throws {
        let expectation = XCTestExpectation(description: "Call bool.putTrue")

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

    func test_getFalse200() throws {
        let expectation = XCTestExpectation(description: "Call bool.getFalse")

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

    func test_putFalse200() throws {
        let expectation = XCTestExpectation(description: "Call bool.putFalse")

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

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

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

    func test_getInvalid200() throws {
        let expectation = XCTestExpectation(description: "Call bool.getInvalid")

        client.boolOperation.getInvalid { result, httpResponse in
            switch result {
            case .success:
                XCTFail("bool.getInvalid expected failed")
            case .failure:
                XCTAssertEqual(httpResponse?.statusCode, 200)
            }
            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 AutoRestSwaggerBatByte
import AzureCore
import XCTest

class AutoRestSwaggerBatByteTest: XCTestCase {
    var client: AutoRestSwaggerBatByteClient!

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

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

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

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

        client.byte.getEmpty { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(String(decoding: data, as: UTF8.self), "\"\"")
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getEmpty failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getNonAscii200() throws {
        let expectation = XCTestExpectation(description: "Call byte.getNonAscii")

        client.byte.getNonAscii { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(String(decoding: data, as: UTF8.self), "\"//79/Pv6+fj39g==\"")
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getNonAscii failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_getInvalid() throws {
        let expectation = XCTestExpectation(description: "Call byte.getInvalid")

        client.byte.getInvalid { result, httpResponse in
            switch result {
            case let .success(data):
                XCTAssertEqual(String(decoding: data, as: UTF8.self), "\"::::SWAGGER::::\"")
                XCTAssertEqual(httpResponse?.statusCode, 200)
            case let .failure(error):
                let details = errorDetails(for: error, withResponse: httpResponse)
                XCTFail("Call getInvalid failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }

    func test_putInvalid() throws {
        let expectation = XCTestExpectation(description: "Call byte.put")

        client.byte.put(nonAscii: "\"//79/Pv6+fj39g==\"".data(using: .utf8) ?? 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 put failed. error=\(details)")
            }
            expectation.fulfill()
        }
        wait(for: [expectation], timeout: 5.0)
    }
}