Beispiel #1
0
 /// <summary>
 /// Creates a new instance of the <see cref="NntpLastResponse"/> class.
 /// </summary>
 /// <param name="code">The response code received from the server.</param>
 /// <param name="message">The response message received from the server.</param>
 /// <param name="success">A value indicating whether the command succeeded or failed.</param>
 /// <param name="responseType">The type of the response received from the server.</param>
 /// <param name="number">The <see cref="NntpArticle"/> number received from the server.</param>
 /// <param name="messageId">The <see cref="NntpMessageId"/> received from the server.</param>
 public NntpLastResponse(int code, string message, bool success, NntpLastResponseType responseType, int number, NntpMessageId messageId)
     : base(code, message, success)
 {
     ResponseType = responseType;
     Number       = number;
     MessageId    = messageId ?? NntpMessageId.Empty;
 }
Beispiel #2
0
        public NntpLastResponse Parse(int code, string message)
        {
            NntpLastResponseType responseType = Enum.IsDefined(typeof(NntpLastResponseType), code)
                ? (NntpLastResponseType)code
                : NntpLastResponseType.Unknown;

            if (responseType == NntpLastResponseType.Unknown)
            {
                log.LogError("Invalid response code: {Code}", code);
            }

            if (!IsSuccessResponse(code))
            {
                return(new NntpLastResponse(code, message, false, responseType, 0, string.Empty));
            }

            // get stat
            string[] responseSplit = message.Split(' ');
            if (responseSplit.Length < 2)
            {
                log.LogError("Invalid response message: {Message} Expected: {{number}} {{messageid}}", message);
            }

            int.TryParse(responseSplit.Length > 0 ? responseSplit[0] : null, out int number);
            string messageId = responseSplit.Length > 1 ? responseSplit[1] : string.Empty;

            return(new NntpLastResponse(code, message, true, responseType, number, messageId));
        }
Beispiel #3
0
        public void ResponseShouldBeParsedCorrectly(
            int responseCode,
            string responseMessage,
            NntpLastResponseType expectedResponseType,
            long expectedArticleNumber,
            string expectedMessageId)
        {
            NntpLastResponse lastResponse = new LastResponseParser().Parse(responseCode, responseMessage);

            Assert.Equal(expectedResponseType, lastResponse.ResponseType);
            Assert.Equal(expectedArticleNumber, lastResponse.Number);
            Assert.Equal(expectedMessageId, lastResponse.MessageId.Value);
        }