summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/TestUtilities/TestMultipleRequestsConnectionManager.m
blob: b1935a8ab9e4edde52916fb13dc576e3a79efc28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
//  TestMultipleRequestsConnectionManager.m
//  SmartDeviceLinkTests
//
//  Created by Joel Fischer on 2/8/18.
//  Copyright © 2018 smartdevicelink. All rights reserved.
//

#import "TestMultipleRequestsConnectionManager.h"

#import "SDLAddCommand.h"
#import "SDLAddCommandResponse.h"
#import "SDLRPCFunctionNames.h"
#import "TestResponse.h"

@implementation TestMultipleRequestsConnectionManager

- (instancetype)init {
    self = [super init];
    if (!self) { return nil; }

    _responses = [[NSMutableDictionary alloc] init];

    return self;
}

- (void)sendConnectionRPC:(__kindof SDLRPCMessage *)rpc {
    [super sendConnectionRPC:rpc];
}

- (void)sendConnectionRequest:(__kindof SDLRPCRequest *)request withResponseHandler:(nullable SDLResponseHandler)handler {
    [super sendConnectionRequest:request withResponseHandler:handler];

    NSAssert([request.name isEqualToString:SDLRPCFunctionNameAddCommand], @"The TestMultipleRequestsConnectionManager is only setup for SDLAddCommand");

    SDLAddCommand *addCommand = (SDLAddCommand *)request;
    TestResponse *response = self.responses[addCommand.correlationID];

    if (response == nil || handler == nil) { return; }
    handler(request, response.testResponse, response.testError);
}

@end