Beispiel #1
0
 public void Get_ArtistInfo()
 {
     var request = new HttpRequestMessage(HttpMethod.Get, artistInfo);
     var routeTester = new RouteTester(config, request);
     Assert.AreEqual(typeof(ArtistInfoController), routeTester.GetControllerType());
     Assert.AreEqual(ReflectionHelper.GetMethodName((ArtistInfoController c) => c.Get(Guid.NewGuid())), routeTester.GetActionName());
 }
        public void ProfileShouldMapRouteDefaultIndex()
        {
            var tester = new RouteTester<UsersAreaRegistration>();

            tester.WithIncomingRequest("/Users/Profile/Index")
                .ShouldMatchRoute("Users", "Profile", "Index");
        }
        public void VotesShouldMapRouteVote()
        {
            var tester = new RouteTester<UsersAreaRegistration>();

            tester.WithIncomingRequest("/Users/Votes/Vote")
                .ShouldMatchRoute("Users", "Votes", "Vote");
        }
        public void TagsShouldMapRouteAll()
        {
            var tester = new RouteTester<UsersAreaRegistration>();

            tester.WithIncomingRequest("/Users/Tags/All")
                .ShouldMatchRoute("Users", "Tags", "All");
        }
        public void TestIncomingRoutes()
        {
            // Arrange
            var tester = new RouteTester<MvcApplication>();
            var taskListId = ShortGuid.NewGuid().ToString();
            const string taskListOwnerId = "user-windowsliveid";
            var noteId = ShortGuid.NewGuid().ToString();
            const string noteOwnerId = "user-windowsliveid";
            const string fileName = "test.txt";

            // Assert
            tester.WithIncomingRequest("/handler.axd/pathInfo").ShouldBeIgnored();
            tester.WithIncomingRequest("/").ShouldMatchRoute("Users", "Home");

            tester.WithIncomingRequest("/TaskLists/Index").ShouldMatchRoute("TaskLists", "Index");
            tester.WithIncomingRequest(string.Format("/TaskLists/{0}/{1}/Details", taskListOwnerId, taskListId)).ShouldMatchRoute("TaskLists", "Details", new { taskListOwnerId, taskListId });
            tester.WithIncomingRequest(string.Format("/TaskLists/{0}/{1}/Edit", taskListOwnerId, taskListId)).ShouldMatchRoute("TaskLists", "Edit", new { taskListOwnerId, taskListId });
            tester.WithIncomingRequest(string.Format("/TaskLists/{0}/{1}/Delete", taskListOwnerId, taskListId)).ShouldMatchRoute("TaskLists", "Delete", new { taskListOwnerId, taskListId });
            tester.WithIncomingRequest(string.Format("/TaskLists/{0}/{1}/Share", taskListOwnerId, taskListId)).ShouldMatchRoute("TaskLists", "Share", new { taskListOwnerId, taskListId });

            tester.WithIncomingRequest(string.Format("/Notes/TaskList/{0}/{1}/Index", taskListOwnerId, taskListId)).ShouldMatchRoute("Notes", "Index", new { taskListOwnerId, taskListId });
            tester.WithIncomingRequest(string.Format("/Notes/TaskList/{0}/{1}/Create", taskListOwnerId, taskListId)).ShouldMatchRoute("Notes", "Create", new { taskListOwnerId, taskListId });
            tester.WithIncomingRequest(string.Format("/Notes/{0}/{1}/Details", noteOwnerId, noteId)).ShouldMatchRoute("Notes", "Details", new { noteOwnerId, noteId });
            tester.WithIncomingRequest(string.Format("/Notes/{0}/{1}/Delete", noteOwnerId, noteId)).ShouldMatchRoute("Notes", "Delete", new { noteOwnerId, noteId });
            tester.WithIncomingRequest(string.Format("/Notes/{0}/{1}/Edit", noteOwnerId, noteId)).ShouldMatchRoute("Notes", "Edit", new { noteOwnerId, noteId });
            tester.WithIncomingRequest(string.Format("/Notes/{0}/{1}/Share", noteOwnerId, noteId)).ShouldMatchRoute("Notes", "Share", new { noteOwnerId, noteId });
            tester.WithIncomingRequest(string.Format("/Notes/{0}/{1}/Copy", noteOwnerId, noteId)).ShouldMatchRoute("Notes", "Copy", new { noteOwnerId, noteId });
            tester.WithIncomingRequest(string.Format("/Notes/{0}/{1}/Move", noteOwnerId, noteId)).ShouldMatchRoute("Notes", "Move", new { noteOwnerId, noteId });

            tester.WithIncomingRequest(string.Format("/Files/Note/{0}/{1}/Index", noteOwnerId, noteId)).ShouldMatchRoute("Files", "Index", new { noteOwnerId, noteId });
            tester.WithIncomingRequest(string.Format("/Files/Note/{0}/{1}/Download/{2}", noteOwnerId, noteId, fileName)).ShouldMatchRoute("Files", "Download", new { noteOwnerId, noteId, fileName });
            tester.WithIncomingRequest(string.Format("/Files/Note/{0}/{1}/Delete/{2}", noteOwnerId, noteId, fileName)).ShouldMatchRoute("Files", "Delete", new { noteOwnerId, noteId, fileName });
        }
        public void TestOutgoingRoutes()
        {
            // Arrange
            var tester = new RouteTester<MvcApplication>();
            var taskListId = ShortGuid.NewGuid().ToString();
            const string taskListOwnerId = "user-windowsliveid";
            var noteId = ShortGuid.NewGuid().ToString();
            const string noteOwnerId = "user-windowsliveid";
            const string fileName = "test.txt";

            // Assert
            tester.WithRouteInfo("Users", "Home").ShouldGenerateUrl("/");
            tester.WithRouteInfo("TaskLists", "Index").ShouldGenerateUrl("/TaskLists/Index");
            tester.WithRouteInfo("TaskLists", "Index", new { sortOrder = "Title", page = 1 }).ShouldGenerateUrl("/TaskLists/Index?sortOrder=Title&page=1");
            tester.WithRouteInfo("TaskLists", "Details", new { taskListOwnerId, taskListId }).ShouldGenerateUrl(string.Format("/TaskLists/{0}/{1}/Details", taskListOwnerId, taskListId));
            tester.WithRouteInfo("TaskLists", "Edit", new { taskListOwnerId, taskListId }).ShouldGenerateUrl(string.Format("/TaskLists/{0}/{1}/Edit", taskListOwnerId, taskListId));
            tester.WithRouteInfo("TaskLists", "Delete", new { taskListOwnerId, taskListId }).ShouldGenerateUrl(string.Format("/TaskLists/{0}/{1}/Delete", taskListOwnerId, taskListId));
            tester.WithRouteInfo("TaskLists", "Share", new { taskListOwnerId, taskListId }).ShouldGenerateUrl(string.Format("/TaskLists/{0}/{1}/Share", taskListOwnerId, taskListId));

            tester.WithRouteInfo("Notes", "Index", new { taskListOwnerId, taskListId }).ShouldGenerateUrl(string.Format("/Notes/TaskList/{0}/{1}", taskListOwnerId, taskListId));
            tester.WithRouteInfo("Notes", "Create", new { taskListOwnerId, taskListId }).ShouldGenerateUrl(string.Format("/Notes/TaskList/{0}/{1}/Create", taskListOwnerId, taskListId));
            tester.WithRouteInfo("Notes", "Details", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Notes/{0}/{1}/Details", noteOwnerId, noteId));
            tester.WithRouteInfo("Notes", "Delete", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Notes/{0}/{1}/Delete", noteOwnerId, noteId));
            tester.WithRouteInfo("Notes", "Edit", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Notes/{0}/{1}/Edit", noteOwnerId, noteId));
            tester.WithRouteInfo("Notes", "Share", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Notes/{0}/{1}/Share", noteOwnerId, noteId));
            tester.WithRouteInfo("Notes", "Copy", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Notes/{0}/{1}/Copy", noteOwnerId, noteId));
            tester.WithRouteInfo("Notes", "Move", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Notes/{0}/{1}/Move", noteOwnerId, noteId));

            tester.WithRouteInfo("Files", "Index", new { noteOwnerId, noteId }).ShouldGenerateUrl(string.Format("/Files/Note/{0}/{1}", noteOwnerId, noteId));
            tester.WithRouteInfo("Files", "Download", new { noteOwnerId, noteId, fileName }).ShouldGenerateUrl(string.Format("/Files/Note/{0}/{1}/Download/{2}", noteOwnerId, noteId, fileName));
            tester.WithRouteInfo("Files", "Delete", new { noteOwnerId, noteId, fileName }).ShouldGenerateUrl(string.Format("/Files/Note/{0}/{1}/Delete/{2}", noteOwnerId, noteId, fileName));
        }
        public void ArticlesShouldMapRouteDetailsWithPassedParameterId()
        {
            var tester = new RouteTester<UsersAreaRegistration>();

            tester.WithIncomingRequest("/Users/Articles/Details/5")
                .ShouldMatchRoute("Users", "Articles", "Details", new { id = 5 });
        }
Beispiel #8
0
        public void Get_ArtistInfo()
        {
            var request     = new HttpRequestMessage(HttpMethod.Get, artistInfo);
            var routeTester = new RouteTester(config, request);

            Assert.AreEqual(typeof(ArtistInfoController), routeTester.GetControllerType());
            Assert.AreEqual(ReflectionHelper.GetMethodName((ArtistInfoController c) => c.Get(Guid.NewGuid())), routeTester.GetActionName());
        }
        public void LoginRequired_ShouldReturnCorrectOutboundRoute()
        {
            // Assemble
            var sut = new RouteTester <MvcApplication>(typeof(RouteConfig));

            // Act and Assert
            sut.WithRouteInfo("Error", "LoginRequired").ShouldGenerateUrl("/Error/LoginRequired");
        }
Beispiel #10
0
        public void V2_RPC_UrlControllerPostIsCorrect()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, "http://www.strathweb.com/api/v2/url/Add");

            var routeTester = new RouteTester(_config, request);

            Assert.Equal(typeof(UrlController), routeTester.GetControllerType());
            Assert.Equal(ReflectionHelpers.GetMethodName((UrlController p) => p.Add(new Url())), routeTester.GetActionName());
        }
Beispiel #11
0
        [Test] public void GET_method_has_correct_destination_GetGamesForPublisher()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, _prefix + "api/publisher/1/games");

            var routeTester = new RouteTester(_config, request);

            Assert.AreEqual(typeof(PublisherController), routeTester.GetControllerType());
            //Assert.AreEqual(ReflectionHelper.GetMethodName((PublisherController p) => p.GetPublisherGames(1)), routeTester.GetActionName());
        }
Beispiel #12
0
        public void PUT_method_has_correct_destination_EditGenre()
        {
            var request = new HttpRequestMessage(HttpMethod.Put, _prefix + "api/genres/1");

            var routeTester = new RouteTester(_config, request);

            Assert.AreEqual(typeof(GenresController), routeTester.GetControllerType());
            Assert.AreEqual(ReflectionHelper.GetMethodName((GenresController p) => p.EditGenre(It.IsAny <int>(), It.IsAny <GenreModel>())), routeTester.GetActionName());
        }
Beispiel #13
0
        public void GET_method_has_correct_destination_GetGenres()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, _prefix + "api/platforms");

            var routeTester = new RouteTester(_config, request);

            Assert.AreEqual(typeof(PlatformsController), routeTester.GetControllerType());
            Assert.AreEqual(ReflectionHelper.GetMethodName((PlatformsController p) => p.GetPlatforms()), routeTester.GetActionName());
        }
