Esempio n. 1
0
 public ActionResult GetStats(string code)
 {
     try
     {
         string   host = ApplicationEnv.GetApiUrl(HttpContext);
         ShortUrl url  = ShortUrlBusiness.Stats(code);
         var      dto  = new ShortUrlDTO(url, host, fullData: true);
         dto.countClick = ClickBusiness.CountClicksByCode(code);
         return(Ok(dto));
     }
     catch (ShortUrlException e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 2
0
        public void Test_ClickedAndStats()
        {
            int clicksToShow = 10; // This could be as system parameter
            int clickCount   = clicksToShow + 4;

            ShortUrl url = ShortUrlBusiness.MakeShortUrl(referenceURL);

            for (int i = 0; i < clickCount; i++)
            {
                ShortUrlBusiness.Clicked(url.Code, fakeIp);
            }

            ShortUrl urlStats = ShortUrlBusiness.Stats(url.Code);
            long     counted  = ClickBusiness.CountClicksByCode(url.Code);

            Assert.Equal(clicksToShow, urlStats.ClickList.Count);
            Assert.Equal(clickCount, counted);
        }