public void Lend_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.Lend("abcd", "edin", DateTime.Now);            
        }
        public void Lend_ShouldFailWithValidUserAndNonAvailableItem()
        {
            
            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.GetUser(It.IsAny<string>())).Returns(this.userList.Where(u => u.Username == "edin").First());
            store
                .Setup(x => x.IsAvailableForLending(It.IsAny<LibraryItem>(), It.IsAny<DateTime>())).Returns(false);

            var biblioteca = new BibliotecaService(store.Object);
            biblioteca.Lend("HEA1", "edin", DateTime.Now);
        }
        public void Lend_ShouldProceedWhenUserTriesToLendThirdBook()
        {
            var user = this.userList.Where(u => u.Username == "edin").First();
            user.AddLending(new LendingDetails(bookCatalog[0], user, DateTime.Now));
            user.AddLending(new LendingDetails(bookCatalog[1], user, DateTime.Now));

            var store = new Mock<IBibliotecaStore>();
            store.Setup(x => x.GetItem(It.IsAny<string>()))
                 .Returns((string id) => this.bookCatalog
                     .Where(b => b.ID == id)
                     .SingleOrDefault());
            store
                .Setup(x => x.GetUser(It.IsAny<string>())).Returns(user);
            store
                .Setup(x => x.IsAvailableForLending(It.IsAny<LibraryItem>(), It.IsAny<DateTime>())).Returns(true);
            store
                .Setup(x => x.AddLending(It.IsAny<LibraryItem>(), It.IsAny<User>(), It.IsAny<DateTime>()))
                .Verifiable();

            var biblioteca = new BibliotecaService(store.Object);
            biblioteca.Lend("HEL1", "edin", DateTime.Now);

            store.Verify();
        }
        public void Lend_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(true);

            var biblioteca = new BibliotecaService(store.Object);
            biblioteca.Lend("HEA1", "inexistent user", DateTime.Now);
        }