示例#1
0
            public void ThrowsExceptionWhenMethodIsNotEligible()
            {
                var scanner = new RouteScanner();
                var method  = typeof(MethodsToScan).GetMethod("InvalidRoute");

                Should.Throw <InvalidRouteMethodExceptions>(() => scanner.ScanMethod(method));
            }
示例#2
0
            public void ReturnsNoRoutesWhenMethodHasNoAttribute()
            {
                var scanner = new RouteScanner();
                var method  = typeof(MethodsToScan).GetMethod("HasNoAttributes");

                var routes = scanner.ScanMethod(method);

                routes.ShouldNotBeNull();
                routes.ShouldBeEmpty();
            }
示例#3
0
            public void AppliesBasepathToRoutesReturned()
            {
                var scanner = new RouteScanner();
                var method  = typeof(MethodsToScan).GetMethod("HasOneAttribute");

                var routes1 = scanner.ScanMethod(method, "/dog");
                var routes2 = scanner.ScanMethod(method, "cat");

                routes1.ShouldNotBeNull();
                routes2.ShouldNotBeNull();
                routes1.Count.ShouldBe(1);
                routes2.Count.ShouldBe(1);


                routes1[0].HttpMethod.ShouldBe(HttpMethod.GET);
                routes1[0].PathInfo.ShouldBe("/dog/stuff");

                routes2[0].HttpMethod.ShouldBe(HttpMethod.GET);
                routes2[0].PathInfo.ShouldBe("/cat/stuff");
            }
示例#4
0
            public void ReturnsOneRouteWhenMethodHasOneAttribute()
            {
                var scanner = new RouteScanner();
                var method  = typeof(MethodsToScan).GetMethod("HasOneAttribute");

                var routes = scanner.ScanMethod(method);

                routes.ShouldNotBeNull();
                routes.Count.ShouldBe(1);

                var route = routes[0];

                route.HttpMethod.ShouldBe(HttpMethod.GET);
                route.PathInfo.ShouldBe("/stuff");
            }
示例#5
0
            public void LogsMessageForGeneratedRoutes()
            {
                var logger  = new InMemoryLogger();
                var scanner = new RouteScanner {
                    Logger = logger
                };
                var method = typeof(MethodsToScan).GetMethod("HasMultipleAttributes");

                var routes = scanner.ScanMethod(method);

                routes.ShouldNotBeNull();
                routes.Count.ShouldBe(2);

                var route1 = routes[0];
                var route2 = routes[1];

                logger.Logs.Count.ShouldBe(2);
                logger.Logs[0].Message.ShouldBe($"Generated route {route1.HttpMethod} {route1.PathInfo} > {route1.Name}");
                logger.Logs[1].Message.ShouldBe($"Generated route {route2.HttpMethod} {route2.PathInfo} > {route2.Name}");
            }
示例#6
0
            public void ReturnsMultipleRoutesWhenMethodHasMultipleAttributes()
            {
                var scanner = new RouteScanner();
                var method  = typeof(MethodsToScan).GetMethod("HasMultipleAttributes");

                var routes = scanner.ScanMethod(method);

                routes.ShouldNotBeNull();
                routes.Count.ShouldBe(2);

                var route1 = routes[0];

                route1.HttpMethod.ShouldBe(HttpMethod.DELETE);
                route1.PathInfo.ShouldBe("/more/stuff");

                var route2 = routes[1];

                route2.HttpMethod.ShouldBe(HttpMethod.POST);
                route2.PathInfo.ShouldBe("/stuff/[id]");
            }