public void ConversionShouldBeCalledBetweenDifferentSignatures()
        {
            object theDefault = "42";

            Func<string, int> convert1 = app => int.Parse(app, CultureInfo.InvariantCulture) + 1;
            Func<int, string> convert2 = app => app.ToString(CultureInfo.InvariantCulture) + "2";

            Func<string, string> middleware1 = app => app + "3";
            Func<int, int> middleware2 = app => app + 4;

            var builder = new AppBuilder();
            builder.AddSignatureConversion(convert1);
            builder.AddSignatureConversion(convert2);
            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew<int>(x => x.Use(middleware1).Use(middleware2));

            // "42" + 1: 43         // theDefault passed through convert1 for next middleware
            // 43 + 4: 47           // passed through middleware2
            // 47 + "2": "472"      // passed through convert2 for next middleware
            // "472" + "3": "4723"  // passed through middleware1
            // "4723" + 1: 4724     // passed through convert1 to return

            theApp.ShouldBe(4724);
        }
Beispiel #2
0
        public void ConversionShouldBeCalledBetweenDifferentSignatures()
        {
            object theDefault = "42";

            Func <string, int> convert1 = app => int.Parse(app, CultureInfo.InvariantCulture) + 1;
            Func <int, string> convert2 = app => app.ToString(CultureInfo.InvariantCulture) + "2";

            Func <string, string> middleware1 = app => app + "3";
            Func <int, int>       middleware2 = app => app + 4;

            var builder = new AppBuilder();

            builder.AddSignatureConversion(convert1);
            builder.AddSignatureConversion(convert2);
            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew <int>(x => x.Use(middleware1).Use(middleware2));

            // "42" + 1: 43         // theDefault passed through convert1 for next middleware
            // 43 + 4: 47           // passed through middleware2
            // 47 + "2": "472"      // passed through convert2 for next middleware
            // "472" + "3": "4723"  // passed through middleware1
            // "4723" + 1: 4724     // passed through convert1 to return

            theApp.ShouldBe(4724);
        }
Beispiel #3
0
        public void InstanceMemberNamedInvokeShouldQualifyAsAppWithRun()
        {
            var theSite = new MySite();

            var builder = new AppBuilder();

            var theApp = builder.BuildNew <Func <int, string> >(x => x.Run(theSite));

            theApp(42).ShouldBe("Called[42]");
        }
Beispiel #4
0
        public void DelegateShouldQualifyAsAppWithRun()
        {
            Func <int, string> theDefault = call => "Hello[" + call + "]";
            Func <int, string> theSite    = call => "Called[" + call + "]";

            var builder = new AppBuilder();

            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew <Func <int, string> >(x => x.Run(theSite));

            theApp(42).ShouldBe("Called[42]");
        }
Beispiel #5
0
        public void OtherObjectShouldThrow()
        {
            Func <int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();

            builder.Properties["builder.DefaultApp"] = theDefault;

            Should.Throw <NotSupportedException>(() =>
            {
                var theApp = builder.BuildNew <Func <int, string> >(
                    x => x.Use(new object()));
            });
        }
Beispiel #6
0
        public void TypeofClassConstructorsWithWrongParameterCountShouldThrow()
        {
            Func <int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();

            builder.Properties["builder.DefaultApp"] = theDefault;

            Should.Throw <MissingMethodException>(() =>
            {
                var theApp = builder.BuildNew <Func <int, string> >(
                    x => x.Use(typeof(StringPlusValue2), "arg 1", "extra arg"));
            });
        }
        public void InstanceMemberNamedInvokeShouldQualifyAsMiddlewareFactory()
        {
            Func<int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();
            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew<Func<int, string>>(
                x => x
                    .Use(new StringPlusValue(" world!"))
                    .Use(new StringPlusValue(" there,")));

            theApp(42).ShouldBe("Hello[42] there, world!");
        }
