/// <summary>
        /// The navigation actions in this test are all triggered by requests to the history handler to directly change the current URL - this
        /// is not how navigation is expected to work in most cases but it's possible that a project might be getting migrated bit by bit and
        /// so some navigations will may be triggered by direct calls to HTML5 history's pushState in some parts of the application, rather
        /// than the static methods being used in all cases. This is still supported, even if it is not encouraged.
        /// </summary>
        private static void TestHotelRouterWithDynamicNavigationCalls(Assert assert)
        {
            if (assert == null)
            {
                throw new ArgumentNullException("assert");
            }

            var navigatorTestWrapper = GetNavigatorToTest(
                initialUrl: new UrlPathDetails(NonNullList <NonBlankTrimmedString> .Empty),
                assert: assert,
                navigatorGenerator: dispatcher => new RootPlusDynamicIdItemPagesNavigator <Hotel>(dispatcher)
                );

            // The navigator initialisation will have executed match-current-route logic, so there should be a single action already present
            // corresponding to the initialUrl specified above
            navigatorTestWrapper.AssertActionRecorded <NavigateToRoot <Hotel> >();

            // Explicitly navigate again to the same URL we're already on - even though the route hasn't changed, this action should result
            // in the route being re-analysed and another action being recorded
            navigatorTestWrapper.NavigateTo(UrlDetailsCreator.New());
            navigatorTestWrapper.AssertActionRecorded <NavigateToRoot <Hotel> >();

            // Now navigate to a different route: /item/abc
            navigatorTestWrapper.NavigateTo(UrlDetailsCreator.New("item", "abc"));
            navigatorTestWrapper.AssertActionRecorded <NavigateToItem <Hotel> >(action => action.Id.Value == "abc");
        }
Esempio n. 2
0
        public static void Go()
        {
            QUnit.Module("Static Matches");

            QUnit.Test("Match '/'", assert =>
            {
                var routeInfo = RouteBuilder.Empty;
                var url       = UrlDetailsCreator.New();
                assert.RouteMatched(routeInfo, url);
            });

            QUnit.Test("Match '/home'", assert =>
            {
                var routeInfo = RouteBuilder.Empty.Fixed("home");
                var url       = UrlDetailsCreator.New("home");
                assert.RouteMatched(routeInfo, url);
            });

            QUnit.Test("Match '/home/info'", assert =>
            {
                var routeInfo = RouteBuilder.Empty.Fixed("home", "info");
                var url       = UrlDetailsCreator.New("home", "info");
                assert.RouteMatched(routeInfo, url);
            });

            QUnit.Test("NotFound '/home' if only '/other' route specified", assert =>
            {
                var routeInfo = RouteBuilder.Empty.Fixed("other");
                var url       = UrlDetailsCreator.New("home");
                assert.RouteNotMatched(routeInfo, url);
            });

            QUnit.Test("NotFound '/home' if only '/home/info' route specified", assert =>
            {
                var routeInfo = RouteBuilder.Empty.Fixed("home", "info");
                var url       = UrlDetailsCreator.New("home");
                assert.RouteNotMatched(routeInfo, url);
            });
        }
Esempio n. 3
0
        public static void Go()
        {
            QUnit.Module("Variable Matches");

            QUnit.Test("Match '/home/info' for route '/home/{name:String}'", assert =>
            {
                var routeInfo = RouteBuilder.Empty
                                .Fixed("home")
                                .String(segment => new { Name = segment });
                var url = UrlDetailsCreator.New("home", "info");
                assert.RouteMatched(
                    routeInfo,
                    url,
                    new { Name = new NonBlankTrimmedString("info") },
                    (actual, expected) => actual.Name.Value == expected.Name.Value
                    );
            });

            QUnit.Test("Match '/home/123' for route '/home/{key:Int}'", assert =>
            {
                var routeInfo = RouteBuilder.Empty
                                .Fixed("home")
                                .Int(value => new { Key = value });
                var url = UrlDetailsCreator.New("home", "123");
                assert.RouteMatched(
                    routeInfo,
                    url,
                    new { Key = 123 },
                    (actual, expected) => actual.Key == expected.Key
                    );
            });

            QUnit.Test("NotFound '/home/info' if only '/home/{key:Int}' route specified", assert =>
            {
                var routeInfo = RouteBuilder.Empty
                                .Fixed("home")
                                .Int(value => new { Key = value });
                var url = UrlDetailsCreator.New("home", "info");
                assert.RouteNotMatched(routeInfo, url);
            });

            QUnit.Test("Match '/product/toy/123' for route '/product/{type:string}/{key:Int}'", assert =>
            {
                var routeInfo = RouteBuilder.Empty
                                .Fixed("product")
                                .String(type => new { Type = type })
                                .Int((dataSoFar, key) => new { dataSoFar.Type, Key = key });
                var url = UrlDetailsCreator.New("product", "toy", "123");
                assert.RouteMatched(
                    routeInfo,
                    url,
                    new { Type = new NonBlankTrimmedString("toy"), Key = 123 },
                    (actual, expected) => (actual.Type.Value == expected.Type.Value) && (actual.Key == expected.Key)
                    );
            });

            QUnit.Test("Match '/product/toy/123' for route '/product/{type:string}/{key:Int}' using Tuples", assert =>
            {
                var routeInfo = RouteBuilder.Empty
                                .Fixed("product")
                                .String()
                                .Int();
                var url = UrlDetailsCreator.New("product", "toy", "123");
                assert.RouteMatched(
                    routeInfo,
                    url,
                    Tuple.Create(new NonBlankTrimmedString("toy"), 123),
                    (actual, expected) => (actual.Item1.Value == expected.Item1.Value) && (actual.Item2 == expected.Item2)
                    );
            });
        }