Esempio n. 1
0
        public void Sort_WithDependencies_CanSort()
        {
            var list = new List <TestSortableTask>()
            {
                new FirstTask()
                {
                    RunAfter = new Type[] { typeof(SecondTask), typeof(FithTask) }
                },
                new SecondTask()
                {
                    RunBefore = new Type[] { typeof(SixthTask) }
                },
                new ThirdTask()
                {
                    RunAfter = new Type[] { typeof(FirstTask) }
                },
                new FourthTask(),
                new FithTask(),
                new SixthTask()
            };

            var result = OrderableTaskSorter.Sort(list);

            var stringResult = string.Join(',', result.Select(r => r.GetType().Name));
            var expected     = string.Join(',', nameof(SecondTask), nameof(FithTask), nameof(FirstTask), nameof(FourthTask), nameof(SixthTask), nameof(ThirdTask));

            Assert.Equal(expected, stringResult);
        }
Esempio n. 2
0
        public void Sort_WithOrdering_CanSort()
        {
            var list = new List <TestSortableTask>()
            {
                new FirstTask()
                {
                    Ordering = 6
                },
                new SecondTask()
                {
                    Ordering = 5
                },
                new ThirdTask()
                {
                    Ordering = -3
                },
                new FourthTask()
                {
                    Ordering = -8
                },
                new FithTask(),
                new SixthTask()
            };

            var result = OrderableTaskSorter.Sort(list);

            var stringResult = string.Join(',', result.Select(r => r.GetType().Name));
            var expected     = string.Join(',', nameof(FourthTask), nameof(ThirdTask), nameof(FithTask), nameof(SixthTask), nameof(SecondTask), nameof(FirstTask));

            Assert.Equal(expected, stringResult);
        }
Esempio n. 3
0
        public void Sort_NullSource_ThrowsException()
        {
            string[] collection = null;

            Assert.Throws <ArgumentNullException>(() =>
            {
                OrderableTaskSorter.Sort(collection);
            });
        }
Esempio n. 4
0
 private static ICollection <IStartupConfigurationTask> SortTasksByDependency(IEnumerable <IStartupConfigurationTask> startupTasks)
 {
     try
     {
         // Do a Topological Sort based on task dependencies
         return(OrderableTaskSorter.Sort(startupTasks));
     }
     catch (CyclicDependencyException ex)
     {
         throw new CyclicDependencyException("A cyclic dependency has been detected between multiple IStartupConfigurationTask classes. Check your startup tasks to ensure they do not depend on each other. For more details see the inner exception message.", ex);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Orders and runs RegisterRoutes() on all instances of IRouteRegistration
        /// registered in the dependency container.
        /// </summary>
        /// <param name="routeBuilder">
        /// The MVC routeBuilder to add routes to.
        /// </param>
        public void Initialize(IEndpointRouteBuilder routeBuilder)
        {
            ICollection <IRouteRegistration> sortedRoutes;

            try
            {
                // Then do a Topological Sort based on dependencies
                sortedRoutes = OrderableTaskSorter.Sort(_routeRegistrations);
            }
            catch (CyclicDependencyException ex)
            {
                throw new CyclicDependencyException($"A cyclic dependency has been detected between multiple {nameof(IRouteRegistration)} classes. Check your route registrations to ensure they do not depend on each other. For more details see the inner exception message.", ex);
            }

            foreach (var routeRegistration in sortedRoutes)
            {
                routeRegistration.RegisterRoutes(routeBuilder);
            }
        }