Example #1
0
        // Test whether URL passed to 'ShortenURLService' is corretly stored in DB
        public void CheckShortenURL()
        {
            var    jsonText         = File.ReadAllText(System.IO.Path.GetFullPath(@"..\..\..\appsettings.json"));
            var    connectionString = JsonConvert.DeserializeObject <Config> (jsonText);
            var    thisMD5Svc       = new MD5HashService();
            var    thisDb           = new URLDBContext(connectionString.ConnectionStrings);
            string testURL          = "https://www.abc.net.au/news/2019-07-18/caleb-ewan-delivers-a-stage-winner-in-his-debut-tour/11320128?section=sport";
            var    svc    = new ShortenURLService(thisDb, thisMD5Svc);
            var    result = svc.getShortURL(testURL);
            var    id     = Int64.Parse(Utils.Base64Decode(result));

            Assert.AreEqual(testURL, thisDb.Url.Where(x => x.Id == id).FirstOrDefault().Url1);
        }
Example #2
0
        //Check service does not create duplicate records

        public void checkExpandedURL()
        {
            var jsonText         = File.ReadAllText(System.IO.Path.GetFullPath(@"..\..\..\appsettings.json"));
            var connectionString = JsonConvert.DeserializeObject <Config>(jsonText);
            var thisMD5Svc       = new MD5HashService();
            var thisDb           = new URLDBContext(connectionString.ConnectionStrings);

            string testURL      = "https://www.abc.net.au/news/2019-07-18/caleb-ewan-delivers-a-stage-winner-in-his-debut-tour/11320128?section=sport";
            var    svc          = new ShortenURLService(thisDb, thisMD5Svc);
            var    result       = svc.getShortURL(testURL);
            var    actualResult = svc.getExpandedURL(result);


            Assert.AreEqual(testURL, actualResult);
        }