public void BuildTestWhenProviderThrowsException() { const string providerName1 = "Name1"; const string providerName2 = "Name2"; var book1 = new Book("1", "1", "1"); var book2 = new Book("2", "2", "2"); var bookWrapper1 = new BookWrapper(book1, new [] { providerName2 }); var bookWrapper2 = new BookWrapper(book2, new [] { providerName2 }); using (MocksRecord()) { provider1.Stub(p => p.Name).Return(providerName1); provider2.Stub(p => p.Name).Return(providerName2); provider1.Expect(p => p.SelectAll()).Throw(new Exception("FATAL CRASH!!111")); provider2 .Expect(p => p.SelectAll()) .Return(new[] { book1, book2 }); bookFactory.Expect(f => f.Create(book1, new[] { providerName2 })).Return(bookWrapper1); bookFactory.Expect(f => f.Create(book2, new[] { providerName2 })).Return(bookWrapper2); bookIndex.Expect(i => i.Rebuild(new[] { bookWrapper1, bookWrapper2 })); } bookIndexBuilder.Build(); }
public void BuildTestForEmptyQuery(string query) { var book1 = new BookWrapper(new Book("isbn1", "author1", "title1"), new [] { "provider1" }); var book2 = new BookWrapper(new Book("isbn2", "author2", "title2"), new [] { "provider1", "provider2" }); var book3 = new BookWrapper(new Book("isbn3", "author3", "title3"), new [] { "provider2" }); using (MocksRecord()) { bookIndex.Expect(i => i.Search(query, maxSearchResultsCount)).Return(new[] { book1, book2, book3 }); } var expected = new BookListViewModel { Query = query, Books = new[] { new BookViewModel { ISBN = book1.Book.ISBN, Author = book1.Book.Author, Title = book1.Book.Title, Providers = book1.Providers }, new BookViewModel { ISBN = book2.Book.ISBN, Author = book2.Book.Author, Title = book2.Book.Title, Providers = book2.Providers }, new BookViewModel { ISBN = book3.Book.ISBN, Author = book3.Book.Author, Title = book3.Book.Title, Providers = book3.Providers }, } }; var actual = bookListViewModelBuilder.Build(query); actual.ShouldBeEquivalentTo(expected); }