PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Examples/Example.CustomDelegates/AccountSpec.cs

https://github.com/machine/machine.specifications
C# | 50 lines | 39 code | 11 blank | 0 comment | 0 complexity | 2869fd7c427bae7e56f183bda16f4f3c MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0
  1. using System;
  2. using FluentAssertions;
  3. using Machine.Specifications;
  4. namespace Example.CustomDelegates
  5. {
  6. [Subject(typeof(Account), "Funds transfer")]
  7. public class when_transferring_between_two_accounts
  8. {
  9. static Account fromAccount;
  10. static Account toAccount;
  11. Given accounts = () =>
  12. {
  13. fromAccount = new Account {Balance = 1m};
  14. toAccount = new Account {Balance = 1m};
  15. };
  16. When transfer_is_made =
  17. () => fromAccount.Transfer(1m, toAccount);
  18. Then should_debit_the_from_account_by_the_amount_transferred =
  19. () => fromAccount.Balance.Should().Be(0m);
  20. Then should_credit_the_to_account_by_the_amount_transferred =
  21. () => toAccount.Balance.Should().Be(2m);
  22. }
  23. [Subject(typeof(Account), "Funds transfer")]
  24. public class when_transferring_an_amount_larger_than_the_balance_of_the_from_account
  25. {
  26. static Account fromAccount;
  27. static Account toAccount;
  28. static Exception exception;
  29. Given accounts = () =>
  30. {
  31. fromAccount = new Account {Balance = 1m};
  32. toAccount = new Account {Balance = 1m};
  33. };
  34. Because transfer_is_made =
  35. () => exception = Catch.Exception(() => fromAccount.Transfer(2m, toAccount));
  36. Then should_not_allow_the_transfer =
  37. () => exception.Should().BeOfType<Exception>();
  38. }
  39. }