Beispiel #14
0
        public void GET_method_has_correct_destination_DownloadGame()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, _prefix + "api/games/1/download");

            var routeTester = new RouteTester(_config, request);

            Assert.AreEqual(typeof(GamesController), routeTester.GetControllerType());
            //Assert.AreEqual(ReflectionHelper.GetMethodName((GamesController p) => p.DownloadGame(1)), routeTester.GetActionName());
        }
Beispiel #15
0
        public void POST_method_has_correct_destination_CreatePublisher()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, _prefix + "api/publisher");

            var routeTester = new RouteTester(_config, request);

            Assert.AreEqual(typeof(PublisherController), routeTester.GetControllerType());
            Assert.AreEqual(ReflectionHelper.GetMethodName((PublisherController p) => p.CreatePublisher(It.IsAny <PublisherModel>())), routeTester.GetActionName());
        }
Beispiel #16
0
        public void DELETE_method_has_correct_destination_DeletePublisher()
        {
            var request = new HttpRequestMessage(HttpMethod.Delete, _prefix + "api/publisher/1");

            var routeTester = new RouteTester(_config, request);

            Assert.AreEqual(typeof(PublisherController), routeTester.GetControllerType());
            Assert.AreEqual(ReflectionHelper.GetMethodName((PublisherController p) => p.DeletePublisher(It.IsAny <int>())), routeTester.GetActionName());
        }
