Exemplo n.º 1
0
		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 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");
		}
Exemplo n.º 3
0
        /// <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);
        }
		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");
		}
		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));
		}