コード例 #1
0
        bool IOptionHandle.Execute()
        {
            Book book = new Book();

            Console.WriteLine("Ingrese los datos del libro:");
            Console.Write("ISBN: ");
            book.Isbn = Console.ReadLine();
            Console.Write("Titulo: ");
            book.Title = Console.ReadLine();
            Console.Write("Autor: ");
            book.Author = Console.ReadLine();
            try
            {
                IBookRepository repository = RepositoryFactory.CreateBookRepository("json", GetCurrentPath());
                BookRules       rules      = new BookRules(repository);
                rules.Add(book);
                Console.WriteLine($"El libro ha sido creado, Total libros: {rules.Count()}");
                Console.WriteLine();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine();
                Console.Error.WriteLine($"\t{ex.Message}");
                Console.WriteLine();
                Console.WriteLine();
            }
            return(true);
        }
コード例 #2
0
        public void DuplicatedTitle()
        {
            var book1 = new Book {
                Isbn   = "1233434234334",
                Title  = "Don quijote de la mancha",
                Author = "Miguel Servantes"
            };

            IBookRepository repo = NSubstitute.Substitute.For <IBookRepository>();

            repo.Exists(Arg.Any <Book>()).Returns(true);
            var rules = new BookRules(repo);

            Assert.That(() => rules.Add(book1),
                        Throws.TypeOf <ArgumentException>().With.Message.Contains("Duplicated Book"));
        }
コード例 #3
0
        public void ValidTitle(string title)
        {
            //Arrange
            Book book = new Book
            {
                Isbn   = "1234567890123",
                Title  = title,
                Author = "Gabriel Garcia Marquez"
            };
            //Act
            IBookRepository repo  = NSubstitute.Substitute.For <IBookRepository>();
            BookRules       rules = new BookRules(repo);

            //Assert
            rules.Add(book);
            Assert.Pass();
        }
コード例 #4
0
        public void ValidAuthor(string author)
        {
            //Arrange
            Book book = new Book
            {
                Isbn   = "1234567890123",
                Title  = "Don quijote de la mancha",
                Author = author
            };
            //Act
            IBookRepository repo  = NSubstitute.Substitute.For <IBookRepository>();
            BookRules       rules = new BookRules(repo);

            //Assert
            rules.Add(book);
            Assert.Pass();
        }
コード例 #5
0
        public void InvalidTitle(string title)
        {
            //Arrange
            Book book = new Book
            {
                Isbn   = "1234567890123",
                Title  = title,
                Author = "Gabriel Garcia Marquez"
            };

            //Act
            IBookRepository repo  = NSubstitute.Substitute.For <IBookRepository>();
            BookRules       rules = new BookRules(repo);

            //Assert
            Assert.That(() => rules.Add(book),
                        Throws.TypeOf <ArgumentException>().With.Message.Contains("Invalid Title"));
        }
コード例 #6
0
        public void ValidISBN(string isbn)
        {
            //Arrange
            Book book = new Book
            {
                Title  = "Don Quijote de la mancha",
                Isbn   = isbn,
                Author = "Gabriel Garcia Marquez"
            };

            //Act
            IBookRepository repo  = NSubstitute.Substitute.For <IBookRepository>();
            BookRules       rules = new BookRules(repo);

            //Assert
            rules.Add(book);
            Assert.Pass();
        }
コード例 #7
0
        public void InvalidAuthor(string author)
        {
            //Arrange
            Book book = new Book
            {
                Isbn   = "1234567890123",
                Title  = "Don quijote de la mancha",
                Author = author
            };

            //Act
            IBookRepository repo  = NSubstitute.Substitute.For <IBookRepository>();
            BookRules       rules = new BookRules(repo);

            //Assert
            Assert.That(() => rules.Add(book),
                        Throws.TypeOf <ArgumentException>().With.Message.Contains("Invalid Author"));
        }