public void MatchingMechanismAndStrategyReturnsTrue() { string mechanism = $"{PassQualifier}{IncludeMechanism}:{Domain}"; Include include = new Include(mechanism, Qualifier.Pass, new DomainSpec(Domain)); FakeItEasy.A.CallTo(() => _mechanismParserStrategy.Parse(mechanism, Qualifier.Pass, Domain)).Returns(include); Term term; bool success = _parser.TryParse(mechanism, out term); Assert.That(success, Is.True); Assert.That(term, Is.SameAs(include)); FakeItEasy.A.CallTo(() => _qualifierParser.Parse(PassQualifier)).MustHaveHappened(Repeated.Exactly.Once); FakeItEasy.A.CallTo(() => _mechanismParserStrategy.Parse(mechanism, Qualifier.Pass, Domain)).MustHaveHappened(Repeated.Exactly.Once); }
public bool TryParse(string mechanism, out Term term) { Match match = _mechanismRegex.Match(mechanism); if (match.Success) { string qualifierToken = match.Groups["qualifier"].Value; string mechanismToken = match.Groups["mechanism"].Value.ToLower(); string argumentToken = match.Groups["argument"].Value; Qualifier qualifier = _qualifierParser.Parse(qualifierToken); if (!_parserStrategies.TryGetValue(mechanismToken, out IMechanismParserStrategy strategy)) { throw new ArgumentException($"No strategy found to process {mechanismToken}"); } term = strategy.Parse(mechanism, qualifier, argumentToken); if (qualifier == Qualifier.Unknown) { string message = string.Format(SpfParserResource.UnknownQualifierErrorMessage, qualifierToken); string markdown = string.Format(SpfParserMarkdownResource.UnknownQualifierErrorMessage, qualifierToken); term.AddError(new Error(Id, ErrorType.Error, message, markdown)); } return(true); } term = null; return(false); }
public bool TryParse(string mechanism, out Term term) { Match match = _mechanismRegex.Match(mechanism); if (match.Success) { string qualifierToken = match.Groups["qualifier"].Value; string mechanismToken = match.Groups["mechanism"].Value.ToLower(); string argumentToken = match.Groups["argument"].Value; Qualifier qualifier = _qualifierParser.Parse(qualifierToken); IMechanismParserStrategy strategy; if (!_parserStategies.TryGetValue(mechanismToken, out strategy)) { throw new ArgumentException($"No strategy found to process {mechanismToken}"); } term = strategy.Parse(mechanism, qualifier, argumentToken); return(true); } term = null; return(false); }