/// <summary> /// Resolves a set of configurations matches from a caret-delimited query string value. /// Dependency order is considered in the returned order of configurations. /// </summary> public static IConfiguration[] ResolveConfigurationsFromQueryParameter(string queryParameter) { // parse query string value var configNames = (queryParameter ?? string.Empty) .Split('^') .Where(key => !string.IsNullOrWhiteSpace(key)) .ToList(); var allConfigurations = UnicornConfigurationManager.Configurations; // determine which configurations the query string resolves to IEnumerable <IConfiguration> selectedConfigurations; if (configNames.Count == 0) { // query string specified no configs. This means sync all. // but we still have to set in dependency order. selectedConfigurations = allConfigurations; } else { selectedConfigurations = configNames .Select(name => allConfigurations.FirstOrDefault(conf => conf.Name.Equals(name))) .Where(conf => conf != null); } // order the selected configurations in dependency order var resolver = new InterconfigurationDependencyResolver(); return(resolver.OrderByDependencies(selectedConfigurations)); }
/// <summary> /// Resolves a set of configurations matches from a caret-delimited query string value. /// Dependency order is considered in the returned order of configurations. /// </summary> public static IConfiguration[] ResolveConfigurationsFromQueryParameter(string queryParameter, string excludeParameter = null) { // parse query string value var configNames = (queryParameter ?? string.Empty) .Split('^') .Where(key => !string.IsNullOrWhiteSpace(key)) .ToList(); // parse exclude value var excludedConfigNames = (excludeParameter ?? string.Empty) .Split('^') .Where(key => !string.IsNullOrWhiteSpace(key)) .ToList(); var allConfigurations = UnicornConfigurationManager.Configurations; // determine which configurations the query string resolves to List <IConfiguration> selectedConfigurations = new List <IConfiguration>(); if (configNames.Count == 0) { // query string specified no configs. This means sync all. // but we still have to set in dependency order. selectedConfigurations = allConfigurations.ToList(); } else { // I can't LINQ like Kam can LINQ >.< ;-) // querystring specified configs, but each config name can be a wildcard pattern. We have to loop through // them all, and find any and all configs that match foreach (string configName in configNames) { var matchingConfigurations = allConfigurations.Where(c => WildcardMatch(c.Name, configName)); foreach (var matchingConfiguration in matchingConfigurations) { if (!selectedConfigurations.Contains(matchingConfiguration)) { selectedConfigurations.Add(matchingConfiguration); } } } } // process config excludes foreach (var exclude in excludedConfigNames) { selectedConfigurations.RemoveAll(c => WildcardMatch(c.Name, exclude)); } // order the selected configurations in dependency order var resolver = new InterconfigurationDependencyResolver(); return(resolver.OrderByDependencies(selectedConfigurations)); }
public void ShouldThrowWhenTransitiveRecursiveDependencyExists() { // expected order = items without deps first, followed by items with dependencies ordered in dependency order var configs = new[] { DepTestHelper.CreateTestConfiguration("A", "B"), DepTestHelper.CreateTestConfiguration("B", "C"), DepTestHelper.CreateTestConfiguration("C", "A") }; var sut = new InterconfigurationDependencyResolver(); DepTestHelper.GroomConfigs(configs); Assert.Throws <InvalidOperationException>(() => sut.OrderByDependencies(configs)); }
public void ShouldResolveWithDependencies() { var configs = new[] { DepTestHelper.CreateTestConfiguration("B", "A"), DepTestHelper.CreateTestConfiguration("A") }; var sut = new InterconfigurationDependencyResolver(); DepTestHelper.GroomConfigs(configs); var result = sut.OrderByDependencies(configs); result.Length.Should().Be(2); result[0].Name.Should().Be("A"); result[1].Name.Should().Be("B"); }
public static IConfiguration[] ResolveConfigurationsFromQueryParameter(string queryParameter) { var config = (queryParameter ?? string.Empty) .Split('^') .Where(key => !string.IsNullOrWhiteSpace(key)) .ToList(); var configurations = UnicornConfigurationManager.Configurations; if (config.Count == 0) { return(configurations); } var targetConfigurations = config.Select(name => configurations.FirstOrDefault(conf => conf.Name.Equals(name))) .Where(conf => conf != null) .ToArray(); var resolver = new InterconfigurationDependencyResolver(); return(resolver.OrderByDependencies(targetConfigurations)); }
public void ShouldPreserveInputOrderWithDependencies() { // expected order = items without deps first, followed by items with dependencies ordered in dependency order var configs = new[] { DepTestHelper.CreateTestConfiguration("A", "C"), DepTestHelper.CreateTestConfiguration("B", "A"), DepTestHelper.CreateTestConfiguration("C"), DepTestHelper.CreateTestConfiguration("D") }; var sut = new InterconfigurationDependencyResolver(); DepTestHelper.GroomConfigs(configs); var result = sut.OrderByDependencies(configs); result.Length.Should().Be(4); result[0].Name.Should().Be("C"); result[1].Name.Should().Be("D"); result[2].Name.Should().Be("A"); result[3].Name.Should().Be("B"); }