Beispiel #1
0
        public void Test_ValidURL()
        {
            // ARRANGE
            UrlChecker checker = new UrlChecker();
            string     url     = "http://www.ucll.be";

            // ACT
            bool isValid = checker.CheckUrl(url);

            // ASSERT
            Assert.IsTrue(isValid, "Dit zou een geldige url moeten zijn.");
        }
Beispiel #2
0
        public void Test_InvalidURL()
        {
            // ARRANGE
            UrlChecker checker = new UrlChecker();
            string     url     = "foo";

            // ACT
            bool isValid = checker.CheckUrl(url);

            // ASSERT
            Assert.IsFalse(isValid, "Dit zou een ongeldige url moeten zijn.");
        }
Beispiel #3
0
        public IActionResult OnPost(string code, string address)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Redirect("/"));
            }

            if (code.Equals("links", StringComparison.OrdinalIgnoreCase))
            {
                SetErrorMessage("Short address can't be 'links'. It is reserved!");
                return(Page());
            }

            code = code.ToLower();

            Initialize(code);

            if (string.IsNullOrEmpty(address))
            {
                SetErrorMessage("You need to enter an address!");
                return(Page());
            }

            if (!UrlChecker.CheckUrl(address))
            {
                SetErrorMessage("You need to enter a full valid address!");

                return(Page());
            }

            using (var db = new GoContext())
            {
                var link = db.Links.FirstOrDefault(f => f.Code.Equals(code));
                if (link == null)
                {
                    link      = new Link();
                    link.Code = code;

                    db.Links.Add(link);
                }

                link.Url       = address;
                link.UpdatedAt = DateTime.UtcNow;

                db.SaveChanges();

                Address = address;

                SetSuccessMessage("Your short link was saved.");
            }

            return(Page());
        }
Beispiel #4
0
 private void textBox1_TextChanged(object sender, EventArgs e)
 {
     if (_urlChecker.CheckUrl(textBox1.Text))
     {
         textBox1.BackColor = Color.Green;
         Uri uri = new Uri(textBox1.Text);
         textBoxHost.Text = uri.Host;
         textBoxPath.Text = uri.LocalPath;
     }
     else
     {
         textBox1.BackColor = Color.Red;
     }
 }
 static void Main(string[] args)
 {
     while (true)
     {
         System.Console.Write("URL (press Q to quit): ");
         string url = System.Console.ReadLine();
         if (url.ToUpper() == "Q")
         {
             break;
         }
         if (_urlChecker.CheckUrl(url))
         {
             System.Console.ForegroundColor = ConsoleColor.Green;
             System.Console.WriteLine("OK.");
         }
         else
         {
             System.Console.ForegroundColor = ConsoleColor.Red;
             System.Console.WriteLine("Not a valid URL.");
         }
         System.Console.ResetColor();
     }
 }