Ejemplo n.º 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);
    }
Ejemplo n.º 2
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);
    }
    public void should_propagate_unit_tag([Values(null, "tag")] string tag)
    {
        var expected = new List <int>();

        // --arrange
        var buildSession = A.Fake <IBuildSession>();

        A.CallTo(() => buildSession.BuildChain).Returns(Unit.IsType <IEnumerable <int> >().Tag(tag).ToBuildChain());
        var buildUnitCall = A.CallTo(() => buildSession.BuildUnit(Unit.IsType <List <int> >().Tag(tag)));

        buildUnitCall.Returns(expected.ToBuildResult());

        var target = new RedirectOpenGenericType(typeof(List <>), SpecialTag.Propagate);

        // --act
        target.Process(buildSession);

        // --assert
        buildSession.BuildResult.Value.Should().Be(expected);
        buildUnitCall.MustHaveHappenedOnceAndOnly();
    }
    public void should_not_throw_exception_if_unit_is_not_generic_if_throw_on_error_is_not_set()
    {
        var expected = new List <int>();

        // --arrange
        var buildSession = A.Fake <IBuildSession>();

        A.CallTo(() => buildSession.BuildChain).Returns(Unit.IsType <string>().ToBuildChain());
        var buildUnitCall = A.CallTo(() => buildSession.BuildUnit(Unit.IsType <List <int> >()));

        buildUnitCall.Returns(expected.ToBuildResult());

        var target = new RedirectOpenGenericType(typeof(List <>), null, false);

        // --act
        var actual = () => target.Process(buildSession);

        // --assert
        actual.Should().NotThrow();
        buildUnitCall.MustNotHaveHappened();
        buildSession.BuildResult.HasValue.Should().BeFalse();
    }
    public void should_throw_exception_if_unit_is_not_generic()
    {
        var expected = new List <int>();

        // --arrange
        var buildSession = A.Fake <IBuildSession>();

        A.CallTo(() => buildSession.BuildChain).Returns(Unit.IsType <string>().ToBuildChain());
        var buildUnitCall = A.CallTo(() => buildSession.BuildUnit(Unit.IsType <List <int> >()));

        buildUnitCall.Returns(expected.ToBuildResult());

        var target = new RedirectOpenGenericType(typeof(List <>), null);

        // --act
        var actual = () => target.Process(buildSession);

        // --assert
        var reg = new Regex("Building unit .* is not a generic type and can't be redirected.");

        actual.Should().ThrowExactly <ArmatureException>().Where(_ => reg.IsMatch(_.Message));
    }
    public void should_throw_exception_generic_arguments_count_dont_match()
    {
        var expected = new List <int>();

        // --arrange
        var buildSession = A.Fake <IBuildSession>();

        A.CallTo(() => buildSession.BuildChain).Returns(Unit.IsType <Dictionary <int, int> >().ToBuildChain());
        var buildUnitCall = A.CallTo(() => buildSession.BuildUnit(Unit.IsType <List <int> >()));

        buildUnitCall.Returns(expected.ToBuildResult());

        var target = new RedirectOpenGenericType(typeof(List <>), null);

        // --act
        var actual = () => target.Process(buildSession);

        // --assert
        var reg = new Regex("Generic arguments count of building unit .* and the type to redirect .* should be equal.");

        actual.Should().ThrowExactly <ArmatureException>().Where(_ => reg.IsMatch(_.Message));
    }