public void SearchByTitle_ExpectNone() { string gibberish = "aergergvdasc"; Mock <IAuctionDao> mockDao = new Mock <IAuctionDao>(); mockDao.Setup(dao => dao.SearchByTitle(gibberish)); AuctionsController controller = new AuctionsController(mockDao.Object); //IEnumerable<Auction> actual = controller.List(gibberish); //because parameters will be added to this method, we will need to try with different amounts of parameters object actual = SafeReflection.InvokeMethod(controller, "List", new object[] { gibberish, 0 }); if (actual == null) { actual = SafeReflection.InvokeMethod(controller, "List", new object[] { gibberish }); } //if this assertion fails, parameter has not yet been added to method. Need this test because `actual` will be null if parameter doesn't exist and give a false positive Assert.IsTrue(SafeReflection.HasMethodWithParameters(controller.GetType(), "List", new Dictionary <string, Type>() { { "title_like", typeof(string) } })); Assert.IsNull(actual); }
public void SearchByPrice_ExpectNone() { Mock <IAuctionDao> mockDao = new Mock <IAuctionDao>(); mockDao.Setup(dao => dao.SearchByPrice(0.01)); AuctionsController controller = new AuctionsController(mockDao.Object); //List<Auction> actual = controller.List(currentBid_lte: 0.01); object actual = SafeReflection.InvokeMethod(controller, "List", new object[] { null, 0.01 }); //if this assertion fails, parameter has not yet been added to method. Need this test because `actual` will be null if parameter doesn't exist and give a false positive Assert.IsTrue(SafeReflection.HasMethodWithParameters(controller.GetType(), "List", new Dictionary <string, Type>() { { "currentBid_lte", typeof(double) } })); Assert.IsNull(actual); }