public void Return_ShouldBlockUserWhenExceedingTheReturnPeriod() { var returnDate = DateTime.Now.AddDays(40); var user = this.userList.Where(u => u.Username == "edin").First(); user.AddLending(new LendingDetails(bookCatalog[0], user, DateTime.Now)); var store = new Mock<IBibliotecaStore>(); store .Setup(x => x.GetItem(It.Is<string>(i => i == "HEA1"))) .Returns(this.bookCatalog .Where(b => b.ID == "HEA1") .FirstOrDefault()); store .Setup(x => x.IsAvailableForLending(It.IsAny<LibraryItem>(), It.IsAny<DateTime>())).Returns(false); store .Setup(x => x.GetUser(It.IsAny<string>())).Returns(user); store .Setup(x => x.RemoveLending(It.IsAny<LibraryItem>(), It.IsAny<User>(), It.IsAny<DateTime>())) .Verifiable(); store .Setup(x => x.BlockUser(It.IsAny<User>())) .Verifiable(); var biblioteca = new BibliotecaService(store.Object); var userStatus = biblioteca.Return("HEA1", "edin", returnDate); store.Verify(); Assert.AreEqual(UserStatus.Blocked, userStatus); }
public void Return_ShouldThrowExceptionWhenUserIsNotValid() { var store = new Mock<IBibliotecaStore>(); store.Setup(x => x.GetItem(It.Is<string>(i => i == "HEA1"))) .Returns(this.bookCatalog .Where(b => b.ID == "HEA1") .FirstOrDefault()); store.Setup(x => x.IsAvailableForLending(It.IsAny<LibraryItem>(), It.IsAny<DateTime>())).Returns(false); var biblioteca = new BibliotecaService(store.Object); biblioteca.Return("HEA1", "inexistent user", DateTime.Now); }
public void Return_ShouldThrowExceptionWhenUserHasNoValidLending() { var user = this.userList.Where(u => u.Username == "edin").First(); var store = new Mock<IBibliotecaStore>(); store .Setup(x => x.GetItem(It.Is<string>(i => i == "HEA1"))) .Returns(this.bookCatalog .Where(b => b.ID == "HEA1") .FirstOrDefault()); store .Setup(x => x.IsAvailableForLending(It.IsAny<LibraryItem>(), It.IsAny<DateTime>())).Returns(false); store .Setup(x => x.GetUser(It.IsAny<string>())).Returns(user); var biblioteca = new BibliotecaService(store.Object); biblioteca.Return("HEA1", "edin", DateTime.Now); }
public void Return_ShouldThrowExceptionWhenBookIsNotInCatalog() { var store = new Mock<IBibliotecaStore>(); store.Setup(x => x.GetItem(It.Is<string>(i => i == "abcd"))).Returns((LibraryItem)null); var biblioteca = new BibliotecaService(store.Object); biblioteca.Return("abcd", "edin", DateTime.Now); }