示例#1
0
 public void DebitTest()
 {
     BankAccount target = new BankAccount("Mr. Bryan Walton", 11.99);
     double amount = 11.22;
     target.Debit(amount);
     Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05);
 }
示例#2
0
        public void Debit_WithValidAmount_UpdatesBalance()
        {
            // arrange
            double beginningBalance = 11.99;
            double debitAmount = 4.55;
            double expected = 7.44;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

            // act
            account.Debit(debitAmount);

            // assert
            //The method is rather simple.
            //We set up a new BankAccount object with a beginning balance 
            //and then withdraw a valid amount.We use the Microsoft unit test 
            //framework for managed code AreEqual method to verify that the 
            //ending balance is what we expect.
            //A test method must meet the following requirements:
            //The method must be decorated with the[TestMethod] attribute.
            //The method must return void.
            //The method cannot have parameters.

          double actual = account.Balance;
            Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly");
        }
示例#3
0
 public void DebitTest()
 {
     var target = new BankAccount("Mr Brian Walton", 11.99);
     const double amount = 11.22; 
     target.Debit(amount);
     Assert.AreEqual(0.77, target.Balance, 0.05);
 }
示例#4
0
文件: s44_a01.cs 项目: mjmdesigns/IT
 public static void Main()
 {
     BankAccount ba = new BankAccount("Mr. Bryan Walton", 11.99); 
     ba.Credit(5.77);
     ba.Debit(11.22);
     Console.WriteLine("Current balance is ${0}", ba.Balance);
 }
示例#5
0
 public void DebitTest()
 {
     BankAccount target = new BankAccount("Mr. Bryan Walton", 11.99); // TODO: Initialize to an appropriate value
     double amount = 11.22; // TODO: Initialize to an appropriate value
     target.Debit(amount);
     //Assert.Inconclusive("A method that does not return a value cannot be verified.");
     Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05);
 }
 public void DebitTest()
 {
     BankAccount target = new BankAccount("Mr.Bryan Walton", 11.99);
     double amount = 11.22;
     target.Debit(amount);
        // Assert.Inconclusive("Невозможно проверить метод, не возвращающий значение.");
     Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05);
 }
示例#7
0
 public void DebitTest()
 {
     //创建一个账户shenjl,余额为100元
     BankAccount bank = new BankAccount("shenjl", 100);
     //取款10元
     bank.Debit(10);
     //Assert在这里可以理解成断言:在VSTS里做单元测试是基于断言的测试
     //预计的结果是90元,如果等于实际的结果的话就通过,否则不通过。
     Assert.AreEqual(90, bank.Balance);
 }
示例#8
0
        [ExpectedException(typeof(ArgumentOutOfRangeException))] //use the ExpectedExceptionAttribute attribute to assert that right exception has been thrown
        public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange()
        {
            double beginningBalance = 10.00;
            double debitAmount = -100.00;
            BankAccount account = new BankAccount("Ivon Swed", beginningBalance);
            
            account.Debit(debitAmount);

            // assert is handled by ExpectedException
        }
        public void Debit_WhenAmountIsMoreThanBalance_ShouldThrowArgumentOutOfRange()
        {
            // arrange
            double beginningBalance = 11.99;
            double debitAmount = 100.00;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

            // act
            account.Debit(debitAmount);

            // assert is handled by ExpectedException
        }
示例#10
0
        [TestMethod] //required for methods to run in Test Explorer
        public void Debit_WithValidAmount_UpdatesBalance() //can't have parameters and must return void
        {
            double beginningBalance = 10.00;
            double debitAmount = 4.00;
            double expected = 6.00;
            BankAccount account = new BankAccount("Brendon Blanchurd", beginningBalance);
            
            account.Debit(debitAmount);

            // assert
            double actual = account.Balance;
            Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly");
        }
示例#11
0
        public void Debit_WithValidAmount_UpdatesBalance()
        {
            // arrange
            double beginningBalance = 11.99;
            double debitAmount = 4.55;
            double expected = 7.44;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

            // act
            account.Debit(debitAmount);

            // assert
            double actual = account.Balance;
            Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly");
        }
示例#12
0
        public void Debit_FrozenAccountBalance()
        {
            // arrange
            double beginningBalance = 11.99;
            double debitAmount = 4.55;
            double expected = 7.44;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);
            account.FreezeAccount();
            // act
            account.Debit(debitAmount);

            // assert
            double actual = account.Balance;
            Assert.AreEqual(expected, actual, "Account not debited correctly");
        }
示例#13
0
        public void Debit_WithValidAmount_UpdatesBalance()
        {
            // Arrange
            double      beginningBalance = 11.99;
            double      debitAmount      = 4.55;
            double      expected         = 7.44;
            BankAccount account          = new BankAccountNS.BankAccount("Mr. Bryan Walton", beginningBalance);

            // Act
            account.Debit(debitAmount);

            // Assert
            double actual = account.Balance;

            Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly");
        }
