예제 #1
0
        public void InputFieldsUpdated_Test_Valid_HasImageFilePath(string longTitle, string isbnFieldText, string isbn13FieldText, string deweyDecimalFieldText,
                                                                   string ext)
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.TitleFieldText).Returns("title");
            A.CallTo(() => fakeView.LongTitleFieldText).Returns(longTitle);
            A.CallTo(() => fakeView.LanguageFieldText).Returns("English");
            A.CallTo(() => fakeView.PagesFieldText).Returns("60");
            A.CallTo(() => fakeView.SelectedPublisher).Returns("publisher");
            A.CallTo(() => fakeView.Isbn13FieldText).Returns(isbn13FieldText);
            A.CallTo(() => fakeView.IsbnFieldText).Returns(isbnFieldText);
            A.CallTo(() => fakeView.DeweyDecimalFieldText).Returns(deweyDecimalFieldText);
            A.CallTo(() => fakeView.ImageFilePathFieldText).Returns(@"C:\path\to\file." + ext);
            var fakeBookService         = A.Fake <IBookService>();
            var fakeTagService          = A.Fake <ITagService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookService, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            presenter.InputFieldsUpdated(null, null);

            // assert
            Assert.IsTrue(fakeView.SaveButtonEnabled);
        }
예제 #2
0
        public void HandleTagCheckedChanged_Test()
        {
            // arrange
            var           fakeView     = A.Fake <IAddBookForm>();
            List <string> selectedTags = new List <string> {
                "tag1"
            };
            List <string> unselectedTags = new List <string> {
                "tag2"
            };

            A.CallTo(() => fakeView.SelectedTags).Returns(selectedTags);
            A.CallTo(() => fakeView.UnselectedTags).Returns(unselectedTags);
            var fakeBookService                 = A.Fake <IBookService>();
            var fakeTagService                  = A.Fake <ITagService>();
            var fakeImageFileReader             = A.Fake <IImageFileReader>();
            var fakeAuthorService               = A.Fake <IAuthorService>();
            var fakePublisherService            = A.Fake <IPublisherService>();
            MockBookPresenter         presenter = new MockBookPresenter(fakeBookService, fakeTagService, fakeAuthorService, fakePublisherService, fakeView, fakeImageFileReader);
            Dictionary <string, bool> allTags   = new Dictionary <string, bool>();

            allTags.Add("tag1", false);
            allTags.Add("tag2", true);
            presenter.SetAllTags(allTags);

            // act
            presenter.HandleTagCheckedChanged(null, null);

            // assert
            Assert.IsTrue(presenter.GetAllTagsValueByKey("tag1"));
            Assert.IsFalse(presenter.GetAllTagsValueByKey("tag2"));
        }
예제 #3
0
        public async Task SaveButtonClicked_Test_ErrorReadingImageFile()
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.TitleFieldText).Returns("test_book");
            A.CallTo(() => fakeView.LongTitleFieldText).Returns("test_book");
            A.CallTo(() => fakeView.IsbnFieldText).Returns("0123456789");
            A.CallTo(() => fakeView.ImageFilePathFieldText).Returns(@"C:\path\to\image.jpeg");
            A.CallTo(() => fakeView.SelectedPublisher).Returns("some_publisher");
            A.CallTo(() => fakeView.PagesFieldText).Returns("100");
            A.CallTo(() => fakeView.LanguageFieldText).Returns("English");
            var fakeBookService      = A.Fake <IBookService>();
            var fakeTagService       = A.Fake <ITagService>();
            var fakeAuthorService    = A.Fake <IAuthorService>();
            var fakePublisherService = A.Fake <IPublisherService>();
            var fakeImageFileReader  = A.Fake <IImageFileReader>();

            A.CallTo(() => fakeImageFileReader.ReadBytes()).Throws(new System.IO.IOException("error"));
            MockBookPresenter presenter = new MockBookPresenter(fakeBookService, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, fakeImageFileReader);

            // act
            await presenter.HandleSaveButtonClicked(null, null);

            // assert
            A.CallTo(() => fakeView.ShowErrorDialog("Image file error", "error")).MustHaveHappened();
            Assert.IsTrue(fakeView.SaveButtonEnabled);
            Assert.IsTrue(fakeView.CancelButtonEnabled);
        }
예제 #4
0
        public async Task PopulateTagsList_Test()
        {
            // arrange
            var        fakeView = A.Fake <IAddBookForm>();
            List <Tag> tags     = new List <Tag> {
                new Tag {
                    Name = "tag"
                }
            };
            var fakeTagService = A.Fake <ITagService>();

            A.CallTo(() => fakeTagService.GetAll()).Returns(tags);
            var fakeImageFileReader     = A.Fake <IImageFileReader>();
            var fakeBookRepo            = A.Fake <IBookService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            await presenter.PopulateTagsList();

            // assert
            Assert.IsFalse(presenter.GetAllTagsValueByKey("tag"));
        }
