Example #1
0
        public NntpNextResponse Parse(int code, string message)
        {
            NntpNextResponseType responseType = Enum.IsDefined(typeof(NntpNextResponseType), code)
                ? (NntpNextResponseType)code
                : NntpNextResponseType.Unknown;

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

            if (!IsSuccessResponse(code))
            {
                return(new NntpNextResponse(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);
            }

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

            return(new NntpNextResponse(code, message, true, responseType, number, messageId));
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="NntpNextResponse"/> 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 NntpNextResponse(int code, string message, bool success, NntpNextResponseType responseType, long number, NntpMessageId messageId)
     : base(code, message, success)
 {
     ResponseType = responseType;
     Number       = number;
     MessageId    = messageId ?? NntpMessageId.Empty;
 }
 public void ResponseShouldBeParsedCorrectly(
     int responseCode, 
     string responseMessage,
     NntpNextResponseType expectedResponseType,
     long expectedArticleNumber, 
     string expectedMessageId)
 {
     NntpNextResponse nextResponse = new NextResponseParser().Parse(responseCode, responseMessage);
     Assert.Equal(expectedResponseType, nextResponse.ResponseType);
     Assert.Equal(expectedArticleNumber, nextResponse.Number);
     Assert.Equal(expectedMessageId, nextResponse.MessageId.Value);
 }