Created
April 12, 2012 16:07
-
-
Save lhaussknecht/2368670 to your computer and use it in GitHub Desktop.
MSpec in VB.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Account | |
Public Property Balance() As Decimal | |
Public Sub Transfer(ByVal amount As Decimal, ByVal toAccount As Account) | |
If amount > Balance Then | |
Throw New Exception(String.Format("Cannot transfer ${0}. The available balance is ${1}.", amount, Balance)) | |
End If | |
toAccount.Balance += amount | |
Balance -= amount | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Machine.Specifications.Example | |
{ | |
[Subject(typeof(Account), "Funds transfer")] | |
public class when_transferring_between_two_accounts | |
: AccountSpecs | |
{ | |
Because of = () => | |
fromAccount.Transfer(1m, toAccount); | |
It should_debit_the_from_account_by_the_amount_transferred = () => | |
fromAccount.Balance.ShouldEqual(0m); | |
It should_credit_the_to_account_by_the_amount_transferred = () => | |
toAccount.Balance.ShouldEqual(2m); | |
} | |
[Subject(typeof(Account), "Funds transfer"), Tags("failure")] | |
public class when_transferring_an_amount_larger_than_the_balance_of_the_from_account | |
: AccountSpecs | |
{ | |
static Exception exception; | |
Because of =()=> | |
exception = Catch.Exception(()=>fromAccount.Transfer(2m, toAccount)); | |
It should_not_allow_the_transfer =()=> | |
exception.ShouldBeOfType<Exception>(); | |
} | |
public class failure {} | |
public abstract class AccountSpecs | |
{ | |
protected static Account fromAccount; | |
protected static Account toAccount; | |
Establish context =()=> | |
{ | |
fromAccount = new Account {Balance = 1m}; | |
toAccount = new Account {Balance = 1m}; | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports Machine.Specifications | |
Public MustInherit Class AccountSpecs | |
Protected Shared fromAccount As Account | |
Protected Shared toAccount As Account | |
Friend context As Establish = (Sub() | |
fromAccount = New Account() With {.Balance = 1D} | |
toAccount = New Account() With {.Balance = 1D} | |
End Sub) | |
End Class | |
<Subject(GetType(Account), "Funds transfer")> _ | |
Public Class when_transferring_between_two_accounts | |
Inherits AccountSpecs | |
Friend [of] As Because = (Sub() | |
fromAccount.Transfer(1D, toAccount) | |
End Sub) | |
Friend should_debit_the_from_account_by_the_amount_transferred As It = (Sub() | |
fromAccount.Balance.ShouldEqual(0D) | |
End Sub) | |
Friend should_credit_the_to_account_by_the_amount_transferred As It = (Sub() | |
toAccount.Balance.ShouldEqual(2D) | |
End Sub) | |
End Class | |
<Subject(GetType(Account), "Funds transfer"), Tags("Failure")> _ | |
Public Class when_transferring_an_amount_larger_than_the_balance_of_the_from_account | |
Inherits AccountSpecs | |
Shared exception As Exception | |
Friend [of] As Because = (Sub() | |
exception = [Catch].Exception((Sub() | |
fromAccount.Transfer(2D, toAccount) | |
End Sub)) | |
End Sub) | |
Friend should_not_allow_the_transfer As It = (Sub() | |
exception.ShouldBeOfType(Of Exception)() | |
End Sub) | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports Machine.Specifications | |
<Subject("Recent Account Activity Summary page")> _ | |
Public Class when_a_customer_first_views_the_account_summary_page | |
Friend should_display_all_account_transactions_for_the_past_thirty_days As It | |
Friend should_display_debit_amounts_in_red_text As It | |
Friend should_display_deposit_amounts_in_black_text As It | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment