public void TC2_DivideByZero() { IUSD_RMB_ExchangeRateFeed feed = this.PrvGetExchangeRateFeed(); ICalculator calculator = new Calculator(feed); int actualResult = calculator.Divide(9, 0); Assert.Throws <InvalidOperationException>(() => operation()); }
public void TC3_ConvertUSDtoRMBTest() { IUSD_RMB_ExchangeRateFeed feed = this.prvGetMockExchangeRateFeed(); ICalculator calculator = new Calculator(feed); int actualResult = calculator.ConvertUSDtoRMB(1); int expectedResult = 500; Assert.AreEqual(expectedResult, actualResult); }
public void TC2_DivideByZero() { IUSD_RMB_ExchangeRateFeed feed = this.prvGetMockExchangeRateFeed(); ICalculator calculator = new Calculator(feed); //int actualResult = calculator.Divide(9, 1); Assert.That(() => calculator.Divide(9, 0), Throws.TypeOf <System.DivideByZeroException>()); //Assert.Throws<System.DivideByZeroException>(() => calculator.Divide(9, 0)); }
public void TC1_Divide9By3() { IUSD_RMB_ExchangeRateFeed feed = this.prvGetMockExchangeRateFeed(); ICalculator calculator = new Calculator(feed); int actualResult = calculator.Divide(9, 3); int expectedResult = 3; Assert.AreEqual(expectedResult, actualResult); }
public void AssertThrowTest() { IUSD_RMB_ExchangeRateFeed feed = prvGetMockExchangeRateFeed(); ICalculator calculator = new Calculator(feed); //不同写法 // .NET 1.x Assert.Throws(typeof(DivideByZeroException), new TestDelegate(TC2_DivideByZero)); // .NET 2.0 ////Assert.Throws<DivideByZeroException>(TC2_DivideByZero() ); Assert.Throws <DivideByZeroException>(delegate { calculator.Divide(9, 0); }); // Using C# 3.0 Assert.Throws <DivideByZeroException>(() => { calculator.Divide(9, 0); }); //对抛出的异常进行核实 ////DivideByZeroException ex = Assert.Throws<DivideByZeroException>(delegate { throw new DivideByZeroException("message", 42); }); DivideByZeroException ex = Assert.Throws <DivideByZeroException>(delegate { throw new DivideByZeroException("message"); }); Assert.That(ex.Message, Is.EqualTo("message")); ////Assert.That(ex.MyParam, Is.EqualTo(42)); }
public Calculator(IUSD_RMB_ExchangeRateFeed feed) { this._feed = feed; }
//[ExpectedException(typeof(System.DivideByZeroException))] public void TC2_9除以0() { IUSD_RMB_ExchangeRateFeed feed = this.prvGetMockExchangeRateFeed(); ICalculator calculator = new Calculator(feed); int actualResult = calculator.Divide(9, 0); }