예제 #5
0
        public async Task SaveButtonClicked_Test_ErrorWhileCheckingIfIsbnAlreadyExists()
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.LongTitleFieldText).Returns("test book");
            A.CallTo(() => fakeView.IsbnFieldText).Returns("0123456789");
            var       fakeBookRepo = A.Fake <IBookService>();
            Exception ex           = new Exception("error");

            A.CallTo(() => fakeBookRepo.ExistsWithIsbn("0123456789")).Throws(ex);
            var fakeTagService          = A.Fake <ITagService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            await presenter.HandleSaveButtonClicked(null, null);

            // assert
            A.CallTo(() => fakeView.ShowErrorDialog("Error checking if title or ISBN exists.", "error"));
            Assert.IsTrue(fakeView.SaveButtonEnabled);
            Assert.IsTrue(fakeView.CancelButtonEnabled);
        }
예제 #6
0
        public async Task SaveButtonClicked_Test_ErrorSavingBook(string longTitle, string isbnFieldText, string isbn13FieldText, string deweyDecimalFieldText,
                                                                 string ext)
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.TitleFieldText).Returns("title");
            A.CallTo(() => fakeView.LongTitleFieldText).Returns(longTitle);
            A.CallTo(() => fakeView.LanguageFieldText).Returns("English");
            A.CallTo(() => fakeView.PagesFieldText).Returns("60");
            A.CallTo(() => fakeView.SelectedPublisher).Returns("publisher");
            A.CallTo(() => fakeView.Isbn13FieldText).Returns(isbn13FieldText);
            A.CallTo(() => fakeView.IsbnFieldText).Returns(isbnFieldText);
            A.CallTo(() => fakeView.DeweyDecimalFieldText).Returns(deweyDecimalFieldText);
            A.CallTo(() => fakeView.ImageFilePathFieldText).Returns(@"C:\path\to\file." + ext);
            var fakeBookService = A.Fake <IBookService>();

            A.CallTo(() => fakeBookService.Add(A <Book> .That.Matches(b => b.Title == "title"))).Throws(new Exception("error"));
            var fakeTagService          = A.Fake <ITagService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            var fakeImageFileReader     = A.Fake <IImageFileReader>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookService, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, fakeImageFileReader);

            // act
            await presenter.HandleSaveButtonClicked(null, null);

            // assert
            decimal?deweyDecimal;

            if (System.Text.RegularExpressions.Regex.IsMatch(deweyDecimalFieldText, Book.DEWEY_DECIMAL_PATTERN))
            {
                deweyDecimal = decimal.Parse(deweyDecimalFieldText);
            }
            else
            {
                deweyDecimal = null;
            }
            A.CallTo(() => fakeBookService.Add(A <Book> .That.Matches(b =>
                                                                      b.Title == "title" &&
                                                                      b.TitleLong == longTitle &&
                                                                      b.Language == "English" &&
                                                                      b.Pages == 60 &&
                                                                      b.Isbn == isbnFieldText &&
                                                                      b.Isbn13 == isbn13FieldText &&
                                                                      b.DeweyDecimal == deweyDecimal))).MustHaveHappened();
            A.CallTo(() => fakeView.ShowErrorDialog("Error creating book", "error")).MustHaveHappened();
            Assert.IsTrue(fakeView.SaveButtonEnabled);
            Assert.IsTrue(fakeView.CancelButtonEnabled);
        }
예제 #7
0
        public void Prefill_Test()
        {
            // arrange
            Author author1 = new Author {
                FirstName = "John", LastName = "Smith"
            };
            Author author2 = new Author {
                FirstName = "Jane", LastName = "Doe"
            };
            Publisher publisher = new Publisher("some_publisher");
            Book      book      = new Book
            {
                Title              = "test book",
                TitleLong          = "test book: this book is a test",
                Isbn               = "0123456789",
                Isbn13             = "0123456789012",
                DatePublished      = "2020",
                PlaceOfPublication = "AU",
                Pages              = 100,
                Language           = "English",

                Publisher = publisher,

                Authors = new List <Author>
                {
                    author1,
                    author2
                }
            };
            var fakeView                = A.Fake <IAddBookForm>();
            var fakeBookRepo            = A.Fake <IBookService>();
            var fakeTagService          = A.Fake <ITagService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            presenter.Prefill(book);

            // assert
            Assert.AreEqual("test book", fakeView.TitleFieldText);
            Assert.AreEqual("test book: this book is a test", fakeView.LongTitleFieldText);
            Assert.AreEqual("0123456789", fakeView.IsbnFieldText);
            Assert.AreEqual("0123456789012", fakeView.Isbn13FieldText);
            Assert.AreEqual("2020", fakeView.DatePublishedFieldText);
            Assert.AreEqual("AU", fakeView.PlaceOfPublicationFieldText);
            Assert.AreEqual("100", fakeView.PagesFieldText);
            Assert.AreEqual("English", fakeView.LanguageFieldText);
            A.CallTo(() => fakeView.SetPublisher(publisher, true)).MustHaveHappened();
        }
