public void EditViewModelValidationErrorRepopulatesAuthorsDropdown()
        {
            //Arrange
            var    repository   = Mock.Create <IRepository>();
            int    bookId       = 1;
            int    authorId     = 3;
            string errorMessage = "The minimal length for the title is 3";
            var    book         = new BookEditViewModel()
            {
                AuthorId = AuthorHelper.RobertMartin(authorId).AuthorId,
                BookId   = BookHelper.CleanCode(bookId, authorId).BookId,
                Title    = "12", //Too short, min is 3 (defined in the view model)
                Genre    = BookHelper.CleanCode(bookId, authorId).Genre,
            };

            Mock.Arrange(() => repository.Save((Book)Arg.AnyObject)).OccursNever();
            var authorsList = new List <Author>()
            {
                AuthorHelper.RobertMartin(1), AuthorHelper.JRRTolkien(authorId)
            };

            Mock.Arrange(() => repository.GetAllAuthors()).Returns(authorsList).OccursOnce();

            //Act
            var controller = new HomeController(repository);

            controller.ModelState.AddModelError("Title", errorMessage);       //add the view model validation error
            controller.ControllerContext = Mock.Create <ControllerContext>(); //needed by TryValidateModel(entity)
            var result = controller.Edit(book) as ViewResult;

            //Assert
            StandardAssertsForEditErrors(controller, result, book, errorMessage);
            Mock.Assert(repository);
        }
        public void EditDBExceptionRepopulatesAuthorsDropdown()
        {
            //Arrange
            var repository       = Mock.Create <IRepository>();
            int bookId           = 1;
            int authorId         = 1;
            var exceptionMessage = "test exception with message";
            var book             = new BookEditViewModel()
            {
                AuthorId = AuthorHelper.RobertMartin(authorId).AuthorId,
                BookId   = BookHelper.CleanCode(bookId, authorId).BookId,
                Title    = BookHelper.CleanCode(bookId, authorId).Title,
                Genre    = BookHelper.CleanCode(bookId, authorId).Genre,
            };

            Mock.Arrange(() => repository.Save((Book)Arg.AnyObject)).Throws(new Exception(exceptionMessage)).OccursOnce();
            var authorsList = new List <Author>()
            {
                AuthorHelper.RobertMartin(1), AuthorHelper.JRRTolkien(authorId)
            };

            Mock.Arrange(() => repository.GetAllAuthors()).Returns(authorsList).OccursOnce();

            //Act
            var controller = new HomeController(repository);

            controller.ControllerContext = Mock.Create <ControllerContext>(); //needed by TryValidateModel(entity)
            var result = controller.Edit(book) as ViewResult;


            //Assert
            StandardAssertsForEditErrors(controller, result, book, exceptionMessage);
            Mock.Assert(repository);
        }
        public void EditIndexShowsBookEditFormWithBookContentWithPopulatedDropDownList()
        {
            //Arrange
            var repository = Mock.Create <IRepository>();
            var bookToEdit = BookHelper.CleanCode(bookId: 2, authorId: 1);

            Mock.Arrange(() => repository.GetBook(bookToEdit.BookId)).Returns(bookToEdit).OccursOnce();
            //called to populate the dropdownlist
            Mock.Arrange(() => repository.GetAllAuthors()).Returns(
                new List <Author>()
            {
                AuthorHelper.RobertMartin(1),
                AuthorHelper.RoyOsherove(2),
            }).OccursOnce();

            //Act
            var controller   = new HomeController(repository);
            var result       = controller.Edit(bookToEdit.BookId) as ViewResult;
            var model        = result.Model as BookEditViewModel;
            var selectedItem = model.Authors.Find(b => Int32.Parse(b.Value) == bookToEdit.AuthorId);

            //Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(model.BookId, bookToEdit.BookId);
            Assert.AreEqual(model.AuthorId, bookToEdit.AuthorId);
            Assert.AreEqual(model.Genre, bookToEdit.Genre);
            Assert.AreEqual(model.Title, bookToEdit.Title);
            Assert.IsTrue(selectedItem.Selected);
            Assert.IsNull(result.ViewBag.Message);
            Mock.Assert(repository);
        }
