public void Throw_If_ParamethersCount_IsInvalid() { var parameters = new List <string>() { "title", "author", "genre" }; var genreServiceMock = new Mock <IGenreServices>(); var authorServiceMock = new Mock <IAuthorServices>(); var bookServiceMock = new Mock <IBooksServices>(); var command = new AddBookCommand(bookServiceMock.Object, genreServiceMock.Object, authorServiceMock.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 ShouldAddBookrToRepository() { var bookRepository = new BookRepository(); uint quantity = 1; var title = "A Game of Thrones"; var author = "George R. R. Martin"; var consoleOperator = new Mock <IConsoleOperator>(); consoleOperator.Setup(x => x.GetBookDescriptionWithQuantity()).Returns((title, author, quantity, true)); var addBookCommand = new AddBookCommand(bookRepository, consoleOperator.Object); addBookCommand.Execute(); Assert.Single(bookRepository.Book); Assert.Equal(bookRepository.Book.Count, (int)quantity); Assert.Contains(bookRepository.Book.FirstOrDefault().BookDescription.Title, title); Assert.Contains(bookRepository.Book.FirstOrDefault().BookDescription.Author, author); }
public void Call_BookService_AddBook_Once() { var parameters = new List <string>() { "title", "genre", "author", "1" }; var genreServiceMock = new Mock <IGenreServices>(); var authorServiceMock = new Mock <IAuthorServices>(); var bookServiceMock = new Mock <IBooksServices>(); var command = new AddBookCommand(bookServiceMock.Object, genreServiceMock.Object, authorServiceMock.Object); genreServiceMock.Setup(x => x.AddGenre(It.IsAny <string>())).Returns(1); authorServiceMock.Setup(x => x.AddAuthor(It.IsAny <string>())).Returns(1); bookServiceMock.Setup(x => x.AddBook(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(new BookViewModel() { Title = parameters[0] }); command.Execute(parameters); bookServiceMock.Verify(b => b.AddBook(parameters[0], 1, 1, parameters[3]), Times.Once()); }
public void Return_SuccessMessage() { var parameters = new List <string>() { "title", "genre", "author", "1" }; var genreServiceMock = new Mock <IGenreServices>(); var authorServiceMock = new Mock <IAuthorServices>(); var bookServiceMock = new Mock <IBooksServices>(); var command = new AddBookCommand(bookServiceMock.Object, genreServiceMock.Object, authorServiceMock.Object); genreServiceMock.Setup(x => x.AddGenre(It.IsAny <string>())).Returns(1); authorServiceMock.Setup(x => x.AddAuthor(It.IsAny <string>())).Returns(1); bookServiceMock.Setup(x => x.AddBook(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(new BookViewModel() { Title = parameters[0] }); var message = command.Execute(parameters); Assert.AreEqual($"New book {parameters[0]} was added.", message); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t', '\'' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "help": HelpCommand help = new HelpCommand(); result = help.Execute(inputArgs); break; case "ExportToJson": ExportToJsonCommand exportToJson = new ExportToJsonCommand(); result = exportToJson.Execute(inputArgs); break; case "ChangeRole": ChangeRoleCommand changeRole = new ChangeRoleCommand(); result = changeRole.Execute(inputArgs); break; case "clear": ClearCommand clear = new ClearCommand(); result = clear.Execute(inputArgs); break; case "ShowAllUsers": ShowAllUserCommand showAllUsers = new ShowAllUserCommand(); result = showAllUsers.Execute(inputArgs); break; case "AddTown": AddTownCommand addTown = new AddTownCommand(); result = addTown.Execute(inputArgs); break; case "ModifyUser": ModifyUserCommand modifyUser = new ModifyUserCommand(); result = modifyUser.Execute(inputArgs); break; case "AddBook": AddBookCommand addBook = new AddBookCommand(); result = addBook.Execute(inputArgs); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(inputArgs); break; case "Login": LoginCommand login = new LoginCommand(); result = login.Execute(inputArgs); break; case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.Execute(inputArgs); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }