public void CreateBindingData_IfNoMatch_ReturnsNull() { BindingTemplateSource template = BindingTemplateSource.FromString("input/{name}.-/"); var namedParams = template.CreateBindingData("input/foo.bar.-/txt"); Assert.Null(namedParams); }
public void CreateBindingData_IfExtensionSpecialScenario_ReturnsNamedParams() { BindingTemplateSource template = BindingTemplateSource.FromString("input/{name}.csv"); var namedParams = template.CreateBindingData("input/a.b.csv"); Assert.Equal("a.b", namedParams["name"]); }
public void CreateBindingData_IfExtensionLongest_WorksMultiCharacterSeparator() { BindingTemplateSource template = BindingTemplateSource.FromString("input/{name}.-/{extension}"); var namedParams = template.CreateBindingData("input/foo.-/bar.txt"); Assert.Equal("foo", namedParams["name"]); Assert.Equal("bar.txt", namedParams["extension"]); }
public void CreateBindingData_IfExtensionLongest_WorksMultiple() { BindingTemplateSource template = BindingTemplateSource.FromString("input/{name}.{extension}-/{other}"); var namedParams = template.CreateBindingData("input/foo.bar.txt-/asd-/ijij"); Assert.Equal("foo.bar", namedParams["name"]); Assert.Equal("txt-/asd", namedParams["extension"]); Assert.Equal("ijij", namedParams["other"]); }
public ParameterizedBlobPathSource(string containerNamePattern, string blobNamePattern, BindingTemplateSource template) { Debug.Assert(template != null, "template must not be null"); Debug.Assert(template.ParameterNames.Any(), "template must contain one or more parameters"); _containerNamePattern = containerNamePattern; _blobNamePattern = blobNamePattern; _template = template; }
public void BuildCapturePattern_IfValidTemplate_ReturnsValidRegexp() { string pattern = @"{p1}-p2/{{2014}}/{d3}/folder/{name}.{ext}"; var tokens = BindingTemplateParser.GetTokens(pattern).ToList(); string captureRegex = BindingTemplateSource.BuildCapturePattern(tokens); Assert.NotEmpty(captureRegex); Assert.Equal("^(?<p1>.*)-p2/\\{2014}/(?<d3>.*)/folder/(?<name>.*)\\.(?<ext>.*)$", captureRegex); Assert.NotNull(new Regex(captureRegex, RegexOptions.Compiled)); }
public void CreateBindingData_IfNameExtensionCombination_ReturnsNamedParams( string pattern, string actualPath, string expectedName) { BindingTemplateSource template = BindingTemplateSource.FromString(pattern); var namedParams = template.CreateBindingData(actualPath); Assert.NotNull(namedParams); Assert.Equal(expectedName, namedParams["name"]); Assert.Equal("txt", namedParams["extension"]); }
internal BindingDataProvider(string template, bool ignoreCase = false) { _bindingTemplateSource = BindingTemplateSource.FromString(template, ignoreCase); Dictionary <string, Type> contract = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase); foreach (string parameterName in _bindingTemplateSource.ParameterNames) { contract.Add(parameterName, typeof(string)); } _contract = contract; _type = typeof(string); }
public static IBlobPathSource Create(string pattern) { if (pattern == null) { throw new FormatException("Blob paths must not be null."); } string containerNamePattern; string blobNamePattern; int slashIndex = pattern.IndexOf('/'); bool hasBlobName = slashIndex != -1; if (hasBlobName) { // There must be at least one character before the slash and one character after the slash. bool hasNonEmptyBlobAndContainerNames = slashIndex > 0 && slashIndex < pattern.Length - 1; if (!hasNonEmptyBlobAndContainerNames) { throw new FormatException("Blob paths must be in the format container/blob."); } containerNamePattern = pattern.Substring(0, slashIndex); blobNamePattern = pattern.Substring(slashIndex + 1); } else { containerNamePattern = pattern; blobNamePattern = String.Empty; } BindingTemplateSource template = BindingTemplateSource.FromString(pattern); if (template.ParameterNames.Count() > 0) { return(new ParameterizedBlobPathSource(containerNamePattern, blobNamePattern, template)); } BlobClient.ValidateContainerName(containerNamePattern); if (hasBlobName) { BlobClient.ValidateBlobName(blobNamePattern); } return(new FixedBlobPathSource(new BlobPath(containerNamePattern, blobNamePattern))); }
public static IBlobPathSource Create(string pattern) { if (pattern == null) { throw new FormatException("Blob paths must not be null."); } int slashIndex = pattern.IndexOf('/'); bool hasBlobName = slashIndex != -1; string containerNamePattern = pattern; string blobNamePattern = String.Empty; if (hasBlobName) { containerNamePattern = pattern.Substring(0, slashIndex); blobNamePattern = pattern.Substring(slashIndex + 1); } // There must be at least one character before the slash and one character after the slash. bool hasNonEmptyBlobAndContainerNames = slashIndex > 0 && slashIndex < pattern.Length - 1; if ((hasBlobName && !hasNonEmptyBlobAndContainerNames) || containerNamePattern.Contains('\\')) { throw new FormatException($"Invalid blob trigger path '{pattern}'. Paths must be in the format 'container/blob'."); } else if (containerNamePattern.Contains('{')) { throw new FormatException($"Invalid blob trigger path '{pattern}'. Container paths cannot contain {{resolve}} tokens."); } BindingTemplateSource template = BindingTemplateSource.FromString(pattern); if (template.ParameterNames.Count() > 0) { return(new ParameterizedBlobPathSource(containerNamePattern, blobNamePattern, template)); } BlobClientExtensions.ValidateContainerName(containerNamePattern); if (hasBlobName) { BlobClientExtensions.ValidateBlobName(blobNamePattern); } return(new FixedBlobPathSource(new BlobPath(containerNamePattern, blobNamePattern))); }
/// <summary> /// Creates a new instance /// </summary> /// <param name="pattern">The binding template pattern.</param> /// <param name="builtInContract">The initial built in contract.</param> public BindingContract(string pattern, Dictionary <string, Type> builtInContract) { _bindingTemplateSource = BindingTemplateSource.FromString(pattern); _bindingDataContract = CreateBindingDataContract(builtInContract); }