Beispiel #17
0
        public void WithRouteInfo_NullOrEmptyRouteName_ShouldThrowArgumentNullException([Values(null, "")] string value)
        {
            var routes = new RouteCollection();

            routes.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester = new RouteTester(routes);

            Assert.That(() => tester.WithRouteInfo(value), Throws.InstanceOf <ArgumentNullException>());
        }
        public void ShouldBeIgnored_IsIgnored_ShouldWorkFine()
        {
            var routeCollection = new RouteCollection();

            routeCollection.Ignore("ignore");

            var tester = new RouteTester(routeCollection);

            Assert.That(() => tester.WithIncomingRequest("/ignore").ShouldBeIgnored(), Throws.Nothing);
        }
        public void ShouldMatchNoRoute_NoMatch_ShouldWorkFine()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester = new RouteTester(routeCollection);

            Assert.DoesNotThrow(() => { tester.WithIncomingRequest("/unknown").ShouldMatchNoRoute(); }, "Requested URL should not have matched a route.");
        }
Beispiel #20
0
        public void ShouldGenerateUrl_NullOrEmptyExpectedUrl_Throws()
        {
            var routes = new RouteCollection();

            routes.MapPageRoute("Details", "details", "~/pages/details.aspx");

            var tester = new RouteTester(routes);

            Assert.That(() => tester.WithRouteInfo("Details").ShouldGenerateUrl(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => tester.WithRouteInfo("Details").ShouldGenerateUrl(string.Empty), Throws.InstanceOf <ArgumentNullException>());
        }
        public void DefaultRouteTest()
        {
            //// Arrange
            var routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);

            var routeTester = new RouteTester(routes);

            //// Assert
            routeTester.WithIncomingRequest("/").ShouldMatchRoute("Home", "Index");
            routeTester.WithIncomingRequest("/Home").ShouldMatchRoute("Home", "Index");
            routeTester.WithIncomingRequest("/Home/Index").ShouldMatchRoute("Home", "Index");
        }
