Code Snippet
- [TestMethod]
- [ExpectedException(typeof(TradingServiceException))]
- public void ShouldThrowExceptionForInvalidTrade()
- {
- var mockTrade = new Mock<AbstractTrade>(MockBehavior.Strict);
- mockTrade.SetupAllProperties();
- mockTrade.Setup(trade => trade.IsValid()).Returns(false);
- var tradeManager = new TradeManager(mockTrade.Object);
- tradeManager.Execute();
- mockTrade.Verify();
- }
And when the test fails, we get the following message:
TradeGeneratorTests.ShouldThrowExceptionForInvalidTrade : Failed
Test method Zainco.Commodities.Unit.Tests.TradeGeneratorTests.ShouldThrowExceptionForInvalidTrade threw exception:
Zainco.Commodities.Exceptions.TradingServiceException: Precondition failed: Trade.IsValid() == true Trade execution failed
at System.Diagnostics.Contracts.__ContractsRuntime.Requires<TException>(Boolean condition, String message, String conditionText) in :line 0
at Zainco.Commodities.TradingService.TradeManager.Execute() in TradeManager.cs: line 28
at Zainco.Commodities.Unit.Tests.TradeGeneratorTests.ShouldThrowExceptionForInvalidTrade() in TradeGeneratorTests.cs: line 36
Sweet!
No comments:
Post a Comment