示例#1
0
        public void Expand_WithNullUrl_ShouldThrowArgumentException()
        {
            //Arrange
            var mockUnitOfWork = Mock.Of <IUnitOfWork>();
            var mocklogger     = Mock.Of <ILogger>();

            var logic = new UrlLogic(mockUnitOfWork, mocklogger);

            //Act
            logic.Expand(null);

            //Assert
            // ExpectedException Attribute
        }
示例#2
0
        public void Expand_WithInvalidShortUrl_ShouldThrowFormatException()
        {
            //Arrange
            var mockLinkRepository = new Mock <IRepository <Link> >();
            var mockUnitOfWork     = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository.Object);
            mockLinkRepository.Setup(x => x.GetByID(It.IsAny <int>())).Returns((Link)null);
            var mocklogger = Mock.Of <ILogger>();

            var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger);

            //Act
            logic.Expand("InvalidValule");

            //Assert
            // ExpectedException Attribute
        }
示例#3
0
        public void Expand_WithMissingUrl_ShouldThrowArgumentException()
        {
            //Arrange
            var mockLinkRepository = new Mock <IRepository <Link> >();
            var mockUnitOfWork     = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository.Object);
            mockLinkRepository.Setup(x => x.GetByID(0)).Returns((Link)null);
            var mocklogger = Mock.Of <ILogger>();

            var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger);

            //Act
            logic.Expand("AAAAAA");

            //Assert
            // ExpectedException Attribute
        }
示例#4
0
        public void Expand_WithValidShortUrl_ShouldIncrementClicks()
        {
            //Arrange
            var mockLinkRepository = new Mock <IRepository <Link> >();
            var mockUnitOfWork     = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository.Object);
            var link = new Link()
            {
                Clicks  = 0,
                LongUrl = "longUrl"
            };

            mockLinkRepository.Setup(x => x.GetByID(It.IsAny <int>())).Returns(link);
            var mocklogger = Mock.Of <ILogger>();

            var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger);

            //Act
            logic.Expand("AAAAAA");

            //Assert
            link.Clicks.ShouldBeEquivalentTo(1, because: "Expand should increment clicks by one");
        }