示例#4
0
        private void Button2_Click(object sender, EventArgs e)
        {
            Book newBook = new Book
            {
                Name = textBox1.Text
            };

            List <Author> authors = new List <Author>();

            foreach (var item in listBox1.SelectedItems)
            {
                authors.Add(AuthorHelper.MapAuthorModel((AuthorModel)item));
            }

            newBook.Authors = authors;

            List <Genre> genres = new List <Genre>();

            foreach (var item in listBox2.SelectedItems)
            {
                genres.Add(GenreHelper.MapGenreModel((GenreModel)(item)));
            }

            newBook.Genres    = genres;
            newBook.PageCount = Convert.ToInt32(textBox2.Text);

            bool isAdded = BookHelper.Addbook(newBook);

            if (isAdded)
            {
                this.LoadBooks();
            }
        }
示例#5
0
 public IResult Update(Profile profile, int reqUserId)
 {
     if (!AuthorHelper.OwnerAccess(profile.UserId, reqUserId))
     {
         return(new Result(false, Messages.OwnerAccess));
     }
     _profileDal.Update(profile);
     return(new Result(true, Messages.Updated));
 }
示例#6
0
        private void button2_Click(object sender, EventArgs e)
        {
            Author newAuthor = new Author
            {
                Name = textBox2.Text
            };

            AuthorHelper.AddAuthor(newAuthor);
            ListAuthors();
        }
示例#7
0
        private void AdminSayfa_Load(object sender, EventArgs e)
        {
            loggedPerson = Form1.loggedPerson;
            label2.Text  = loggedPerson.FirstName + " " + loggedPerson.LastName;

            label5.Text = GenreHelper.TotalGenreCount().ToString();
            label7.Text = PersonHelper.TotalPersonCount().ToString();
            label8.Text = AuthorHelper.TotalAuthorCount().ToString();
            label9.Text = BookHelper.TotalBookCount().ToString();
        }
示例#8
0
        public MessageDaoTests()
        {
            _authorHelperStub = new AuthorHelper();

            var dbContextOptionsBuilder = new DbContextOptionsBuilder <MessageBoardDbContext>();

            dbContextOptionsBuilder.UseInMemoryDatabase(Assembly.GetAssembly(typeof(MessageDaoTests)).GetName().Name);
            _dbContext = new MessageBoardDbContext(dbContextOptionsBuilder.Options);

            _dao = new MessageDao(_dbContext, _authorHelperStub);
        }
示例#9
0
        private void Kitaplar_Load(object sender, EventArgs e)
        {
            LoadBooks();

            List <AuthorModel> authors = AuthorHelper.MapAuthorEntity(AuthorHelper.ListAuthors());

            listBox1.DataSource    = authors;
            listBox1.SelectionMode = SelectionMode.MultiSimple;

            List <GenreModel> genres = GenreHelper.MapGenreEntity(GenreHelper.ListGenres());

            listBox2.DataSource    = genres;
            listBox2.SelectionMode = SelectionMode.MultiSimple;
        }
示例#10
0
        public static void Main()
        {
            MemberHelper memberHelper = new MemberHelper();

            memberHelper.AddMember("Maryam", "Airport", 033267888);
            AuthorHelper authorHelper = new AuthorHelper();

            authorHelper.AddAuthor("Mark Ryan");
            BookHelper bookHelper = new BookHelper();

            bookHelper.AddBook("Calculus", 3);
            BookIssueHelper bookIssueHelper = new BookIssueHelper();

            bookIssueHelper.AddBookIssue("23-12-2020", 2, 3);
        }
