示例#1
0
        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);
        }
示例#2
0
            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);
            }
示例#3
0
            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>()));
            }
示例#4
0
        public ActionResult Index()
        {
            var model = new RedirectInfo();

              return View(model);
        }
示例#5
-1
            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));
            }