public void Throw_If_ParamethersCount_IsInvalid() { var parameters = new List <string>() { "Fname", "Mname", "Lname" }; var userServiceMock = new Mock <IUsersServices>(); var command = new BorrowBookCommand(userServiceMock.Object); command.Execute(parameters); }
public void ShouldBorrowBookToRepository() { var userRepository = new UserRepository(); var firstName = "Kinga"; var surName = "Sadowska"; var bookRepository = new BookRepository(); var title = "A Game of Thrones"; var author = "George R. R. Martin"; var quantity = 1; var consoleOperator = new Mock <IConsoleOperator>(); consoleOperator.Setup(x => x.GetUser()).Returns((firstName, surName, true)); consoleOperator.Setup(x => x.WriteLine(It.IsAny <string>())); consoleOperator.Setup(x => x.GetBookDescription()).Returns((title, author, true)); consoleOperator.Setup(x => x.GetBookDescriptionWithQuantity()).Returns((title, author, (uint)quantity, true)); var addUserCommand = new AddUserCommand(userRepository, consoleOperator.Object); addUserCommand.Execute(); var addBookCommand = new AddBookCommand(bookRepository, consoleOperator.Object); addBookCommand.Execute(); Assert.Single(userRepository.Users); Assert.Single(bookRepository.Book); var borrowBookCommand = new BorrowBookCommand(bookRepository, userRepository, consoleOperator.Object); borrowBookCommand.Execute(); Book first = null; foreach (var book in bookRepository.Book) { first = book; break; } Assert.Equal(first.CurrentBorrowing.User.FirstName, firstName); Assert.Equal(bookRepository.Book.FirstOrDefault().CurrentBorrowing.User.LastName, surName); Assert.True(bookRepository.Book.FirstOrDefault().IsCurrentBorrowed); }
public void Call_UserService() { var parameters = new List <string>() { "Fname", "Mname", "Lname", "BookTitle" }; string fullName = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2]; var userServiceMock = new Mock <IUsersServices>(); var command = new BorrowBookCommand(userServiceMock.Object); userServiceMock.Setup(u => u.BorrowBook(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(new UserViewModel() { FullName = fullName }); command.Execute(parameters); userServiceMock.Verify(u => u.BorrowBook(parameters[0], parameters[1], parameters[2], parameters[3]), Times.Once); }
public void Return_SuccessMessage() { var parameters = new List <string>() { "Fname", "Mname", "Lname", "BookTitle" }; string fullName = parameters[0] + ' ' + parameters[1] + ' ' + parameters[2]; var userServiceMock = new Mock <IUsersServices>(); var command = new BorrowBookCommand(userServiceMock.Object); userServiceMock.Setup(u => u.BorrowBook(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(new UserViewModel() { FullName = fullName }); string message = command.Execute(parameters); Assert.AreEqual($"User {fullName} borrow the book {parameters[3]}", message); }