Пример #1
0
        public void Build_RunWithMultiFunc_FuncWillExecute()
        {
            var item     = new MiddlewareItemStub();
            var build    = new MiddlewareBuilderStub();
            var exNumber = 5;
            var exStr    = "str";

            build.Use(async(someItem, next) =>
            {
                someItem.SomeValue = 5;
                await next.Invoke();
            });

            build.Use(async(someItem, next) =>
            {
                someItem.SomeStr = "str";
                await next.Invoke();
            });

            var func = build.Build();

            //Assert
            Assert.DoesNotThrow(() => { func(item); });
            Assert.AreEqual(exNumber, item.SomeValue);
            Assert.AreEqual(exStr, item.SomeStr);
        }
Пример #2
0
        public void Build_RunWithoutInput_NotThrow()
        {
            var item  = new MiddlewareItemStub();
            var build = new MiddlewareBuilderStub();
            var func  = build.Build();

            //Assert
            Assert.DoesNotThrow(() => { func(item); });
        }
Пример #3
0
        public void UseMiddleware_WithNoParameters_NotThrowsException()
        {
            var item    = new MiddlewareItemStub();
            var builder = new MiddlewareBuilderStub();

            //Assert
            Assert.DoesNotThrow(() =>
            {
                builder.UseMiddleware <MiddlewareNoArgumentsStub, MiddlewareItemStub>();
                builder.Build();
            });
        }
Пример #4
0
        public void UseMiddleware_WithWrongOrderArguments_ThrowsException()
        {
            var item    = new MiddlewareItemStub();
            var builder = new MiddlewareBuilderStub();

            object[] args = { 5 };

            Assert.Throws <InvalidOperationException>(() =>
            {
                builder.UseMiddleware <MiddlewareWithWrongOrderOfArgumentsStub, MiddlewareItemStub>(args);
                builder.Build();
            });
        }
Пример #5
0
        public void UseMiddleware_WithParameter_NotThrowsException()
        {
            var item    = new MiddlewareItemStub();
            var builder = new MiddlewareBuilderStub();

            object[] args = { 5 };
            //Assert
            Assert.DoesNotThrow(() =>
            {
                builder.UseMiddleware <MiddlewareWithArgumentsStub, MiddlewareItemStub>(args);
                builder.Build();
            });
        }
Пример #6
0
        public void Build_RunWithOneFunc_FuncWillExecute()
        {
            var item          = new MiddlewareItemStub();
            var build         = new MiddlewareBuilderStub();
            var expectedValue = 5;

            build.Use(async(someItem, next) =>
            {
                someItem.SomeValue = 5;
                await next.Invoke();
            });

            var func = build.Build();

            //Assert
            Assert.DoesNotThrow(() => { func(item); });
            Assert.AreEqual(expectedValue, item.SomeValue);
        }