public void GetURLStatusCode_Return400() { //arrange var url400 = "https://www.jielselmani.me/blog?category=Open+Source&format=rss"; //act var underTest400 = CheckURL.GetURLStatusCode(url400); //arrange Assert.AreEqual(400, underTest400); }
public void GetURLStatusCode_Return404() { //arrange var url404 = "http://amartinencosbr600.blogspot.com/feeds/posts/default"; //act var underTest404 = CheckURL.GetURLStatusCode(url404); //arrange Assert.AreEqual(404, underTest404); }
public void GetURLStatusCode_Return200() { //arrange var url200 = "http://google.ca"; //act var underTest200 = CheckURL.GetURLStatusCode(url200); //arrange Assert.AreEqual(200, underTest200); }
public void GetURLStatusCode_Return0() { //arrange var urlUnknown = "http://s-aleinikov.blog.ca/feed/atom/posts/"; //act var underTestUnknown = CheckURL.GetURLStatusCode(urlUnknown); //arrange Assert.AreEqual(0, underTestUnknown); Assert.AreNotEqual(200, underTestUnknown); Assert.AreNotEqual(400, underTestUnknown); Assert.AreNotEqual(404, underTestUnknown); }
public async Task <JsonResult> Post([FromBody] URLModel value) { if (ModelState.IsValid) { string accountID = ""; try { string authHeader = HttpContext.Request.Headers["Authorization"]; if (!string.IsNullOrEmpty(authHeader)) { bool isHeaderValid = HeaderAuthorizationMiddleware.ValidateCredentials(authHeader, _context); if (isHeaderValid) { var user = _context.Users.SingleOrDefault(s => s.Token == authHeader); _model.AccountId = user.AccountId; accountID = user.AccountId; } else { var jsonResult = new { error = "Invalid user!" }; return(new JsonResult(jsonResult)); } } else { var jsonResult = new { error = "Unautorized user!" }; return(new JsonResult(jsonResult)); } } catch (Exception e) { var jsonResult = new { error = "Authorization error! " + e.Message }; return(new JsonResult(jsonResult)); } value.RedirectURL = CheckURL.FormatUrl(value.RedirectURL, true); if (value.RedirectURL.Length > 5) { var ExistingURL = _context.URL.SingleOrDefault(s => s.RedirectURL == value.RedirectURL && s.AccountId == accountID); if (ExistingURL != null) { var jsonResult = new { shortUrl = ExistingURL.ShortCode }; return(new JsonResult(jsonResult)); } var i = await _check.Check(value.RedirectURL); if (i == true) { try { int nextId = 1; int?next = _context.URL.Max(u => (int?)u.ID); if (next != null) { nextId = (int)next + 1; } //_model.ShortCode = _settings.AppUrl + ShorterURL.Encode(nextId); _model.ShortCode = getPath(HttpContext) + ShorterURL.Encode(nextId); _model.RedirectURL = value.RedirectURL; _model.RedirectType = value.RedirectType; _context.URL.Add(_model); if (_context.SaveChanges() > 0) { var jsonResult = new { shortUrl = _model.ShortCode }; return(new JsonResult(jsonResult)); } else { var jsonResult = new { error = "Save model error" }; return(new JsonResult(jsonResult)); } } catch { var jsonResult = new { error = "Save model error" }; return(new JsonResult(jsonResult)); } } else { var jsonResult = new { error = "URL Verification Error" }; return(new JsonResult(jsonResult)); } } var jsonRErroresult = new { error = "Invalid or Nonexistent RedirectURL Error" }; return(new JsonResult(jsonRErroresult)); } else { var jsonResult = new { error = "Invalid model Error" }; return(new JsonResult(jsonResult)); } }