예제 #8
0
        public void HandleAddNewTagClicked_Test_NoEntry()
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.ShowNewTagDialog()).Returns("");
            var fakeBookService         = A.Fake <IBookService>();
            var fakeTagService          = A.Fake <ITagService>();
            var fakeImageFileReader     = A.Fake <IImageFileReader>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookService, fakeTagService, fakeAuthorService, fakePublisherService, fakeView, fakeImageFileReader);

            // act
            presenter.HandleAddNewTagClicked(null, null);

            // assert
            A.CallTo(() => fakeView.ShowTagAlreadyExistsDialog("")).MustNotHaveHappened();
        }
예제 #9
0
        public async Task PopulatePublisherList_Test()
        {
            // arrange
            var       fakeView             = A.Fake <IAddBookForm>();
            var       fakeBookRepo         = A.Fake <IBookService>();
            var       fakeTagService       = A.Fake <ITagService>();
            var       fakeAuthorService    = A.Fake <IAuthorService>();
            var       fakePublisherService = A.Fake <IPublisherService>();
            Publisher publisher1           = new Publisher("some_publisher");

            A.CallTo(() => fakePublisherService.GetAll()).Returns(new List <Publisher> {
                publisher1
            });
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            await presenter.PopulatePublishersList();

            // assert
            A.CallTo(() => fakeView.PopulatePublisherList(A <List <string> > .That.Matches(l => l.Count() == 1 && l.Contains("some_publisher"))));
        }
예제 #10
0
        public void HandleAddNewTagClicked_Test_TagDoesNotYetExist()
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.ShowNewTagDialog()).Returns("tag2");
            var fakeBookService                 = A.Fake <IBookService>();
            var fakeTagService                  = A.Fake <ITagService>();
            var fakeImageFileReader             = A.Fake <IImageFileReader>();
            var fakeAuthorService               = A.Fake <IAuthorService>();
            var fakePublisherService            = A.Fake <IPublisherService>();
            MockBookPresenter         presenter = new MockBookPresenter(fakeBookService, fakeTagService, fakeAuthorService, fakePublisherService, fakeView, fakeImageFileReader);
            Dictionary <string, bool> allTags   = new Dictionary <string, bool>();

            allTags.Add("tag1", true);
            presenter.SetAllTags(allTags);

            // act
            presenter.HandleAddNewTagClicked(null, null);

            // assert
            Assert.IsTrue(presenter.GetAllTagsValueByKey("tag2"));
        }
예제 #11
0
        public async Task SaveButtonClicked_Test_ItemWithLongTitleAlreadyExists()
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.LongTitleFieldText).Returns("test book");
            var fakeBookRepo = A.Fake <IBookService>();

            A.CallTo(() => fakeBookRepo.ExistsWithLongTitle("test book")).Returns(true);
            var fakeTagService          = A.Fake <ITagService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            await presenter.HandleSaveButtonClicked(null, null);

            // assert
            A.CallTo(() => fakeView.ShowItemAlreadyExistsDialog("test book")).MustHaveHappened();
            Assert.IsTrue(fakeView.SaveButtonEnabled);
            Assert.IsTrue(fakeView.CancelButtonEnabled);
        }
예제 #12
0
        public void InputFieldsUpdated_Test_Invalid_NoImageFilePath(string titleFieldText, string longTitleFieldText, string languageFieldText, string pagesFieldText, string selectedPublisher)
        {
            // arrange
            var fakeView = A.Fake <IAddBookForm>();

            A.CallTo(() => fakeView.TitleFieldText).Returns(titleFieldText);
            A.CallTo(() => fakeView.LongTitleFieldText).Returns(longTitleFieldText);
            A.CallTo(() => fakeView.LanguageFieldText).Returns(languageFieldText);
            A.CallTo(() => fakeView.PagesFieldText).Returns(pagesFieldText);
            A.CallTo(() => fakeView.ImageFilePathFieldText).Returns("");
            var fakeBookRepo            = A.Fake <IBookService>();
            var fakeTagService          = A.Fake <ITagService>();
            var fakeAuthorService       = A.Fake <IAuthorService>();
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            presenter.InputFieldsUpdated(null, null);

            // assert
            Assert.IsFalse(fakeView.SaveButtonEnabled);
        }
예제 #13
0
        public async Task PopulateAuthorList_Test()
        {
            // arrange
            var    fakeView          = A.Fake <IAddBookForm>();
            var    fakeBookRepo      = A.Fake <IBookService>();
            var    fakeTagService    = A.Fake <ITagService>();
            var    fakeAuthorService = A.Fake <IAuthorService>();
            Author author1           = new Author {
                FirstName = "John", LastName = "Smith"
            };

            A.CallTo(() => fakeAuthorService.GetAll()).Returns(new List <Author> {
                author1
            });
            var fakePublisherService    = A.Fake <IPublisherService>();
            MockBookPresenter presenter = new MockBookPresenter(fakeBookRepo, fakeTagService, fakeAuthorService, fakePublisherService,
                                                                fakeView, null);

            // act
            await presenter.PopulateAuthorsList();

            // assert
            A.CallTo(() => fakeView.PopulateAuthorList(A <List <string> > .That.Matches(l => l.Count() == 1 && l.Contains("Smith, John"))));
        }