Beispiel #22
0
        public void DefaultRouteTest()
        {
            //// Arrange
            var routes = new RouteCollection();

            RouteConfig.RegisterRoutes(routes);

            var routeTester = new RouteTester(routes);

            //// Assert
            routeTester.WithIncomingRequest("/").ShouldMatchRoute("Home", "Index");
            routeTester.WithIncomingRequest("/Home").ShouldMatchRoute("Home", "Index");
            routeTester.WithIncomingRequest("/Home/Index").ShouldMatchRoute("Home", "Index");
        }
        public void CanAlterContext()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var         tester      = new RouteTester(routeCollection);
            RequestInfo requestInfo = tester.WithIncomingRequest("/test");

            requestInfo.HttpContext.Items.Add("key", "value");

            Assert.That(() => requestInfo.ShouldMatchPageRoute("~/pages/test.aspx"), Throws.Nothing);
            Assert.That(requestInfo.HttpContext.Items["key"], Is.EqualTo("value"));
        }
        public void HomeTest1Test_RouteTest_Should_Not_MatchRoute()
        {
            //// Arrange
            var routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);

            var routeTester = new RouteTester(routes);

            //// Act
            var requsetInfo = routeTester.WithIncomingRequest("/Home/Test/1/Test");

            //// Assert
            requsetInfo.ShouldMatchNoRoute();
        }