Beispiel #8
0
        public void InstanceMemberNamedInvokeShouldQualifyAsMiddlewareFactory()
        {
            Func <int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();

            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew <Func <int, string> >(
                x => x
                .Use(new StringPlusValue(" world!"))
                .Use(new StringPlusValue(" there,")));

            theApp(42).ShouldBe("Hello[42] there, world!");
        }
Beispiel #9
0
        public void TypeofClassConstructorsShouldQualifyAsMiddlewareFactory()
        {
            Func <int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();

            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew <Func <int, string> >(
                x => x
                .Use(typeof(StringPlusValue2), " world!")
                .Use(typeof(StringPlusValue2), " there,"));

            theApp(42).ShouldBe("Hello[42] there, world!");
        }
        public void DelegateShouldBeCalledToAddMiddlewareAroundTheDefaultApp()
        {
            var theNext = "next";
            var theMiddle = "middle";
            var theDefault = "default";

            Func<string, string> middleware = next =>
            {
                theNext = next;
                return theMiddle;
            };

            var builder = new AppBuilder();
            builder.Properties["builder.DefaultApp"] = theDefault;
            var theApp = builder.BuildNew<string>(x => x.Use(middleware));

            builder.Run(theApp);

            theNext.ShouldBeSameAs(theDefault);
            theApp.ShouldBeSameAs(theMiddle);
            theApp.ShouldNotBeSameAs(theDefault);
        }
Beispiel #11
0
        public void DelegateShouldBeCalledToAddMiddlewareAroundTheDefaultApp()
        {
            var theNext    = "next";
            var theMiddle  = "middle";
            var theDefault = "default";

            Func <string, string> middleware = next =>
            {
                theNext = next;
                return(theMiddle);
            };

            var builder = new AppBuilder();

            builder.Properties["builder.DefaultApp"] = theDefault;
            var theApp = builder.BuildNew <string>(x => x.Use(middleware));

            builder.Run(theApp);

            theNext.ShouldBeSameAs(theDefault);
            theApp.ShouldBeSameAs(theMiddle);
            theApp.ShouldNotBeSameAs(theDefault);
        }
        public void TypeofClassConstructorsWithWrongParameterCountShouldThrow()
        {
            Func<int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();
            builder.Properties["builder.DefaultApp"] = theDefault;

            Should.Throw<MissingMethodException>(() =>
            {
                var theApp = builder.BuildNew<Func<int, string>>(
                x => x.Use(typeof(StringPlusValue2), "arg 1", "extra arg"));
            });
        }
        public void TypeofClassConstructorsShouldQualifyAsMiddlewareFactory()
        {
            Func<int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();
            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew<Func<int, string>>(
                x => x
                    .Use(typeof(StringPlusValue2), " world!")
                    .Use(typeof(StringPlusValue2), " there,"));

            theApp(42).ShouldBe("Hello[42] there, world!");
        }
        public void OtherObjectShouldThrow()
        {
            Func<int, string> theDefault = call => "Hello[" + call + "]";

            var builder = new AppBuilder();
            builder.Properties["builder.DefaultApp"] = theDefault;

            Should.Throw<NotSupportedException>(() =>
            {
                var theApp = builder.BuildNew<Func<int, string>>(
                x => x.Use(new object()));
            });
        }
        public void InstanceMemberNamedInvokeShouldQualifyAsAppWithRun()
        {
            var theSite = new MySite();

            var builder = new AppBuilder();

            var theApp = builder.BuildNew<Func<int, string>>(x => x.Run(theSite));

            theApp(42).ShouldBe("Called[42]");
        }
        public void DelegateShouldQualifyAsAppWithRun()
        {
            Func<int, string> theDefault = call => "Hello[" + call + "]";
            Func<int, string> theSite = call => "Called[" + call + "]";

            var builder = new AppBuilder();
            builder.Properties["builder.DefaultApp"] = theDefault;

            var theApp = builder.BuildNew<Func<int, string>>(x => x.Run(theSite));

            theApp(42).ShouldBe("Called[42]");
        }