public void LocalizationRouteCollection_OutboundRoute_CultureInThreadTest() { var localizedRoute = CreateLocalizedRoute(); localizedRoute.AddTranslation(LocalizationRouteCollection.NeutralCulture, "neutral/neutral-{title}_{id}"); localizedRoute.AddTranslation("en-US", "job/job-{title}_{id}"); localizedRoute.AddTranslation("fr-FR", "offre-de-emploi/offre-{title}_{id}"); var routes = new RouteCollection(); routes.Add("OfferDetails", localizedRoute); var tester = new RouteTester(routes); using (new CultureScopedContext("en-US")) { tester.WithRouteInfo("OfferDetails", new { title = "project-manager", id = 12 }) .ShouldGenerateUrl("/job/job-project-manager_12"); } using (new CultureScopedContext("fr-FR")) { tester.WithRouteInfo("OfferDetails", new { title = "chef-de-projet", id = 12 }) .ShouldGenerateUrl("/offre-de-emploi/offre-chef-de-projet_12"); } using (new CultureScopedContext("nl-NL")) { tester.WithRouteInfo("OfferDetails", new { title = "project-manager", id = 12 }) .ShouldGenerateUrl("/neutral/neutral-project-manager_12"); } }
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 TestOutgoingRoutes() { // Arrange // --- Global Arrange // Act and Assert tester.WithRouteInfo("Home", "Index").ShouldGenerateUrl("/"); }
public void ServerError_ShouldReturnCorrectOutboundRoute() { // Assemble var sut = new RouteTester <MvcApplication>(typeof(RouteConfig)); // Act and Assert sut.WithRouteInfo("Error", "ServerError").ShouldGenerateUrl("/Error/ServerError"); }
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 LocalizationRouteCollection_GetVirtualPathWithNullValues_ThrowsArgumentNullException() { var localizedRoute = new LocalizationRouteCollection("~/pages/offer/list.aspx"); localizedRoute.AddTranslation("en-US", "job/job-list"); localizedRoute.AddTranslation("fr-FR", "offre-de-emploi/liste-offre"); var routes = new RouteCollection(); routes.Add("OfferList", localizedRoute); var tester = new RouteTester(routes); using (new CultureScopedContext("en-US")) { tester.WithRouteInfo("OfferList").ShouldGenerateUrl("/job/job-list"); } using (new CultureScopedContext("fr-FR")) { tester.WithRouteInfo("OfferList").ShouldGenerateUrl("/offre-de-emploi/liste-offre"); } }
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 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 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 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"); }