예제 #1
0
        public void BuildRoutes_ControllerWithDefault_ReturnRoutesWithDefault()
        {
            var expectedRouteParts = new[]
            {
                Array.Empty <string>(),
                new[] { "help" },
                new[] { "setup" },
                new[] { "config" },
                new[] { "config", "help" },
                new[] { "config", "setup" }
            };

            var builder = new RoutesBuilder();

            builder.AddController(typeof(TestControllerWithDefault));

            // Act
            var routes = builder.BuildRoutes().ToArray();

            // Assert
            routes
            .Should()
            .HaveCount(expectedRouteParts.Length);

            var routeParts = routes.Select(x => x.RouteParts).ToArray();

            foreach (var expectedRoutePart in expectedRouteParts)
            {
                routeParts
                .Should()
                .ContainEquivalentOf(expectedRoutePart);
            }
        }
예제 #2
0
        public void BuildRoutes_ForControllerClassWithoutControllerAttribute_ReturnsEmptyRoutes()
        {
            var builder = new RoutesBuilder();

            builder.AddController(typeof(TestNoneController));

            // Act
            var routes = builder.BuildRoutes();

            // Assert
            routes
            .Should()
            .BeEmpty();
        }
예제 #3
0
        public void BuildRoutes_ForDemoController_TwoActionRoutesCreated()
        {
            var builder = new RoutesBuilder();

            builder.AddController(typeof(DemoCliController));

            // Act
            var routes = builder.BuildRoutes().ToArray();

            // Assert
            routes
            .Should()
            .HaveCount(2);

            routes.First().RouteParts
            .Should()
            .ContainInOrder("demo", "test");

            routes.First().ControllerType
            .Should()
            .Be(typeof(DemoCliController));

            routes.First().ActionMethod
            .Should()
            .BeSameAs(typeof(DemoCliController).GetMethod(nameof(DemoCliController.DoAsync)));

            routes.Last().RouteParts
            .Should()
            .ContainInOrder("demo", "more", "command");

            routes.Last().ControllerType
            .Should()
            .Be(typeof(DemoCliController));

            routes.Last().ActionMethod
            .Should()
            .BeSameAs(typeof(DemoCliController).GetMethod(nameof(DemoCliController.DoMoreAsync)));
        }