Beispiel #1
0
        public ApodError GetApiKeyInvalidError()
        {
            var errorMessage = $"The API key you provided was invalid. Get one at {_apiUrl}.";
            var apodError    = new ApodError(ApodErrorCode.ApiKeyInvalid, errorMessage);

            return(apodError);
        }
Beispiel #2
0
        public ApodError GetUnknownError(string errorMessage = "")
        {
            var fullErrorMessage = $"{errorMessage} Please open an issue at {_unknownErrorIssueUrl}.";
            var apodError        = new ApodError(ApodErrorCode.Unknown, fullErrorMessage);

            return(apodError);
        }
Beispiel #3
0
        public ApodError GetApiKeyMissingError()
        {
            var errorMessage = $"You must provide an API key. Get one at {_apiUrl}.";
            var apodError    = new ApodError(ApodErrorCode.ApiKeyMissing, errorMessage);

            return(apodError);
        }
Beispiel #4
0
        public ApodError GetCountOutOfRangeError()
        {
            var errorMessage = "The count must be positive and cannot exceed 100.";
            var apodError    = new ApodError(ApodErrorCode.CountOutOfRange, errorMessage);

            return(apodError);
        }
Beispiel #5
0
        public ApodError GetTimeoutError()
        {
            var errorMessage = "The API timed out.";
            var apodError    = new ApodError(ApodErrorCode.Timeout, errorMessage);

            return(apodError);
        }
Beispiel #6
0
        public ApodError GetStartDateAfterEndDateError()
        {
            var errorMessage = "The start date cannot be after the end date.";
            var apodError    = new ApodError(ApodErrorCode.BadRequest, errorMessage);

            return(apodError);
        }
Beispiel #7
0
        public ApodError GetDateOutOfRangeError(DateTime firstValidDate, DateTime lastValidDate)
        {
            var errorMessage = $"Dates must be between {firstValidDate.ToString(_dateFormat)} and {lastValidDate.ToString(_dateFormat)}.";
            var apodError    = new ApodError(ApodErrorCode.DateOutOfRange, errorMessage);

            return(apodError);
        }
Beispiel #8
0
 /// <summary>
 /// The default constructor for an <see cref="ApodResponse"/>.
 /// </summary>
 /// <remarks>
 /// Unless you are overriding internal behaviour, you should not need to call this constructor.
 /// </remarks>
 /// <param name="statusCode">The <see cref="StatusCode"/> value.</param>
 /// <param name="allContent">The <see cref="AllContent"/> value.</param>
 /// <param name="error">The <see cref="Error"/> value.</param>
 public ApodResponse(ApodStatusCode statusCode, ApodContent[] allContent = null, ApodError error = null)
 {
     StatusCode = statusCode;
     AllContent = allContent;
     // Set the Content to the latest entry from AllContent
     Content = AllContent?[AllContent.Length > 1 ? AllContent.Length - 1: 0];
     Error   = error;
 }
Beispiel #9
0
        private void InputHasError(ApodErrorCode errorCode)
        {
            var error = new ApodError(errorCode);

            _errorHandler.Setup(x => x.ValidateCount(It.IsAny <int>())).Returns(error);
            _errorHandler.Setup(x => x.ValidateDate(It.IsAny <DateTime>())).Returns(error);
            _errorHandler.Setup(x => x.ValidateDateRange(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(error);
        }
Beispiel #10
0
        public ApodError GetOverRateLimitError()
        {
            // If/when this library provides caching in the future, information about that should be added here.
            var errorMessage = $"You have exceeded your rate limit. Try again later or go to {_apiUrl}/contact/ for assistance.";
            var apodError    = new ApodError(ApodErrorCode.OverRateLimit, errorMessage);

            return(apodError);
        }
Beispiel #11
0
        public void ToApodResponse_CorrectApodResponse(ApodErrorCode errorCode, string errorMessage)
        {
            var error = new ApodError(errorCode, errorMessage);

            var expected = new ApodResponse(ApodStatusCode.Error, error: error);

            var actual = error.ToApodResponse();

            Assert.Equal(expected.StatusCode, actual.StatusCode);
            Assert.Equal(expected.Error.ErrorCode, actual.Error.ErrorCode);
            Assert.Equal(expected.Error.ErrorMessage, actual.Error.ErrorMessage);
            Assert.Null(actual.Content);
            Assert.Null(actual.AllContent);
        }
Beispiel #12
0
        private void HttpResponseHasError(ApodErrorCode errorCode)
        {
            var error = new ApodError(errorCode);

            _errorHandler
            .Setup(x => x.ValidateHttpResponseAsync(It.IsAny <HttpResponseMessage>()))
            .ReturnsAsync(() => error);

            if (errorCode is ApodErrorCode.None)
            {
                var apodResponse = new ApodResponse(ApodStatusCode.OK);

                _httpResponseParser
                .Setup(x => x.ParseSingleApodAsync(It.IsAny <HttpResponseMessage>()))
                .ReturnsAsync(() => apodResponse);

                _httpResponseParser
                .Setup(x => x.ParseMultipleApodsAsync(It.IsAny <HttpResponseMessage>()))
                .ReturnsAsync(() => apodResponse);
            }
        }
Beispiel #13
0
        public ApodError GetInternalServiceError(string errorMessage = "")
        {
            var apodError = new ApodError(ApodErrorCode.InternalServiceError, errorMessage);

            return(apodError);
        }
Beispiel #14
0
        public ApodError GetBadRequestError(string errorMessage = "")
        {
            var apodError = new ApodError(ApodErrorCode.BadRequest, errorMessage);

            return(apodError);
        }