Ejemplo n.º 1
0
        public void Add(string bookName, string isbn13, string isbn10, string author, string genre, string publisher, string published, string listPrice, string coverLink, OnError <String> onError, OnSuccess onSucess)
        {
            string   error = "";
            BookItem book  = new BookItem();

            if (bookName.Length == 0)
            {
                error += "Book Name is mandatory field\n";
            }
            book.Name   = bookName;
            book.ISBN13 = isbn13;
            if (!CheckExtension.CheckISBN13(isbn13))
            {
                error += "Wrong ISBN-13 Code. No spaces, letters, punctuations. ISBN must have 13 numbers\n";
            }
            book.ISBN10 = isbn10;
            if (!CheckExtension.CheckISBN10(isbn10))
            {
                error += "Wrong ISBN-10 Code. No spaces, letters, punctuations. ISBN must have 10 numbers\n";
            }
            if (author.Length == 0)
            {
                error += "Author is mandatory field\n";
            }
            book.Author = author;
            if (genre.Length == 0)
            {
                error += "Genre is mandatory field\n";
            }
            book.Genre     = genre;
            book.Publisher = publisher;
            if (!CheckExtension.CheckPublished(published))
            {
                error += "Wrong Published Date format. Example: 2018\n";
            }
            else
            {
                book.Published = int.Parse(published);
            }
            if (!CheckExtension.CheckListPrice(listPrice))
            {
                error += "Wrong ListPrice format\n";
            }
            else
            {
                double.TryParse(listPrice, out double x);
                book.ListPrice = x;
            }

            book.CoverLink = coverLink;
            if (error.Length == 0)
            {
                SQLConnection.AddNewItem(book);
                onSucess();
            }
            else
            {
                onError(error);
            }
        }
Ejemplo n.º 2
0
        public void CheckPublishedDate_WithWrongInput_ReturnFalse2()
        {
            //Arrange
            string date = "301";
            //Act
            bool result = CheckExtension.CheckPublished(date);

            //Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 3
0
        public void CheckPublishedDate_WithValidInput_ReturnTrue()
        {
            //Arrange
            string      date    = "2018";
            User        user    = new User();
            AddBookForm addBook = new AddBookForm(user);

            //Act
            bool result = CheckExtension.CheckPublished(date);

            //Assert
            Assert.IsTrue(result);
        }