PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Examples/Example/BankingSpecs.cs

https://github.com/machine/machine.specifications
C# | 54 lines | 43 code | 11 blank | 0 comment | 0 complexity | 7eb87388feacaec93109a0e405ac15a7 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
  5. {
  6. [Subject(typeof(Account), "Funds transfer")]
  7. public class when_transferring_between_two_accounts
  8. : AccountSpecs
  9. {
  10. Establish context = () =>
  11. {
  12. fromAccount = new Account {Balance = 1m};
  13. toAccount = new Account {Balance = 1m};
  14. };
  15. Because of =
  16. () => fromAccount.Transfer(1m, toAccount);
  17. It should_debit_the_from_account_by_the_amount_transferred =
  18. () => fromAccount.Balance.Should().Be(0m);
  19. It should_credit_the_to_account_by_the_amount_transferred =
  20. () => toAccount.Balance.Should().Be(2m);
  21. }
  22. [Subject(typeof(Account), "Funds transfer")]
  23. [Tags("failure")]
  24. public class when_transferring_an_amount_larger_than_the_balance_of_the_from_account
  25. : AccountSpecs
  26. {
  27. static Exception exception;
  28. Establish context = () =>
  29. {
  30. fromAccount = new Account {Balance = 1m};
  31. toAccount = new Account {Balance = 1m};
  32. };
  33. Because of =
  34. () => exception = Catch.Exception(() => fromAccount.Transfer(2m, toAccount));
  35. It should_not_allow_the_transfer =
  36. () => exception.Should().BeOfType<Exception>();
  37. }
  38. public abstract class AccountSpecs
  39. {
  40. protected static Account fromAccount;
  41. protected static Account toAccount;
  42. }
  43. }