Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Machine.Specifications.Example
  7. {
  8. public abstract class with_from_account_and_to_account : Context
  9. {
  10. protected static Account fromAccount;
  11. protected static Account toAccount;
  12.  
  13. public override void SetupContext()
  14. {
  15. fromAccount = new Account { Balance = 1m };
  16. toAccount = new Account { Balance = 1m };
  17. }
  18. }
  19.  
  20. [Specification]
  21. public class When_transfering_between_two_accounts_with_no_context
  22. {
  23. private int foo;
  24. When the_transfer_is_made =()=>
  25. {
  26. fromAccount = new Account { Balance = 1m };
  27. toAccount = new Account { Balance = 1m };
  28. fromAccount.Transfer(1m, toAccount);
  29. };
  30.  
  31. It should_debit_the_from_account_by_the_amount_transferred =()=>
  32. {
  33. fromAccount.Balance.ShouldEqual(0m);
  34. };
  35.  
  36. It should_credit_the_to_account_by_the_amount_transferred =()=>
  37. {
  38. toAccount.Balance.ShouldEqual(2m);
  39. };
  40.  
  41. protected static Account fromAccount;
  42. protected static Account toAccount;
  43. }
  44.  
  45. [Specification]
  46. public class When_transfering_between_two_accounts_has_context
  47. : IHasContext
  48. {
  49. When the_transfer_is_made =()=>
  50. {
  51. fromAccount.Transfer(1m, toAccount);
  52. };
  53.  
  54. It should_debit_the_from_account_by_the_ammount_transferred =()=>
  55. {
  56. fromAccount.Balance.ShouldEqual(0m);
  57. };
  58.  
  59. It should_credit_the_to_account_by_the_amount_transferred =()=>
  60. {
  61. toAccount.Balance.ShouldEqual(2m);
  62. };
  63.  
  64. protected static Account fromAccount;
  65. protected static Account toAccount;
  66. public void SetupContext()
  67. {
  68. fromAccount = new Account { Balance = 1m };
  69. toAccount = new Account { Balance = 1m };
  70. }
  71. }
  72.  
  73. [Specification]
  74. public class When_transfering_between_two_accounts
  75. : with_from_account_and_to_account
  76. {
  77. When the_transfer_is_made =()=>
  78. {
  79. fromAccount.Transfer(1m, toAccount);
  80. };
  81.  
  82. It should_debit_the_from_account_by_the_ammount_transferred =()=>
  83. {
  84. fromAccount.Balance.ShouldEqual(0m);
  85. };
  86.  
  87. It should_credit_the_to_account_by_the_amount_transferred =()=>
  88. {
  89. toAccount.Balance.ShouldEqual(2m);
  90. };
  91. }
  92.  
  93. [Specification]
  94. public class When_transfering_an_amount_greater_than_the_balance_of_the_from_account
  95. : with_from_account_and_to_account
  96. {
  97. When the_transfer_is_made =()=>
  98. {
  99. fromAccount.Transfer(2m, toAccount);
  100. };
  101.  
  102. It_should_throw a_System_Exception =x=>
  103. {
  104. x.ShouldBeOfType<Exception>();
  105. };
  106. }
  107. }
Add Comment
Please, Sign In to add comment