Beispiel #25
0
        public void ShouldGenerateUrl_MismatchUrls_Throws()
        {
            var routes = new RouteCollection();

            routes.MapPageRoute("Details", "details", "~/pages/details.aspx");

            var tester = new RouteTester(routes);

            Assert.That(
                () => tester.WithRouteInfo("Details").ShouldGenerateUrl("/wrong"),
                Throws.InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"URL mismatch. Expected: ""/wrong"", but was: ""/details""."));
        }
        public void ShouldMapPageRoute_CompareNullRouteValue_ShouldWorkFine()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Details", "{culture}/details/{id}", "~/pages/details.aspx", false, new RouteValueDictionary {
                { "culture", "en-US" }, { "id", (int?)null }
            });

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/fr-FR/details/");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/details.aspx", new { id = (string)null }),
                Throws.Nothing);
        }
Beispiel #27
0
        public void CanAlterHttpContext()
        {
            var routes = new RouteCollection();

            routes.MapPageRoute("Details", "details", "~/pages/details.aspx");

            var tester    = new RouteTester(routes);
            var routeInfo = tester.WithRouteInfo("Details");
            var ctx       = routeInfo.HttpContext;

            ctx.Items.Add("key", "value");

            Assert.That(() => { routeInfo.ShouldGenerateUrl("/details"); }, Throws.Nothing);
            Assert.AreEqual("value", routeInfo.HttpContext.Items["key"]);
        }
        public void ShouldMapPageRoute_CorrectRouteValues_ShouldWorkFine()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Details", "{culture}/details/{id}", "~/pages/details.aspx", false, new RouteValueDictionary {
                { "culture", "en-US" }
            });

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("en-US/details/14");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/details.aspx", new { id = 14, culture = "en-US" }),
                Throws.Nothing);
        }
Beispiel #29
0
        public void HomeTest1Test_RouteTest_Should_Not_MatchRoute()
        {
            //// Arrange
            var routes = new RouteCollection();

            RouteConfig.RegisterRoutes(routes);

            var routeTester = new RouteTester(routes);

            //// Act
            var requsetInfo = routeTester.WithIncomingRequest("/Home/Test/1/Test");

            //// Assert
            requsetInfo.ShouldMatchNoRoute();
        }
        public void ShouldMapPageRoute_NullOrEmptyUrl_Throws()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/test");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute(null),
                Throws.InstanceOf <ArgumentNullException>());
            Assert.That(
                () => requestInfo.ShouldMatchPageRoute(string.Empty),
                Throws.InstanceOf <ArgumentNullException>());
        }
        public void ShouldBeIgnored_UrlNotIgnored_ShouldThrowAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester = new RouteTester(routeCollection);

            Assert.That(
                () => tester.WithIncomingRequest("/test").ShouldBeIgnored(),
                Throws
                .InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"The request was not ignored (for url: ""/test"")."));
        }