示例#11
0
        public IResult Update(Advert advert)
        {
            try
            {
                if (!AuthorHelper.OwnerAccess(advert.UserId, advert.User.Id))
                {
                    return(new Result(false, Messages.OwnerAccess));
                }

                _advertDal.Update(advert);
                return(new Result(true, Messages.Updated));
            }
            catch (Exception error)
            {
                return(new Result(false, error.Message));
            }
        }
        public void CreateWithDBExceptionAddsErrorToModelStateAndRepopulatesAuthorsDropdown()
        {
            //Arrange
            var repository       = Mock.Create <IRepository>();
            int bookId           = 1;
            int authorId         = 1;
            var exceptionMessage = "Unable to save changes. Try again, and if the problem persists, see your system administrator.";
            var book             = new BookEditViewModel()
            {
                AuthorId = AuthorHelper.RobertMartin(authorId).AuthorId,
                BookId   = BookHelper.CleanCode(bookId, authorId).BookId,
                Title    = BookHelper.CleanCode(bookId, authorId).Title,
                Genre    = BookHelper.CleanCode(bookId, authorId).Genre,
            };

            Mock.Arrange(() => repository.CreateBook((Book)Arg.AnyObject)).Throws(new Exception()).OccursOnce();
            var authorsList = new List <Author>()
            {
                AuthorHelper.RobertMartin(1), AuthorHelper.JRRTolkien(authorId)
            };

            Mock.Arrange(() => repository.GetAllAuthors()).Returns(authorsList).OccursOnce();

            //Act
            var controller = new HomeController(repository);

            controller.ControllerContext = Mock.Create <ControllerContext>(); //needed by TryValidateModel(entity)
            var result         = controller.Create(book) as ViewResult;
            var model          = result.Model as BookEditViewModel;
            var errorStates    = from m in controller.ModelState.Values select m.Errors;
            var selectedAuthor = model.Authors.Find(a => a.Selected);

            //Assert
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(exceptionMessage, errorStates.First().First().ErrorMessage);
            Assert.AreEqual(book.AuthorId.ToString(), selectedAuthor.Value);
            Assert.IsNull(controller.ViewBag.Message);
            Assert.IsNull(controller.TempData["Message"]);
            Mock.Assert(repository);
        }
        public void CreateIndexShowsEmptyCreationFormWithPopulatedDropDownList()
        {
            //Arrange
            var repository  = Mock.Create <IRepository>();
            var authorsList = new List <Author>()
            {
                AuthorHelper.RobertMartin(1), AuthorHelper.JRRTolkien(2)
            };

            Mock.Arrange(() => repository.GetAllAuthors()).Returns(authorsList).OccursOnce();

            //Act
            var        controller = new HomeController(repository);
            ViewResult result     = controller.Create();
            var        model      = result.Model as BookEditViewModel;

            //Assert
            Assert.IsInstanceOfType(model, typeof(BookEditViewModel));
            Assert.AreEqual(2, model.Authors.Count);
            Assert.IsFalse(model.Authors.Exists(a => a.Selected));
            Assert.IsNull(result.ViewBag.Message);
            Mock.Assert(repository);
        }
        public void FindByGenreReturnsAllInGenre()
        {
            //Arrange
            var repository = Mock.Create <IRepository>();

            Mock.Arrange(() => repository.GetBooksByGenre(BookHelper.ArtOfUnitTesting(1).Genre)).Returns(new List <Book>()
            {
                BookHelper.ArtOfUnitTesting(1),
                BookHelper.CleanCode(2)
            }).MustBeCalled();

            //Act
            var        controller = new HomeController(repository);
            ViewResult result     = controller.FindByGenre("Programming");
            var        model      = result.Model as IEnumerable <Book>;

            //Assert
            Assert.AreEqual(2, model.Count());
            Assert.AreEqual(AuthorHelper.RoyOsherove().FullName, model.ToList()[0].Author.FullName);
            Assert.AreEqual(AuthorHelper.RobertMartin().FullName, model.ToList()[1].Author.FullName);
            Assert.AreEqual(BookHelper.ArtOfUnitTesting().Title, model.ToList()[0].Title);
            Assert.AreEqual(BookHelper.CleanCode().Title, model.ToList()[1].Title);
            Mock.Assert(repository);
        }
示例#15
0
 public BookController(BookService service, AuthorService authorService, PublishingHouseService publishingHouseService)
 {
     this.service          = service;
     authorHelper          = new AuthorHelper(authorService);
     publishingHouseHelper = new PublishingHouseHelper(publishingHouseService);
 }
