Ejemplo n.º 1
0
        private static SeedingPlan GetSeedingPlanFor(SeedAssembly seedAssembly, ISeedingSetup seedingSetup)
        {
            Assert(seedAssembly != null);

            var seedInfoTree = SeedInfoTree.Create(seedAssembly.SeedTypes);

            var seedingSteps = new List <SeedInfo>();

            foreach (var seedInfo in seedInfoTree.AllSeeds)
            {
                RecursivelyBuildSeedingSteps(seedInfo);
            }

            return(new SeedingPlan(seedingSetup, seedAssembly.SeedingSetupType, seedingSteps));

            void RecursivelyBuildSeedingSteps(SeedInfo seedInfo)
            {
                if (seedingSteps.Contains(seedInfo))
                {
                    return;
                }

                foreach (var dependency in seedInfo.DependsOn)
                {
                    RecursivelyBuildSeedingSteps(dependency);
                }

                seedingSteps.Add(seedInfo);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the <see cref="SeedInfoTree"/> that describes the seed build upon the <paramref name="seedTypes"/>.
        /// </summary>
        internal static SeedInfoTree Create(IEnumerable <Type> seedTypes)
        {
            Assert(seedTypes != null);
            Assert(seedTypes.All(type => type.IsSeedType()));

            SeedInfoTree result = new SeedInfoTree();

            foreach (var seedType in seedTypes)
            {
                result.GetOrCreateSeedInfoFor(seedType);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public SeedInfoTree GetSeedInfoTree(Assembly assembly, IEnumerable <string> seedFilters)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(GetSeedInfoTreeImpl());

            SeedInfoTree GetSeedInfoTreeImpl()
            {
                var seedAssembly = SeedAssembly.Create(assembly, seedFilters);

                return(SeedInfoTree.Create(seedAssembly.SeedTypes));
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <SeedInfo> GetSeedsFor(Assembly assembly, IEnumerable <string> seedFilters)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(GetSeedInfosImpl());

            IEnumerable <SeedInfo> GetSeedInfosImpl()
            {
                var seedAssembly = SeedAssembly.Create(assembly, seedFilters);

                return(SeedInfoTree.Create(seedAssembly.SeedTypes)
                       .AllSeeds
                       .Where(seedInfo => seedAssembly.SeedTypes.Contains(seedInfo.SeedType)));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SeedInfo"/> that describes the seed
        /// represented by the <paramref name="seedType"/>.
        /// </summary>
        internal static SeedInfo CreateFor(Type seedType, SeedInfoTree seedInfoTree)
        {
            Debug.Assert(seedType != null);
            Debug.Assert(seedType.IsSeedType());
            Debug.Assert(seedInfoTree != null);

            var seedOutputProperties = GetSeedOutputProperty();

            // TODO: Check that we do not have any circular dependencies.
            // TODO: Check all other things as well :-)

            return(new SeedInfo(seedType, seedOutputProperties, GetExplicitDependencies().Concat(GetImplicitDependencies()).ToList()));

            PropertyInfo[] GetSeedOutputProperty()
            {
                return(seedType
                       .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                       .Where(property => property.IsSeedOutputProperty())
                       .ToArray());
            }

            IEnumerable <SeedInfo> GetImplicitDependencies()
            {
                return(seedOutputProperties
                       .Select(property => seedInfoTree.GetOrCreateSeedInfoFor(property.PropertyType.DeclaringType)));
            }

            IEnumerable <SeedInfo> GetExplicitDependencies()
            {
                // TODO: Add checks: SeedType != null. SeedType.IsSeedType().

                return(seedType
                       .GetCustomAttributes(typeof(RequiresAttribute), false)
                       .Cast <RequiresAttribute>()
                       .Select(attribute => attribute.SeedOrScenarioType)
                       .Select(seedInfoTree.GetOrCreateSeedInfoFor));
            }
        }