public async Task Invoke_HttpInternalServerError_HttpResponseExceptionHasInternalServerError()
        {
            var mockAuthenticationClient = new Mock <IAuthenticationClientAsync>();

            mockAuthenticationClient.Setup(ac => ac.Login())
            .Returns(Task.FromResult(new LoginResponse()
            {
                LoginStatus = "SUCCESS", SessionToken = "abc"
            }));

            _mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError,
                Content    = new StringContent("{}")
            }));

            HttpClient httpClient = new HttpClient(_mockHttpMessageHandler.Object);

            _requestInvoker = new RequestInvokerAsync(mockAuthenticationClient.Object, _mockConfiguration.Object, httpClient, _mockRegistry);
            try
            {
                await _requestInvoker.Invoke <IList <EventTypeResult> >(BetfairMethod.ListEventTypes, null);
            }
            catch (HttpResponseException exception)
            {
                Assert.AreEqual(HttpStatusCode.InternalServerError, exception.Response.StatusCode);
            }
        }
        public async Task Invoke_MethodIsEmpty_ThrowsArgumentOutOfRangeException()
        {
            var        mockAuthenticationClient = new Mock <IAuthenticationClientAsync>();
            HttpClient httpClient = new HttpClient(_mockHttpMessageHandler.Object);

            _requestInvoker = new RequestInvokerAsync(mockAuthenticationClient.Object, _mockConfiguration.Object, httpClient, _mockRegistry);
            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() =>
                                                                            await _requestInvoker.Invoke <IList <EventTypeResult> >(BetfairMethod.UnknownMethod, null));
        }
        public async Task Invoke_LoginResponseIsNull_ThrowsAuthenticationException()
        {
            var mockAuthenticationClient = new Mock <IAuthenticationClientAsync>();

            mockAuthenticationClient.Setup(ac => ac.Login())
            .Returns(Task.FromResult((LoginResponse)null));

            HttpClient httpClient = new HttpClient(_mockHttpMessageHandler.Object);

            _requestInvoker = new RequestInvokerAsync(mockAuthenticationClient.Object, _mockConfiguration.Object, httpClient, _mockRegistry);
            await Assert.ThrowsExceptionAsync <AuthenticationException>(async() =>
                                                                        await _requestInvoker.Invoke <IList <EventTypeResult> >(BetfairMethod.ListEventTypes, null));
        }
        public async Task Invoke_AuthenticationThrowsHttpResponseException_ThrowsHttpResponseException()
        {
            var mockAuthenticationClient = new Mock <IAuthenticationClientAsync>();

            mockAuthenticationClient.Setup(ac => ac.Login())
            .Throws(new HttpResponseException(HttpStatusCode.InternalServerError));

            HttpClient httpClient = new HttpClient(_mockHttpMessageHandler.Object);

            _requestInvoker = new RequestInvokerAsync(mockAuthenticationClient.Object, _mockConfiguration.Object, httpClient, _mockRegistry);
            await Assert.ThrowsExceptionAsync <HttpResponseException>(async() =>
                                                                      await _requestInvoker.Invoke <IList <EventTypeResult> >(BetfairMethod.ListEventTypes, null));
        }