public void Shorten_WithNullLink_ShouldThrowArgumentException() { //Arrange var mockUnitOfWork = Mock.Of <IUnitOfWork>(); var mocklogger = Mock.Of <ILogger>(); var logic = new UrlLogic(mockUnitOfWork, mocklogger); //Act logic.Shorten(null); //Assert // ExpectedException Attribute }
public void Shorten_WithZeroId_ShouldThrowException() { //Arrange var mockLinkRepository = Mock.Of <IRepository <Link> >(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository); var mocklogger = Mock.Of <ILogger>(); var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger); var link = new Link() { LongUrl = "some url", Id = 0 }; //Act logic.Shorten(link); //Assert // ExpectedException Attribute }
public void Shorten_WithLink_ShouldCalculateShortUrl() { //Arrange var mockLinkRepository = Mock.Of <IRepository <Link> >(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository); var mocklogger = Mock.Of <ILogger>(); var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger); var link = new Link() { LongUrl = "some url", Id = 1 }; //Act logic.Shorten(link); //Assert link.ShortUrl.Should().NotBeNullOrEmpty("Shorten should calculate the ShortUrl Property"); }
public void Shorten_WithLink_ShouldCallRepositoryInsert() { //Arrange var mockLinkRepository = new Mock <IRepository <Link> >(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository.Object); var mocklogger = Mock.Of <ILogger>(); var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger); var link = new Link() { LongUrl = "some url", CreatedDate = DateTime.Now.AddDays(-1), Id = 1 }; //Act logic.Shorten(link); //Assert mockLinkRepository.Verify(x => x.Insert(link), "Link Repository should call insert when shortening a url"); }
public void Shorten_WithLink_ShouldSetCreatedDate() { //Arrange var mockLinkRepository = Mock.Of <IRepository <Link> >(); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.SetupGet(x => x.LinkRepository).Returns(mockLinkRepository); var mocklogger = Mock.Of <ILogger>(); var logic = new UrlLogic(mockUnitOfWork.Object, mocklogger); var link = new Link() { LongUrl = "some url", CreatedDate = DateTime.Now.AddDays(-1), Id = 1 }; //Act logic.Shorten(link); //Assert link.CreatedDate.Should().BeCloseTo(DateTime.Now, precision: 500, because: "Shorten should calculate the ShortUrl Property"); }