Пример #1
0
        public async Task Execute_RunSamePipelineTwice_SuccessfullyExecute()
        {
            var pipeline = new AsyncPipeline <PersonModel>(new ActivatorMiddlewareResolver())
                           .Add <PersonWithEvenId>()
                           .Add <PersonWithOddId>()
                           .Add <PersonWithEmailName>()
                           .Add <PersonWithGenderProperty>();

            // This person model has a name that matches the 'PersonWithEmailName' middleware.
            var personModel = new PersonModel
            {
                Name = "*****@*****.**"
            };

            await pipeline.Execute(personModel);

            // Check if the level of 'personModel' is 3, which is configured by 'PersonWithEmailName' middleware.
            Assert.AreEqual(3, personModel.Level);


            // Creates a new instance with a 'Gender' property. The 'PersonWithGenderProperty'
            // middleware should be the last one to be executed.
            personModel = new PersonModel
            {
                Name   = "*****@*****.**",
                Gender = Gender.Other
            };

            pipeline.Execute(personModel);

            // Check if the level of 'personModel' is 4, which is configured by 'PersonWithGenderProperty' middleware.
            Assert.AreEqual(4, personModel.Level);
        }
Пример #2
0
        public async Task Execute_RunSeveralMiddleware_SuccessfullyExecute()
        {
            var pipeline = new AsyncPipeline <PersonModel>(new ActivatorMiddlewareResolver())
                           .Add <PersonWithEvenId>()
                           .Add <PersonWithOddId>()
                           .Add <PersonWithEmailName>()
                           .Add <PersonWithGenderProperty>();

            // This person model has a name that matches the 'PersonWithEmailName' middleware.
            var personModel = new PersonModel
            {
                Name = "*****@*****.**"
            };

            await pipeline.Execute(personModel);

            // Check if the level of 'personModel' is 3, which is configured by 'PersonWithEmailName' middleware.
            Assert.AreEqual(3, personModel.Level);
        }
Пример #3
0
        public async Task Execute_RunSeveralMiddlewareWithTwoBeingDynamiccalyAdded_SuccessfullyExecute()
        {
            var pipeline = new AsyncPipeline <PersonModel>(new ActivatorMiddlewareResolver())
                           .Add <PersonWithEvenId>()
                           .Add(typeof(PersonWithOddId))
                           .Add <PersonWithEmailName>()
                           .Add(typeof(PersonWithGenderProperty));

            // This person model has a gender, so the last middleware will be the one handling the input.
            var personModel = new PersonModel
            {
                Gender = Gender.Female
            };

            await pipeline.Execute(personModel);

            // Check if the level of 'personModel' is 4, which is configured by 'PersonWithGenderProperty' middleware.
            Assert.AreEqual(4, personModel.Level);
        }