Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- // nunit runner
- NUnit.ConsoleRunner.Runner.Main(new string[]
- {
- Assembly.GetExecutingAssembly().Location,
- });
- }
- public interface IBookMarket
- {
- }
- public class BooksInfo
- {
- }
- public class BookInfoProvider
- {
- public BooksInfo GetBookInfo(IBookMarket bookinfo)
- {
- if(bookinfo == null)
- throw new ArgumentNullException("bookinfo should not be null");
- return null;
- }
- }
- [TestFixture]
- public class TestGetBookInfo
- {
- [Test]
- [ExpectedException(
- ExpectedException = typeof(ArgumentNullException),
- ExpectedMessage = "bookinfo should not be null",
- MatchType = MessageMatch.Contains)]
- public void TestGetBookInfoExceptionOldStyle()
- {
- new BookInfoProvider().GetBookInfo(null);
- }
- [Test]
- public void TestGetBookInfoExceptionNewStyle()
- {
- Assert.That(
- () => new BookInfoProvider().GetBookInfo(null),
- Throws.InstanceOf<ArgumentNullException>()
- .And.Message.Contains("bookinfo should not be null"));
- }
- object[] TestData =
- {
- new TestCaseData(new BookMarketStub()), // "good" case
- new TestCaseData(null).Throws(typeof(ArgumentNullException)) // "bad" exceptional case
- };
- [Test]
- [TestCaseSource("TestData")]
- public void TestGetBookInfoDataDriven(IBookMarket bookinfo)
- {
- new BookInfoProvider().GetBookInfo(bookinfo);
- Assert.Pass("all ok"); // this is not necessary
- }
- }
- public class BookMarketStub : IBookMarket
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement