/// <inheritdoc /> public ValidatedRegExExtractor(RegexClaimExtractionConfig.ExtractValueByRegexAsync func, Regex regex, string claim, ClaimLocation location) { _extract = func; _regex = regex; _claimName = claim; ClaimLocation = location; }
/// <inheritdoc /> internal ValidRegexClaimExtractionConfig(RegexClaimExtractionConfig.ExtractValueByRegexAsync func, Regex regex, string claim, ClaimLocation location) { _extract = func; _regex = regex; _claimName = claim; ClaimLocation = location; }
public void RegExExtraction_Theory(string regexString, string content, string extractionFunction) { const string claimName = "PityTheFoolClaim"; RegexClaimExtractionConfig.ExtractValueByRegexAsync extractionFunc = null; if (extractionFunction?.Equals(nameof(ExtractionFunctions.RegexFunc)) ?? false) { extractionFunc = ExtractionFunctions.RegexFunc; } var regex = new Regex(regexString); var config = new ValidRegexClaimExtractionConfig(extractionFunc, regex, claimName, ClaimLocation.Body); Assert.True(config.ClaimLocation.Equals(ClaimLocation.Body)); Assert.True(config.ExtractionType.Equals(ExtractionType.RegEx)); var result = config.GetClaimAsync(content).Result; switch (regexString) { case "/a/b/c/(.*)/e": { if (string.IsNullOrEmpty(content)) { if (content == null) { Assert.Equal(claimName, result.Type); Assert.Equal(string.Empty, result.Value); } else { Assert.Equal(claimName, result.Type); Assert.Equal(string.Empty, result.Value); } } else { Assert.Equal(claimName, result.Type); Assert.Equal("d", result.Value); } break; } case "/a/(.*)/c/d/e": { Assert.Equal(claimName, result.Type); Assert.Equal("b", result.Value); break; } case "": { Assert.Equal(claimName, result.Type); Assert.Equal(string.Empty, result.Value); break; } } }