示例#16
0
 public AuthorFilterAttribute(AuthorHelper authorHelper)
 {
     _authorHelper = authorHelper;
 }
示例#17
0
 private void ListAuthors()
 {
     dataGridView1.DataSource = AuthorHelper.ListAuthors();
 }
示例#18
0
        /// <summary>
        /// loads the information of a book from an online source
        /// </summary>
        public Book AutoLoadDNB(string isbn)
        {
            Book book = new Book();

            book.BookIsbn = isbn;
            if (IsbnValidated(isbn))
            {
                htmlData = Regex.Replace(htmlData, @"\t|\n|\r", "");
                htmlData = Regex.Replace(htmlData, "<a href=.*?>", "");
                var genreName = GetGenreNeu().Replace("[", "(").Replace("]", ")");
                if (!genreName.Equals(""))
                {
                    GenreHelper helper = new GenreHelper();
                    Genre       genre  = new Genre();
                    if (helper.FindIdByName(genreName) < 0)
                    {
                        genre.GenreName = genreName;
                        genre.Add();
                    }
                    genre          = new Genre(helper.FindIdByName(genreName));
                    book.BookGenre = genre;
                }

                var titel = GetTitelNeu().Replace("[", "(").Replace("]", ")");
                if (!titel.Equals(""))
                {
                    book.BookTitle = titel;
                }

                var authors = GetAutorNeu();
                foreach (string s in authors)
                {
                    Author       author = new Author();
                    AuthorHelper helper = new AuthorHelper();
                    if (helper.FindIdByName(s) < 0)
                    {
                        author.AuthorName = s;
                        author.Add();
                    }
                    author = new Author(helper.FindIdByName(s));
                    book.BookAuthors.Add(author);
                }

                var ausgabe = GetAusgabeNeu().Replace("[", "(").Replace("]", ")");
                if (!ausgabe.Equals(""))
                {
                    book.BookEdition = ausgabe;
                }

                var publisherName = GetVerlagNeu().Replace("[", "(").Replace("]", ")");
                if (!publisherName.Equals(""))
                {
                    PublisherHelper helper    = new PublisherHelper();
                    Publisher       publisher = new Publisher();
                    if (helper.FindIdByName(publisherName) < 0)
                    {
                        publisher.PublisherName = publisherName;
                        publisher.Add();
                    }
                    publisher          = new Publisher(helper.FindIdByName(publisherName));
                    book.BookPublisher = publisher;
                }

                var jahr = GetDatumNeu();
                if (!jahr.Equals(""))
                {
                    try
                    {
                        DateTime date = new DateTime(int.Parse(jahr), 1, 1);
                        book.BookDatePublication = date;
                    }
                    catch
                    {
                        book.BookDatePublication = DateTime.UtcNow;
                    }
                }

                var preis = GetPreisNeu().Replace('.', ',');
                if (!preis.Equals(""))
                {
                    book.BookPrice = decimal.Parse(preis);
                }

                var languageName = GetSpracheNeu().Replace("[", "(").Replace("]", ")");
                if (!languageName.Equals(""))
                {
                    LanguageHelper helper   = new LanguageHelper();
                    Language       language = new Language();
                    if (helper.FindIdByName(languageName) < 0)
                    {
                        language.LanguageName = languageName;
                        language.Add();
                    }
                    language          = new Language(helper.FindIdByName(languageName));
                    book.BookLanguage = language;
                }

                var image = GetPictureNeu(isbn);
                if (image != null)
                {
                    book.BookImage = image;
                }
                return(book);
                //MetroMessageBox.Show(this, "Das Buch \"" + tb_Titel.Text + "\" wurde erfolgreich geladen!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                return(book);
                //AutoLoadBuecherNachISBN();
            }
        }
示例#19
0
 public MessageDao(MessageBoardDbContext dbContext, AuthorHelper authorHelper)
 {
     _dbContext    = dbContext;
     _authorHelper = authorHelper;
 }