public void ParseTestNormalBehavior() { const string isbn1 = "ISBN1", author1 = "AUTHOR1", title1 = "TITLE1"; var book1 = new Book(isbn1, author1, title1); const string isbn2 = "ISBN2", author2 = "AUTHOR2", title2 = "TITLE2"; var book2 = new Book(isbn2, author2, title2); const string isbn3 = "ISBN3", author3 = "AUTHOR3", title3 = "TITLE3"; var book3 = new Book(isbn3, author3, title3); var xmlText = $@"<?xml version=""1.0""?> <data> <booklist> <book isbn=""{isbn1}"" author=""{author1}"" title=""{title1}"" /> <book isbn=""{isbn2}"" author=""{author2}"" title=""{title2}"" /> <book isbn=""{isbn3}"" author=""{author3}"" title=""{title3}"" /> </booklist> </data>"; var providerXmlData = CreateProviderData(xmlText); using (MocksRecord()) { bookFactory.Expect(f => f.Create(isbn1, author1, title1)).Return(book1); bookFactory.Expect(f => f.Create(isbn2, author2, title2)).Return(book2); bookFactory.Expect(f => f.Create(isbn3, author3, title3)).Return(book3); } var actual = marvelParser.Parse(providerXmlData); var expected = new[] { book1, book2, book3 }; actual.ShouldAllBeEquivalentTo(expected); }
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(); }