Beispiel #32
0
        public void WithIncomingRequest_NullOrEmptyUrl_ShouldThrowArgumentNullException([Values(null, "")] string value)
        {
            var routes = new RouteCollection();

            routes.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester = new RouteTester(routes);

            Assert.That(
                () => tester.WithIncomingRequest(value),
                Throws
                .ArgumentException
                .With
                .Message
                .StartsWith("Url cannot be null or empty."));
        }
        public void Home_RouteTest_Should_MatchRoute()
        {
            //// Arrange
            var routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);

            var expectedControllerName = "Home";
            var expectedActionName = "Index";

            var routeTester = new RouteTester(routes);

            //// Act
            var requsetInfo = routeTester.WithIncomingRequest("/Home");

            //// Assert
            requsetInfo.ShouldMatchRoute(expectedControllerName, expectedActionName);
        }
        public void ShouldMatchNoRoute_UrlIncorrectlyMatches_ShouldThrowAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester = new RouteTester(routeCollection);

            Assert.That(
                () => tester.WithIncomingRequest("/test").ShouldMatchNoRoute(),
                Throws
                .InstanceOf <WebFormsRouteUnitTester
                             .AssertionException>()
                .With
                .Message
                .EqualTo(@"A matching route was found (for url: ""/test"")."));
        }
        public void ShouldMapPageRoute_NoPageRouteHandler_ShouldThrowAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.Add(new Route("test", new FakeRouteHandler()));

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/test");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/test.aspx"),
                Throws
                .InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"RouteHandler is not a PageRouteHandler but a ""WebFormsRouteUnitTester.Tests.RequestInfoTest+FakeRouteHandler""."));
        }
        public void ShouldMapPageRoute_MismatchUrl_ShouldThrowAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Test", "test", "~/pages/test.aspx");

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/test");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/details.aspx"),
                Throws
                .InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"Resolved path is: ""~/pages/test.aspx"", expected: ""~/pages/details.aspx""."));
        }
Beispiel #37
0
        public void Home_RouteTest_Should_MatchRoute()
        {
            //// Arrange
            var routes = new RouteCollection();

            RouteConfig.RegisterRoutes(routes);

            var expectedControllerName = "Home";
            var expectedActionName     = "Index";

            var routeTester = new RouteTester(routes);

            //// Act
            var requsetInfo = routeTester.WithIncomingRequest("/Home");

            //// Assert
            requsetInfo.ShouldMatchRoute(expectedControllerName, expectedActionName);
        }
        public void ShouldMapPageRoute_UnexpectedRouteValues_ShouldThrowsAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Details", "details/{id}", "~/pages/details.aspx", false, new RouteValueDictionary {
                { "id", 1036 }
            });

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/details");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/details.aspx"),
                Throws
                .InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"Route values mismatch. Expected 0 route values, but vas: 1 route values (for url: ""/details"")."));
        }
        public void ShouldMapPageRoute_MissingRouteValueKey_ShouldThrowAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Details", "{culture}/details/{id}", "~/pages/details.aspx", false, new RouteValueDictionary {
                { "culture", "en-US" }
            });

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/fr-FR/details/13");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/details.aspx", new { title = "project-manager" }),
                Throws
                .InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"Route values mismatch. Expected route value with key ""title"" was not found (for url: ""/fr-FR/details/13"")."));
        }
        public void ShouldMapPageRoute_WrongRouteValue_ShouldThrowAssertionException()
        {
            var routeCollection = new RouteCollection();

            routeCollection.MapPageRoute("Details", "{culture}/details/{id}", "~/pages/details.aspx", false, new RouteValueDictionary {
                { "culture", "en-US" }
            });

            var tester      = new RouteTester(routeCollection);
            var requestInfo = tester.WithIncomingRequest("/fr-FR/details/13");

            Assert.That(
                () => requestInfo.ShouldMatchPageRoute("~/pages/details.aspx", new { id = 14 }),
                Throws
                .InstanceOf <WebFormsRouteUnitTester.AssertionException>()
                .With
                .Message
                .EqualTo(@"Route values mismatch. Expected: route value with key ""id"" and value ""14"", but was: route value with key ""id"" and value ""13"" (for url: ""/fr-FR/details/13"")."));
        }
