Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Machine.Specifications.Example | ||
{ | ||
public class Account | ||
{ | ||
private decimal _balance; | ||
|
||
public int AccountNo { get; set; } | ||
public decimal Balance | ||
{ | ||
get { return _balance; } | ||
set { _balance = value; } | ||
} | ||
|
||
public void Transfer(decimal amount, Account toAccount) | ||
{ | ||
if (amount > _balance) | ||
{ | ||
throw new Exception(String.Format("Cannot transfer ${0}. The available balance is ${1}.", amount, _balance)); | ||
} | ||
|
||
_balance -= amount; | ||
toAccount.Balance += amount; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return string.Format("\"Account {0}\"", AccountNo); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace xUnit.BDDExtensions.SampleCode.UI | ||
{ | ||
public class Article {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.FSharp.Collections; | ||
|
||
namespace xUnit.BDDExtensions.SampleCode.UI | ||
{ | ||
public class ArticleSearchViewModel | ||
{ | ||
private readonly IArticleSource _articleSource; | ||
|
||
public ArticleSearchViewModel(IArticleSource articleSource) | ||
{ | ||
_articleSource = articleSource; | ||
} | ||
|
||
public string SearchTerm { get; set; } | ||
|
||
public FSharpList<Article> Results { get; set; } | ||
|
||
public void StartSearch() | ||
{ | ||
Results = _articleSource.Search(SearchTerm); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,8 @@ public override string ToString() | |
return Name; | ||
} | ||
} | ||
} | ||
|
||
namespace Machine.Specifications.Example | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.FSharp.Collections; | ||
|
||
namespace xUnit.BDDExtensions.SampleCode.UI | ||
{ | ||
public interface IArticleSource | ||
{ | ||
FSharpList<Article> Search(string searchTerm); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module AccountSpec | ||
|
||
open NaturalSpec | ||
open Machine.Specifications.Example | ||
|
||
let transferring_money_to money toAccount (fromAccount:Account) = | ||
toSpec <| (sprintf "transferring %A to %A" money toAccount) | ||
fromAccount.Transfer(money,toAccount) | ||
fromAccount | ||
|
||
let balance amount (account:Account) = | ||
printMethod amount | ||
account.Balance = amount | ||
|
||
|
||
|
||
[<Scenario>] | ||
let ``When transferring between two account``() = | ||
let fromAccount = new Account(AccountNo=1,Balance=1m) | ||
let toAccount = new Account(AccountNo=2,Balance=1m) | ||
|
||
Given fromAccount // Arrange | ||
|> When transferring_money_to 1m toAccount // Act | ||
|> It should have (balance 0m) // Assert | ||
|> Whereas toAccount | ||
|> It should have (balance 2m) | ||
|> Verify |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module ArticleSearchViewModelSpec | ||
|
||
open NaturalSpec | ||
|
||
open xUnit.BDDExtensions.SampleCode.UI | ||
open System.Collections.Generic | ||
|
||
let starting_search (vm:ArticleSearchViewModel) = | ||
printMethod "" | ||
vm.StartSearch() | ||
vm | ||
|
||
let articleCount count (vm:ArticleSearchViewModel) = | ||
printMethod count | ||
Seq.length vm.Results = count | ||
|
||
|
||
|
||
[<Scenario>] | ||
let ``Given an existing search term when starting for articles``() = | ||
let empty : Article list = [] | ||
let service = | ||
mock<IArticleSource> "Service" | ||
|> setup <@fun x -> x.Search @> (fun x -> if x = "Term" then empty else failwith "Error") | ||
|
||
let viewModel = new ArticleSearchViewModel(service,SearchTerm = "Term") | ||
|
||
Given viewModel | ||
|> When starting_search | ||
|> It should have (articleCount 0) | ||
|> Verify | ||
|
||
|
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
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