public void CanShortenUrl()
        {
            var userUrl = new UserDto()
            {
                Id = 1000,
                OriginalUrl = "http://google.com",
                AccessCount = 0,
                LastAccessedOn = DateTime.Now
            };

            var dbUserUrl = new Shorty.Data.UserUrl()
            {
                Id = 1000,

            };

            var repo = new Mock<IRepository>();
            repo.Setup(r => r.SaveUrl(It.IsAny<UserUrl>()))
                .Returns(() => dbUserUrl);

            var converter = new BaseConverter();
            shortener = new ShortService(converter, repo.Object);

            var result = shortener.ShortenUrl(userUrl);

            Assert.AreEqual("Ge", result.Url);
        }
Beispiel #2
0
        public bool DeleteUrl(UserUrl userUrl)
        {
            _context.Urls.Remove(userUrl);
            var operationResult = _context.SaveChanges();

            return operationResult > 0;
        }
        public void CanExpandUrl()
        {
            var dbUserUrl = new Shorty.Data.UserUrl()
            {
                Id = 1000,
                OriginalUrl = "http://google.com",
                AccessCount = 0,
            };

            var testUrl = "http://bitly.com/Ge";
            var repo = new Mock<IRepository>();
            repo.Setup(r => r.GetById(It.IsAny<int>())).Returns(() => dbUserUrl);

            var converter = new BaseConverter();
            shortener = new ShortService(converter, repo.Object);

            var result = shortener.ExpandUrl(testUrl);
        }
Beispiel #4
0
        public UserUrl SaveUrl(UserUrl userUrl)
        {
            if (userUrl.Id == 0)
            {
                _context.Urls.Add(userUrl);
            }
            else
            {
                _context.Entry(userUrl).State = EntityState.Modified;
            }

            var result = _context.SaveChanges();

            return userUrl;
        }