public void should_return_children_merged_actions()
        {
            // --arrange
            var buildStep1 = new LastUnitSequenceMatcher(Match.Type <int>(null));

            buildStep1.AddBuildAction(BuildStage.Cache, CreateByReflectionBuildAction.Instance);
            var singletonAction = new SingletonBuildAction();
            var buildStep2      = new AnyUnitSequenceMatcher();

            buildStep2.AddBuildAction(BuildStage.Cache, singletonAction);

            var target = new WildcardUnitSequenceMatcher(Match.Type <string>(null));

            target.AddOrGetUnitSequenceMatcher(buildStep1);
            target.AddOrGetUnitSequenceMatcher(buildStep2);

            // --act
            var actual = target.GetBuildActions(new[] { Unit.OfType <string>(), Unit.OfType <int>() }.GetTail(0), 0);

            // --assert
            actual.Should().NotBeNull();
            // ReSharper disable once PossibleNullReferenceException
            actual[BuildStage.Cache]
            .Should()
            .HaveCount(2)
            .And
            .Subject.Select(_ => _.Entity)
            .Should()
            .BeEquivalentTo(CreateByReflectionBuildAction.Instance, singletonAction);
        }
Ejemplo n.º 2
0
        public Tuner CreatedByReflection()
        {
            var childMatcher = new WildcardUnitSequenceMatcher(Match.OpenGenericType(OpenGenericType, Token), UnitSequenceMatchingWeight.WildcardMatchingUnit - 1);

            UnitSequenceMatcher
            .AddOrGetUnitSequenceMatcher(childMatcher)
            .AddBuildAction(BuildStage.Create, CreateByReflectionBuildAction.Instance);

            return(new Tuner(childMatcher));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Used to make a build plan for <paramref name="unitInfo"/>
        ///   How it should be treated is specified by subsequence calls using returned object.
        /// </summary>
        public static TreatingTuner Treat([NotNull] this BuildPlansCollection buildPlans, [NotNull] UnitInfo unitInfo)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(new UnitInfoMatcher(unitInfo));

            return(new TreatingTuner(buildPlans.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Used to make a build plan for a unit only if it is building in a context of building <paramref name="type" /> with token <paramref name="token" />
        /// </summary>
        public SequenceTuner Building([NotNull] Type type, object token = null)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type(type, token));

            return(new SequenceTuner(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///   Used to make a build plan for Unit of type <typeparamref name="T" />.
        ///   How <typeparamref name="T" /> should be treated is specified by subsequence calls using returned object.
        /// </summary>
        public static TreatingTuner <T> Treat <T>([NotNull] this BuildPlansCollection buildPlans, object token = null)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type <T>(token));

            return(new TreatingTuner <T>(buildPlans.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///   Used to make a build plan for a unit only if it is building in a context of building <paramref name="type" />.
        /// </summary>
        public static SequenceTuner Building([NotNull] this BuildPlansCollection buildPlans, Type type, object token = null)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type(type, token));

            return(new SequenceTuner(buildPlans.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 7
0
        private static TreatingTuner Treat(BuildPlansCollection buildPlans, UnitInfo unitInfo)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var unitMatcher = new MockUnitMatcher(new UnitInfoMatcher(unitInfo));

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(unitMatcher);

            return(new TreatingTuner(buildPlans.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 8
0
        /// <summary>
        ///   Used to make a build plan for all inheritors of <typeparamref name="T" />.
        ///   How <typeparamref name="T" /> should be treated is specified by subsequence calls using returned object.
        /// </summary>
        public static TreatingTuner <T> TreatInheritorsOf <T>([NotNull] this BuildPlansCollection buildPlans, object token = null)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(
                new BaseTypeMatcher(new UnitInfo(typeof(T), token)),
                UnitSequenceMatchingWeight.WildcardMatchingBaseTypeUnit);

            return(new TreatingTuner <T>(buildPlans.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///   Used to make a build plan for whole class of open generic types.
        ///   How <paramref name="openGenericType" /> should be treated is specified by subsequence calls using returned object.
        /// </summary>
        public static TreatingOpenGenericTuner TreatOpenGeneric([NotNull] this BuildPlansCollection buildPlans, Type openGenericType, object token = null)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(
                Match.OpenGenericType(openGenericType, token),
                UnitSequenceMatchingWeight.WildcardMatchingOpenGenericUnit);

            return(new TreatingOpenGenericTuner(buildPlans.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 10
0
        /// <summary>
        ///   Used to override a build plan for <paramref name="type"/>
        ///   How it should be treated is specified by subsequence calls using returned object.
        /// </summary>
        public static TreatingTuner Override([NotNull] this BuildPlansCollection buildPlans, [NotNull] Type type, object token = null)
        {
            if (buildPlans == null)
            {
                throw new ArgumentNullException(nameof(buildPlans));
            }

            var newSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type(type, token));
            var oldSequenceMatcher = buildPlans.Children.Single(_ => _.Equals(newSequenceMatcher));

            buildPlans.Children.Remove(oldSequenceMatcher);

            return(new TreatingTuner(buildPlans.AddOrGetUnitSequenceMatcher(newSequenceMatcher)));
        }
        public void should_match_build_sequence_weak()
        {
            var expected = new SingletonBuildAction();

            // --arrange
            var target = new WildcardUnitSequenceMatcher(Match.Type <IDisposable>(null))
                         .AddOrGetUnitSequenceMatcher(new WildcardUnitSequenceMatcher(Match.Type <MemoryStream>(null)))
                         .AddBuildAction(BuildStage.Cache, expected);

            // --act
            var actual = target
                         .GetBuildActions(new[] { Unit.OfType <IDisposable>(), Unit.OfType <string>(), Unit.OfType <MemoryStream>() }.GetTail(0), 0)
                         .GetTopmostAction(BuildStage.Cache);

            // --assert
            actual.Should().BeSameAs(expected);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///   Used to make a build plan for <typeparamref name="T" />.
        ///   How <typeparamref name="T" /> should be treated is specified by subsequence calls using returned object
        /// </summary>
        public TreatingTuner <T> Treat <T>(object token = null)
        {
            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type <T>(token));

            return(new TreatingTuner <T>(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }
Ejemplo n.º 13
0
        /// <summary>
        ///   Used to make a build plan for Unit of type <paramref name="type"/>.
        ///   How it should be treated is specified by subsequence calls using returned object.
        /// </summary>
        public TreatingTuner Treat([NotNull] Type type, object token = null)
        {
            var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type(type, token));

            return(new TreatingTuner(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher)));
        }