Beispiel #41
0
        public void TestMethod1()
        {
            //
            // TODO: Add test logic here
            //

            // Arrange
            var tester = new RouteTester<MvcApplication>();

            // Assert
            //tester.WithIncomingRequest("/").ShouldMatchRoute("Home", "Index");
            tester.WithIncomingRequest("/CRUD/Referre").ShouldMatchRoute("Referree", "Index");
            //tester.WithIncomingRequest("/Foo/Index").ShouldMatchRoute("Foo", "Index");
            //tester.WithIncomingRequest("/Foo/Bar").ShouldMatchRoute("Foo", "Bar");
            //tester.WithIncomingRequest("/Foo/Bar/5").ShouldMatchRoute("Foo", "Bar", new { id = 5 });

            //tester.WithIncomingRequest("/Foo/Bar/5/Baz").ShouldMatchNoRoute();

            //tester.WithIncomingRequest("/handler.axd/pathInfo").ShouldBeIgnored();
        }
 public void TestRouteById()
 {
     var tester = new RouteTester<MvcApplication>();
     tester.WithIncomingRequest("/").ShouldMatchRoute("Home", "Index");            
 }
        public void TestOutgoingRoutes()
        {
            // Arrange
               var tester = new RouteTester<MvcApplication>();

               // Assert
               tester.WithRouteInfo("Office", "Edit").ShouldGenerateUrl("/office/edit");
               tester.WithRouteInfo("Office", "Summary").ShouldGenerateUrl("/office/summary");
               //tester.WithRouteInfo("Home", "About").ShouldGenerateUrl("/Home/About");
               //tester.WithRouteInfo("Home", "About", new { id = 5 }).ShouldGenerateUrl("/Home/About/5");
               //tester.WithRouteInfo("Home", "About", new { id = 5, someKey = "someValue" }).ShouldGenerateUrl("/Home/About/5?someKey=someValue");
        }
        public void TestIncomingRoutes()
        {
            // Arrange
              var tester = new RouteTester<MvcApplication>();

              // Assert
              tester.WithIncomingRequest("/").ShouldMatchRoute("Search", "Index");
              tester.WithIncomingRequest("/queue").ShouldMatchRoute("Queue", "Index");
              tester.WithIncomingRequest("/office/summary").ShouldMatchRoute("Office", "Summary");
              tester.WithIncomingRequest("/office/create").ShouldMatchRoute("Office", "Create");
              tester.WithIncomingRequest("/office/edit").ShouldMatchRoute("Office", "Edit");
              tester.WithIncomingRequest("/office/search").ShouldMatchRoute("Office", "Search");
              tester.WithIncomingRequest("/office/model").ShouldMatchRoute("Office", "Model");
              //tester.WithIncomingRequest("/multiplefamily/report/edit/f8de7dcf-5bc2-42d3-ae7e-9fe601038ac9/berkshire-by-the-sea").ShouldMatchRoute("Multiplefamily", "Edit");

              //tester.WithIncomingRequest("/Foo/Index").ShouldMatchRoute("Foo", "Index");
              //tester.WithIncomingRequest("/Foo/Bar").ShouldMatchRoute("Foo", "Bar");
              //tester.WithIncomingRequest("/Foo/Bar/5").ShouldMatchRoute("Foo", "Bar", new { id = 5 });

              //tester.WithIncomingRequest("/Foo/Bar/5/Baz").ShouldMatchNoRoute();

              //tester.WithIncomingRequest("/handler.axd/pathInfo").ShouldBeIgnored();
        }
 public void BeforeScenario()
 {
     var routes = new RouteCollection();
     RouteConfig.RegisterRoutes(routes);
     this.RouteTester = new RouteTester(routes);
 }