示例#14
0
        /// <summary>
        /// Metodo de ejecución principal
        /// </summary>
        /// <param name="args">Parametros de entrada a la ejecución principal.</param>
        static void Main(string[] args)
        {
            BankAccount ba = new BankAccount("Mr. Bryan Walton", 11.99);

            try
            {
                //ba.Credit(5.77);
                ba.Debit(-100);
                Console.WriteLine("Current balance is ${0}", ba.Balance);
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#15
0
        public void Debit_WhenAmountIsMoreThanBalance_ShouldThrowArgumentOutOfRange()
        {
            // arrange
            double      beginningBalance = 11.99;
            double      debitAmount      = 20.0;
            BankAccount account          = new BankAccount("Mr. Bryan Walton", beginningBalance);

            // act
            try {
                account.Debit(debitAmount);
            } catch (ArgumentOutOfRangeException e) {
                // assert
                StringAssert.Contains(e.Message, BankAccount.DebitAmountExceedsBalanceMessage);
                return;
            }
            Assert.Fail("No exception was thrown.");
        }
 public void Debit_WhenAmountIsGreaterThanBalance_ShouldThrowArgumentOutOfRange()
 {
     // arrange
     double beginningBalance = 11.99;
     double debitAmount = 20.0;
     BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);
     // act
     try
     {
         account.Debit(debitAmount);
     }
     catch (ArgumentOutOfRangeException e)
     {
         // assert
         StringAssert.Contains(e.Message, BankAccount. DebitAmountExceedsBalanceMessage);
     }
 }
示例#17
0
        public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange()
        {
            // arrange
            double beginningBalance = 11.99;
            double debitAmount = 7.44;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

               // act
            try
            {
                account.Debit(debitAmount);
            }
            catch (ArgumentOutOfRangeException e)
            {
                // assert
                StringAssert.Contains(e.Message, BankAccount. DebitAmountExceedsBalanceMessage);
                return;
            }
            Assert.Fail("No exception was thrown.");
        }
示例#18
0
        // don't need to say [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Debit_WhenAmountIsMoreThanBalance_ShouldThrowArgumentOutOfRange()
        {
            double beginningBalance = 10.00;
            double debitAmount = 100.00;
            BankAccount account = new BankAccount("Allar Bogleaeava", beginningBalance);
            
            try
            {
                account.Debit(debitAmount);
            }
            catch (ArgumentOutOfRangeException e)
            {
                // assert
                StringAssert.Contains(e.Message, BankAccount.DebitAmountExceedsBalanceMessage);
                return;
            }
            Assert.Fail("No exception was thrown.");

            // assert is handled by ExpectedException
        }
示例#19
0
        public void Debit_WhenAmountIsGreaterThanBalance_ShouldThrowArgumentOutOfRange()
        {
            // arrange
            double beginningBalance = 21.99;
            double debitAmount = 20.0;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

            // act
            try
            {
                account.Debit(debitAmount);
            }
            catch (ArgumentOutOfRangeException e)
            {
                // assert
                StringAssert.Contains(e.Message, BankAccount. DebitAmountExceedsBalanceMessage);
                return;
            }
            //如果不进入catch的话,在不检查任何条件的情况下使断言失败,显示消息
            //Assert.Fail("No exception was thrown.");
        }
示例#20
0
        public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange()
        {
            //Arrange
            double      beginningBalance = 11.99;
            double      debitAmount      = -100.00;
            BankAccount account          = new BankAccount("Mr. Bryan Walton", beginningBalance);

            //Act
            try
            {
                account.Debit(debitAmount);
            }
            catch (ArgumentOutOfRangeException e)
            {
                //Assert is handled by the ExpectedException attribute on the test method.
                StringAssert.Contains(e.Message, BankAccount.DebitAmountLessThanZeroMessage);
                return;
            }

            Assert.Fail("The expected exception not thrown.");
        }
示例#21
0
        public static void Main(string[] args)
        {
            /*
             * Avant modifications, ce programme cree un compte en banque au nom de Mr. Bryan Walton et y depose 12.25
             * Il execute ensuite 10 fois une sequence de deux operations:
             *  - Un credit d'un montant aletoire entre 0 et 100 dollars (MaxAmount)
             *  - Un debit d'un montant aletoire entre 0 et 100 dollars (MaxAmount)
             * A chacune de ces operations il refuse un nombre negatif ou un debit superieur a la balance du compte
             * Il affiche la blance apres chaque operation
             * toto
             */



            //BankAccount ba = new BankAccount("Mr. Bryan Walton", 12.25);
            //1) changement de nom
            BankAccount ba = new BankAccount("M. Julien Brunet", 12.25);

            Random rand = new Random();

            // for (int i = 0; i < 10 ; i++)
            //2) on ajoute 5 operations pour en avoir 15
            for (int i = 0; i < 15; i++)
            {
                ba.Credit(Math.Round(rand.NextDouble() * MaxAmount, 2));
                Thread.Sleep(500);

                //Je ne veux que 10 credits mais 15 debits
                if (i < 10)
                {
                    ba.Debit(Math.Round(rand.NextDouble() * MaxAmount, 2));
                    Thread.Sleep(500);
                }
            }

            Console.ReadKey();
        }
示例#22
0
        public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange()
        {
            // arrange
            double beginningBalance = 11.99;
            double debitAmount = -100.00;
            BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance);

            // act
            account.Debit(debitAmount);

            // 此处的断言被ExpectedException异常处理了,在Bank类中有相应的设置,可以看出是怎样的异常
            // assert is handled by ExpectedException
        }