Example #1
0
        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());
        }
Example #2
0
        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);
        }
Example #3
0
        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));
        }
Example #4
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);
        }
Example #5
0
            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));
            }
Example #6
0
 public Calculator(IUSD_RMB_ExchangeRateFeed feed)
 {
     this._feed = feed;
 }
Example #7
0
 //[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);
 }
Example #8
0
 public Calculator(IUSD_RMB_ExchangeRateFeed feed)
 {
     this._feed = feed;
 }