public void InputShouldBeParsedCorrectly(string input, NntpPostingStatus expectedStatus, string expectedOtherGroup)
        {
            NntpPostingStatus status = PostingStatusParser.Parse(input, out string otherGroup);

            Assert.Equal(expectedStatus, status);
            Assert.Equal(expectedOtherGroup, otherGroup);
        }
示例#2
0
        /// <summary>
        /// Creates a new instance of the <see cref="NntpGroup"/> class.
        /// </summary>
        /// <param name="name">The name of the <see cref="NntpGroup"/>.</param>
        /// <param name="articleCount">The estimated number of articles in the <see cref="NntpGroup"/>.</param>
        /// <param name="lowWaterMark">The reported low water mark of the <see cref="NntpGroup"/>.</param>
        /// <param name="highWaterMark">The reported high water mark of the <see cref="NntpGroup"/>.</param>
        /// <param name="postingStatus">The current <see cref="NntpPostingStatus"/> of the <see cref="NntpGroup"/>.</param>
        /// <param name="otherGroup">The name of the other <see cref="NntpGroup"/> under which the articles are filed when the
        /// <see cref="PostingStatus"/> is <see cref="NntpPostingStatus.OnlyArticlesFromPeersPermittedFiledLocally"/>.</param>
        /// <param name="articleNumbers">A list of <see cref="NntpArticle"/> numbers in the <see cref="NntpGroup"/>.</param>
        public NntpGroup(
            string name,
            long articleCount,
            long lowWaterMark,
            long highWaterMark,
            NntpPostingStatus postingStatus,
            string otherGroup,
            IEnumerable <long> articleNumbers)
        {
            Name          = name ?? string.Empty;
            ArticleCount  = articleCount;
            LowWaterMark  = lowWaterMark;
            HighWaterMark = highWaterMark;
            PostingStatus = Enum.IsDefined(typeof(NntpPostingStatus), postingStatus) ? postingStatus : NntpPostingStatus.Unknown;
            OtherGroup    = otherGroup ?? string.Empty;

            switch (articleNumbers)
            {
            case null:
                // create empty immutable list
                ArticleNumbers = new List <long>(0).ToImmutableList();
                break;

            case ICollection <long> collection:
                // make immutable
                ArticleNumbers = collection.OrderBy(n => n).ToImmutableList();
                break;

            default:
                // not a collection but a stream of numbers, keep enumerator
                // this is immutable already
                ArticleNumbers = articleNumbers;
                break;
            }
        }
示例#3
0
        private IEnumerable <NntpGroup> EnumerateGroups(IEnumerable <string> dataBlock)
        {
            if (dataBlock == null)
            {
                yield break;
            }

            int    checkParameterCount = requestType == GroupStatusRequestType.Basic ? 4 : 5;
            string errorMessage        = requestType == GroupStatusRequestType.Basic
                ? "Invalid newsgroup information line: {Line} Expected: {{group}} {{high}} {{low}} {{status}}"
                : "Invalid newsgroup information line: {Line} Expected: {{group}} {{high}} {{low}} {{count}} {{status}}";

            foreach (string line in dataBlock)
            {
                string[] lineSplit = line.Split(' ');
                if (lineSplit.Length < checkParameterCount)
                {
                    log.LogError(errorMessage, line);
                    continue;
                }

                var argCount = 1;
                int.TryParse(lineSplit[argCount++], out int highWaterMark);
                int.TryParse(lineSplit[argCount++], out int lowWaterMark);

                var articleCount = 0;
                if (requestType == GroupStatusRequestType.Extended)
                {
                    int.TryParse(lineSplit[argCount++], out articleCount);
                }

                NntpPostingStatus postingStatus = PostingStatusParser.Parse(lineSplit[argCount], out string otherGroup);
                if (postingStatus == NntpPostingStatus.Unknown)
                {
                    log.LogError("Invalid posting status {Status} in line: {Line}", lineSplit[argCount], line);
                }

                yield return(new NntpGroup(
                                 lineSplit[0],
                                 articleCount,
                                 lowWaterMark,
                                 highWaterMark,
                                 postingStatus,
                                 otherGroup,
                                 new int[0]));
            }
        }
示例#4
0
 /// <summary>
 /// Creates a new instance of the <see cref="NntpGroup"/> class.
 /// </summary>
 /// <param name="name">The name of the <see cref="NntpGroup"/>.</param>
 /// <param name="articleCount">The estimated number of articles in the <see cref="NntpGroup"/>.</param>
 /// <param name="lowWaterMark">The reported low water mark of the <see cref="NntpGroup"/>.</param>
 /// <param name="highWaterMark">The reported high water mark of the <see cref="NntpGroup"/>.</param>
 /// <param name="postingStatus">The current <see cref="NntpPostingStatus"/> of the <see cref="NntpGroup"/>.</param>
 /// <param name="otherGroup">The name of the other <see cref="NntpGroup"/> under which the articles are filed when the
 /// <see cref="PostingStatus"/> is <see cref="NntpPostingStatus.OnlyArticlesFromPeersPermittedFiledLocally"/>.</param>
 /// <param name="articleNumbers">A list of <see cref="NntpArticle"/> numbers in the <see cref="NntpGroup"/>.</param>
 public NntpGroup(
     string name,
     int articleCount,
     int lowWaterMark,
     int highWaterMark,
     NntpPostingStatus postingStatus,
     string otherGroup,
     IEnumerable <int> articleNumbers)
 {
     Name           = name ?? string.Empty;
     ArticleCount   = articleCount;
     LowWaterMark   = lowWaterMark;
     HighWaterMark  = highWaterMark;
     PostingStatus  = Enum.IsDefined(typeof(NntpPostingStatus), postingStatus) ? postingStatus : NntpPostingStatus.Unknown;
     OtherGroup     = otherGroup ?? string.Empty;
     ArticleNumbers = articleNumbers ?? new int[0];
 }
示例#5
0
        public void NntpGroupShouldBeSerializedAndDeserializedCorrectly(
            string name,
            int articleCount,
            int lowWaterMark,
            int highWaterMark,
            NntpPostingStatus postingStatus,
            string otherGroup,
            int[] articleNumbers)
        {
            var expected = new NntpGroup(
                name,
                articleCount,
                lowWaterMark,
                highWaterMark,
                postingStatus,
                otherGroup,
                articleNumbers);

            string json   = JsonConvert.SerializeObject(expected);
            var    actual = JsonConvert.DeserializeObject <NntpGroup>(json);

            Assert.Equal(expected, actual);
        }