public void ThrowsExceptionWhenMethodIsNotEligible() { var scanner = new RouteScanner(); var method = typeof(MethodsToScan).GetMethod("InvalidRoute"); Should.Throw <InvalidRouteMethodExceptions>(() => scanner.ScanMethod(method)); }
public void ReturnsNoRoutesWhenMethodHasNoAttribute() { var scanner = new RouteScanner(); var method = typeof(MethodsToScan).GetMethod("HasNoAttributes"); var routes = scanner.ScanMethod(method); routes.ShouldNotBeNull(); routes.ShouldBeEmpty(); }
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"); }
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"); }
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}"); }
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]"); }