public ActionResult Index(RedirectInfo info) { if (!ModelState.IsValid) return RedirectToAction("Index"); var url = NormalizeUrl(info.URL); var safeUrl = NormalizeUrl(info.SafeURL ?? Constants.DEFAULT_SAFE_URL); var ttl = info.TTL ?? Constants.DEFAULT_TTL; var id = logic.CreateRedirect(url, safeUrl, ttl); var redirectLink = Url.RouteUrl("Redirect", new { id }, Request.Url.Scheme); return Content(redirectLink); }
public void PostReturnsValidationErrorIfUrlIsMissing() { var info = new RedirectInfo(); var helper = new MvcHelper(); helper.SetUpController(sut); sut.ValidateModel(info); sut.Index(info); Assert.IsFalse(sut.ModelState.IsValid); Assert.AreEqual(1, sut.ModelState["URL"].Errors.Count); Assert.AreEqual("Please enter the URL.", sut.ModelState["URL"].Errors[0].ErrorMessage); }
public void PostNormalizesSafeUrl() { var info = new RedirectInfo { URL = "example.com", SafeURL = "example.com" }; var helper = new MvcHelper(); helper.SetUpController(sut); sut.Index(info); svc.Verify(it => it.CreateRedirect(It.IsAny<string>(), "http://example.com/", It.IsAny<int>())); }
public ActionResult Index() { var model = new RedirectInfo(); return View(model); }
public void PostReturnsShortenedUrl() { svc .Setup(it => it.CreateRedirect("http://example.com/", It.IsAny<string>(), It.IsAny<int>())) .Returns("123"); var info = new RedirectInfo { URL = "example.com" }; var helper = new MvcHelper(); helper.SetUpController(sut); helper.Response.Setup(x => x.ApplyAppPathModifier("/r/123")).Returns("http://localhost/r/123"); var result = (sut.Index(info) as ContentResult).Content; Assert.IsTrue(result.EndsWith("/r/123"), string.Format("Result is [{0}]", result)); }