Ejemplo n.º 1
0
        public UriTag Parse(string uriString)
        {
            string[] tokens = uriString?.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries).Select(_ => _.Trim()).ToArray() ?? new string[0];

            DmarcUri dmarcUri = _dmarcUriParser.Parse(tokens.ElementAtOrDefault(0));

            MaxReportSize maxReportSize = tokens.Length > 1
                ? _maxReportSizeParser.Parse(tokens[1])
                : null;

            UriTag uriTag = new UriTag(uriString, dmarcUri, maxReportSize);

            if (tokens.Length > 2)
            {
                string unexpectedValues             = string.Join(",", tokens.Skip(2));
                string unexpectedValuesErrorMessage = string.Format(DmarcParserResource.UnexpectedValueErrorMessage, unexpectedValues, "uri", unexpectedValues);
                uriTag.AddError(new Error(ErrorType.Error, unexpectedValuesErrorMessage));
            }

            return(uriTag);
        }
        public void UriAndMaxReportSizeTokensPresentFullyFormedUriTagReturned()
        {
            string value = $"{UriString}!{SizeString}";

            DmarcUri dmarcUri = new DmarcUri(new Uri(UriString));

            A.CallTo(() => _dmarcUriParser.Parse(UriString)).Returns(dmarcUri);

            MaxReportSize maxReportSize = new MaxReportSize(50, Unit.M);

            A.CallTo(() => _maxReportSizeParser.Parse(SizeString)).Returns(maxReportSize);

            UriTag uriTag = _parser.Parse(value);

            Assert.That(uriTag.Uri, Is.SameAs(dmarcUri));
            Assert.That(uriTag.MaxReportSize, Is.SameAs(maxReportSize));
            Assert.That(uriTag.ErrorCount, Is.Zero);

            A.CallTo(() => _dmarcUriParser.Parse(UriString)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => _maxReportSizeParser.Parse(SizeString)).MustHaveHappened(Repeated.Exactly.Once);
        }