Beispiel #1
0
        public void should_return_children_merged_actions()
        {
            // --arrange
            var unitIdMatcher = Match.Type <int>(null);
            var buildStep1    = new IfFirstUnit(unitIdMatcher);

            buildStep1.UseBuildAction(Static.Of <CreateByReflection>(), BuildStage.Cache);

            var singletonAction = new Singleton();
            var buildStep2      = new SkipTillUnit(unitIdMatcher);

            buildStep2.UseBuildAction(singletonAction, BuildStage.Cache);

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

            target.GetOrAddNode(buildStep1);
            target.GetOrAddNode(buildStep2);

            // --act
            var actual = target.GatherBuildActions(new[] { Unit.IsType <string>(), Unit.IsType <int>() }.ToBuildChain(), out var actionBag, 0);

            // --assert
            actual.Should().BeTrue();
            actionBag.Should().NotBeNull();

            actionBag ![BuildStage.Cache]
Beispiel #2
0
    public void should_match_first_unit_and_send_the_rest_to_children()
    {
        const string kind = "kind";

        var expected = new UnitId("expected", "expected");

        // --arrange
        var target = new IfFirstUnit(new UnitPattern(kind));
        var child1 = A.Fake <IBuildChainPattern>();
        var child2 = A.Fake <IBuildChainPattern>();

        target.AddNode(child1);
        target.AddNode(child2);

        // --act
        var chain = new[] { new UnitId(kind, null), expected }.ToArrayTail();

        target.GatherBuildActions(chain, out var actionBag, 0);

        // --assert
        A.CallTo(() => child1.GatherBuildActions(An <BuildChain> .That.IsEqualTo(expected.ToArrayTail(), Comparer.OfArrayTail <UnitId>()), out actionBag, An <int> ._))
        .MustHaveHappenedOnceAndOnly();

        A.CallTo(() => child2.GatherBuildActions(An <BuildChain> .That.IsEqualTo(expected.ToArrayTail(), Comparer.OfArrayTail <UnitId>()), out actionBag, An <int> ._))
        .MustHaveHappenedOnceAndOnly();
    }
Beispiel #3
0
    public void AsCreated([Values(null, "tag")] object?tag)
    {
        var expectedType   = typeof(List <>);
        var expectedAction = new RedirectOpenGenericType(expectedType, tag);
        var expectedChild  = new IfFirstUnit(new IsGenericOfDefinition(expectedType, tag))
                             .UseBuildAction(Default.CreationBuildAction, BuildStage.Create);

        // --arrange
        var actual = new Util.TestBuildChainPattern();
        var target = new TreatingOpenGenericTuner(actual);

        // --act
        target.AsCreated(expectedType, tag);

        // --assert
        actual.BuildActions.Should()
        .HaveCount(1)
        .And.ContainKey(BuildStage.Create)
        .And.Subject.Values.Single()
        .Should()
        .HaveCount(1)
        .And.Contain(expectedAction);

        actual.Children.Single().Should().BeEquivalentTo(expectedChild);
    }
Beispiel #4
0
    public void should_tune_getting_constructor_without_parameters()
    {
        var expected = new IfFirstUnit(Static.Of <IsConstructor>()).UseBuildAction(new GetConstructorByParameterTypes(), BuildStage.Create);
        // --arrange
        var target = Constructor.Parameterless();
        var root   = new BuildChainPatternTree();

        // --act
        target.Tune(root);

        // --assert
        root.Children.Single().Should().BeEquivalentTo(expected);
    }
Beispiel #5
0
    public void should_tune_getting_constructor_marked_with_inject_attribute([Values(null, "id")] object?id)
    {
        var expected = new IfFirstUnit(Static.Of <IsConstructor>()).UseBuildAction(new GetConstructorByInjectPointId(id), BuildStage.Create);

        // --arrange
        var target = Constructor.MarkedWithInjectAttribute(id);
        var root   = new BuildChainPatternTree();

        // --act
        target.Tune(root);

        // --assert
        root.Children.Single().Should().BeEquivalentTo(expected);
    }
    public void should_add_reflection_creation_strategy([Values(null, "tag")] object?tag)
    {
        var expectedType = typeof(IDisposable);
        var expected     = new IfFirstUnit(new UnitPattern(expectedType, tag)).UseBuildAction(new CreateByReflection(), BuildStage.Create);

        // --arrange
        var actual = new BuildChainPatternTree();
        var target = new CreationTuner(actual, expectedType, tag);

        // --act
        target.CreatedByReflection();

        // --assert
        actual.Children.Single().Should().BeEquivalentTo(expected);
    }
Beispiel #7
0
    public void should_add_default_creation_strategy([Values(null, "tag")] object?tag)
    {
        var expectedType = typeof(IList <>);
        var expected     = new IfFirstUnit(new IsGenericOfDefinition(expectedType, tag)).UseBuildAction(Default.CreationBuildAction, BuildStage.Create);

        // --arrange
        var actual = new BuildChainPatternTree();
        var target = new OpenGenericCreationTuner(actual, expectedType, tag);

        // --act
        target.CreatedByDefault();

        // --assert
        actual.Children.Single().Should().BeEquivalentTo(expected);
    }
    public void AsCreatedT([Values(null, "tag")] string tag)
    {
        var expectedBuildActions = Util.CreateBag(BuildStage.Create, new RedirectType(typeof(MemoryStream), tag));
        var expectedChildNode    = new IfFirstUnit(new UnitPattern(typeof(MemoryStream), tag))
                                   .UseBuildAction(Default.CreationBuildAction, BuildStage.Create);

        // --arrange
        var actual = new Util.TestBuildChainPattern();
        var target = new TreatingTuner <IDisposable>(actual);

        // --act
        target.AsCreated <MemoryStream>(tag);

        // // --assert
        actual.BuildActions.Should().BeEquivalentTo(expectedBuildActions);
        actual.Children.Single().Should().BeEquivalentTo(expectedChildNode);
    }
        public void should_return_all_merged_actions()
        {
            var singletonAction = new Singleton();

            // --arrange
            var unitIdMatcher = Match.Type <string>(null);
            var matchString   = new IfFirstUnit(unitIdMatcher).UseBuildAction(new CreateByReflection(), BuildStage.Cache);
            var matchAny      = new SkipTillUnit(unitIdMatcher).UseBuildAction(singletonAction, BuildStage.Cache);

            var target = new BuildChainPatternTree();

            target.Children.Add(matchString);
            target.Children.Add(matchAny);

            // --act
            var actual = target.GatherBuildActions(new[] { Unit.IsType <string>() }.ToArrayTail(), out var actionBag);

            // --assert
            actual.Should().BeTrue();
            actionBag ![BuildStage.Cache]
Beispiel #10
0
    public void should_not_call_children_if_not_match_first_unit()
    {
        const string kind = "kind";

        var expected = new UnitId("expected", "expected");

        // --arrange
        var target = new IfFirstUnit(new UnitPattern(kind));
        var child1 = A.Fake <IBuildChainPattern>();
        var child2 = A.Fake <IBuildChainPattern>();

        target.AddNode(child1);
        target.AddNode(child2);

        // --act
        var chain = new[] { new UnitId("bad", null), new UnitId(kind, null), expected }.ToArrayTail();

        target.GatherBuildActions(chain, out var actionBag, 0);

        // --assert
        A.CallTo(() => child1.GatherBuildActions(default, out actionBag, default)).WithAnyArguments().MustNotHaveHappened();