public void GetJsWebApiErrorCode_WebApiException_ReturnsExpectedErrorCode(WebApiErrorCode? errorCode, 
            Int32? unrecognisedErrorCode, String expectedCode)
        {
            /* Arrange */
            var ex = new WebApiException()
            {
                ErrorCode = errorCode,
                UnrecognisedErrorCode = unrecognisedErrorCode
            };

            /* Act */
            var code = WebApiController.GetJsWebApiErrorCode(ex);

            /* Assert */
            Assert.That(code, Is.EqualTo(expectedCode));
        }
        public void GetWebApiResourceResultOnError_AccessTokenExpired_ReturnsExpectedResult(Int32 attempt,
            Boolean expectNullJsonResult, Boolean expectedGetNewTokenFlag)
        {
            /* Arrange */
            var ex = new WebApiException()
            {
                StatusCode = HttpStatusCode.Unauthorized,
                AccessTokenExpiredOrInvalid = true
            };

            /* Act */
            Boolean getNewAccessToken;
            var result = WebApiController.GetWebApiResourceResultOnError(ex, attempt, out getNewAccessToken);

            /* Assert */
            Assert.That(result, expectNullJsonResult ? Is.Null : Is.Not.Null);
            Assert.That(getNewAccessToken, Is.EqualTo(expectedGetNewTokenFlag));
        }
        public void GetWebApiResourceResultOnError_WebApiErrorCode_ReturnsExceptedErrorCode(
            WebApiErrorCode? errorCode, String expectedErrorCode)
        {
            /* Arrange */
            var ex = new WebApiException()
            {
                StatusCode = HttpStatusCode.BadRequest,
                ErrorCode = errorCode
            };

            /* Act */
            Boolean getNewAccessToken;
            var result = WebApiController.GetWebApiResourceResultOnError(ex, 0, out getNewAccessToken);

            /* Assert */
            Assert.That(result.TypedData.success, Is.EqualTo(true));
            Assert.That(result.TypedData.webApiErrorCode, Is.EqualTo(expectedErrorCode));
        }
        public void GetWebApiResourceResultOnError_ErrorCondition_ReturnsExpectedResult(HttpStatusCode? statusCode,
            Boolean expectedSuccess, Int32 expectedStatus)
        {
            /* Arrange */
            var ex = new WebApiException() { StatusCode = statusCode };

            /* Act */
            Boolean getNewAccessToken;
            var result = WebApiController.GetWebApiResourceResultOnError(ex, 0, out getNewAccessToken);

            /* Assert */
            Assert.That(result.TypedData.success, Is.EqualTo(expectedSuccess));

            if (expectedSuccess)
                Assert.That(result.TypedData.httpStatus, Is.EqualTo(expectedStatus));
        }