예제 #1
0
            public void InvokesSharedAndNonSharedInstanceMethod()
            {
                var method   = typeof(TestInvokeRoutes).GetMethod("SharedInstanceMethod");
                var instance = new TestInvokeRoutes();

                // These use the same method and share an instance
                var route1 = new Route(instance.SharedInstanceMethod);
                var route2 = new Route(instance.SharedInstanceMethod);

                // This uses the same method, but should be using a different instance
                var route3 = new Route(method);

                TestInvokeRoutes.SharedInstanceMethodHit.ShouldBeFalse();

                route1.Invoke(Mocks.HttpContext());

                TestInvokeRoutes.SharedInstanceMethodHit.ShouldBeTrue();
                instance.InstanceHits.ShouldBe(1);

                route2.Invoke(Mocks.HttpContext());
                instance.InstanceHits.ShouldBe(2);

                route3.Invoke(Mocks.HttpContext());
                instance.InstanceHits.ShouldBe(2);

                route1.Invoke(Mocks.HttpContext());
                instance.InstanceHits.ShouldBe(3);
            }
예제 #2
0
                public void OverridesWithMethod()
                {
                    const string pathinfo = "/path/to/resource";
                    var          method   = typeof(TestInvokeRoutes).GetMethod("ShouldThrowNoExceptions");
                    Func <IHttpContext, IHttpContext> function = new TestInvokeRoutes().ShouldThrowNoExceptions;
                    var fname = $"{method.ReflectedType.FullName}.{method.Name}";

                    var route = new Route(function, HttpMethod.GET, pathinfo);

                    route.ToString().ShouldBe($"{HttpMethod.GET} {pathinfo} > {fname}");
                }
예제 #3
0
            public void InvokesSharedInstanceMethod()
            {
                var instance = new TestInvokeRoutes();
                var route    = new Route(instance.InstanceMethod);

                TestInvokeRoutes.InstanceMethodHit.ShouldBeFalse();

                route.Invoke(Mocks.HttpContext());

                TestInvokeRoutes.InstanceMethodHit.ShouldBeTrue();
                instance.InstanceHits.ShouldBe(1);

                route.Invoke(Mocks.HttpContext());
                instance.InstanceHits.ShouldBe(2);
            }