Exemple #1
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);
    }
Exemple #2
0
    public void using_arguments_should_add_registrations()
    {
        const string expectedString = "expected";
        const int    expectedInt    = 312;

        var tuner1 = A.Dummy <IArgumentTuner>();
        var tuner2 = A.Dummy <IArgumentTuner>();

        var expectedWeight = WeightOf.BuildChainPattern.IfFirstUnit + WeightOf.InjectionPoint.ByTypeAssignability;

        var expectedChildNode =
            new SkipWhileUnit(Static.Of <IsServiceUnit>())
        {
            Children =
            {
                new IfFirstUnit(new IsAssignableFromType(expectedString.GetType()), expectedWeight)
                .UseBuildAction(new Instance <object>(expectedString),              BuildStage.Cache),
                new IfFirstUnit(new IsAssignableFromType(expectedInt.GetType()),    expectedWeight)
                .UseBuildAction(new Instance <object>(expectedInt),                 BuildStage.Cache)
            }
        };

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

        // --act
        target.UsingArguments(tuner1, expectedString, expectedInt, tuner2);

        // --assert
        A.CallTo(() => tuner1.Tune(actual, 0)).MustHaveHappenedOnceAndOnly().Then(
            A.CallTo(() => tuner2.Tune(actual, 0)).MustHaveHappenedOnceAndOnly());

        actual.Children.Single().Should().BeEquivalentTo(expectedChildNode);
    }
    public void AsT([Values(null, "tag")] string tag)
    {
        // --arrange
        var actual = new Util.TestBuildChainPattern();
        var target = new TreatingTuner <IDisposable>(actual);

        // --act
        target.As <Stream>(tag);

        // --assert
        actual.BuildActions.Should().BeEquivalentTo(Util.CreateBag(BuildStage.Create, new RedirectType(typeof(Stream), tag)));
    }
    public void AsIs([Values(null, "tag")] string tag)
    {
        var expectedBuildActions = Util.CreateBag(BuildStage.Create, Default.CreationBuildAction);

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

        // --act
        target.AsIs();

        // // --assert
        actual.BuildActions.Should().BeEquivalentTo(expectedBuildActions);
    }
Exemple #5
0
    public void AsSingleton()
    {
        var expectedBuildActions = Util.CreateBag(BuildStage.Cache, new Singleton());

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

        // --act
        target.AsSingleton();

        // // --assert
        actual.BuildActions.Should().BeEquivalentTo(expectedBuildActions);
    }
    public void AsInstance([Values(null, "tag")] string tag)
    {
        var expectedInstance     = new MemoryStream();
        var expectedBuildActions = Util.CreateBag(BuildStage.Cache, new Instance <IDisposable>(expectedInstance));

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

        // --act
        target.AsInstance(expectedInstance);

        // // --assert
        actual.BuildActions.Should().BeEquivalentTo(expectedBuildActions);
    }
    public void AsCreatedWith([Values(null, "tag")] string tag)
    {
        // ReSharper disable once ConvertToLocalFunction
        Func <IBuildSession, IDisposable> factoryMethod = _ => new MemoryStream();
        var expectedBuildActions = Util.CreateBag(BuildStage.Create, new CreateWithFactoryMethod <IDisposable>(factoryMethod));

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

        // --act
        target.AsCreatedWith(factoryMethod);

        // // --assert
        actual.BuildActions.Should().BeEquivalentTo(expectedBuildActions);
    }
    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);
    }
Exemple #9
0
    public void AsIs()
    {
        var expectedAction = Default.CreationBuildAction;

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

        // --act
        target.AsIs();

        // --assert
        actual.BuildActions.Should()
        .HaveCount(1)
        .And.ContainKey(BuildStage.Create)
        .And.Subject.Values.Single()
        .Should()
        .HaveCount(1)
        .And.Contain(expectedAction);
    }
Exemple #10
0
    public void As([Values(null, "tag")] object?tag)
    {
        var expectedType = typeof(List <>);
        var expected     = new RedirectOpenGenericType(expectedType, tag);

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

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

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