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); }
public void CreditTest() { BankAccount target = new BankAccount("Mr. Bryan Walton", 11.99); // TODO: Initialize to an appropriate value double amount = 0F; // TODO: Initialize to an appropriate value target.Credit(amount); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
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"); }
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); }
public void CreditTest() { var target = new BankAccount("Mr Brian Walton", 11.99); const double amount = 0.01; target.Credit(amount); Assert.AreEqual(12.00, target.Balance); }
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); }
public void CreditTest() { BankAccount target = new BankAccount("Mr.Bryan Walton", 11.99); double amount = 11.22; target.Credit(amount); Assert.Inconclusive("Невозможно проверить метод, не возвращающий значение."); }
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); }
public void DebitTest() { //创建一个账户shenjl,余额为100元 BankAccount bank = new BankAccount("shenjl", 100); //取款10元 bank.Debit(10); //Assert在这里可以理解成断言:在VSTS里做单元测试是基于断言的测试 //预计的结果是90元,如果等于实际的结果的话就通过,否则不通过。 Assert.AreEqual(90, bank.Balance); }
[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 }
[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"); }
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 }
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"); }
public void Credit_Balance() { // arrange double beginningBalance = 11.99; double creditAmount = 4.55; double expected = 16.54; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); // act account.Credit(creditAmount); // assert double actual = account.Balance; Assert.AreEqual(expected, actual, "Account not credited correctly"); }
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"); }
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"); }
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); } }
// 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 }
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."); }
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."); }