Esempio n. 1
0
        /// <summary>
        ///   Specifies what unit should be built to fill <see cref="Maybe{T}" /> value.
        /// </summary>
        public static TreatingTuner <T> TreatMaybeValue <T>(this TreatingTuner <Maybe <T> > treatingTuner)
        {
            var treat       = treatingTuner.AsExtensibility <IUnitSequenceExtensibility>();
            var uniqueToken = Guid.NewGuid();

            treat.UnitSequenceMatcher.AddBuildAction(BuildStage.Create, new BuildMaybeAction <T>(uniqueToken));
            return(new TreatingTuner <T>(treat.UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(new WildcardUnitSequenceMatcher(Match.Type <T>(uniqueToken), 0))));
        }
Esempio n. 2
0
        /// <summary>
        /// Specifies what unit should be built to fill <see cref="Maybe{T}" /> value.
        /// </summary>
        public static TreatingTuner <T> TreatMaybeValue <T>(this TreatingTuner <Maybe <T> > treatingTuner)
        {
            var treat     = treatingTuner.GetInternals();
            var uniqueTag = Guid.NewGuid();

            treat.Member1.UseBuildAction(new BuildMaybeAction <T>(uniqueTag), BuildStage.Create);

            return(new TreatingTuner <T>(
                       treat.Member1.GetOrAddNode(new SkipTillUnit(new UnitPattern(typeof(T), uniqueTag), 0))));
        }
Esempio n. 3
0
    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)));
    }
Esempio n. 4
0
    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);
    }
Esempio n. 5
0
    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);
    }
Esempio n. 6
0
    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);
    }
Esempio n. 7
0
    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);
    }
Esempio n. 8
0
        /// <summary>
        ///   Specifies that value from built <see cref="Maybe{T}" /> should be used as a unit.
        /// </summary>
        public static TreatingTuner <Maybe <T> > AsMaybeValueOf <T>(this TreatingTuner <T> treatingTuner)
        {
            var treat = treatingTuner.AsExtensibility <IUnitSequenceExtensibility>();

            return(new TreatingTuner <Maybe <T> >(treat.UnitSequenceMatcher.AddBuildAction(BuildStage.Initialize, new GetMaybeValueBuildAction <T>())));
        }
Esempio n. 9
0
        /// <summary>
        /// Specifies that value from built <see cref="Maybe{T}" /> should be used as a unit.
        /// </summary>
        public static TreatingTuner <Maybe <T> > AsMaybeValueOf <T>(this TreatingTuner <T> treatingTuner)
        {
            var treat = treatingTuner.GetInternals();

            return(new TreatingTuner <Maybe <T> >(treat.Member1.UseBuildAction(new GetMaybeValueBuildAction <T>(), BuildStage.Initialize)));
        }