main
 1using System.Windows.Forms;
 2using developwithpassion.bdd.contexts;
 3using Gorilla.Commons.Testing;
 4using gorilla.commons.utility;
 5using Rhino.Mocks;
 6
 7namespace MoMoney.Presentation.Model.Navigation
 8{
 9    public class TreeBranchSpecs {}
10
11    [Concern(typeof (TreeBranch))]
12    public abstract class behaves_like_a_tree_branch : concerns_for<ITreeBranch, TreeBranch>
13    {
14        context c = () =>
15        {
16            command = the_dependency<Command>();
17            tree_node = dependency<TreeNode>();
18        };
19
20        public override ITreeBranch create_sut()
21        {
22            return new TreeBranch(tree_node, command);
23        }
24
25        static protected TreeNode tree_node;
26        static protected Command command;
27    }
28
29    public class when_accepting_a_visitor_that_visits_tree_nodes : behaves_like_a_tree_branch
30    {
31        it should_allow_the_visitor_to_visit_it = () => visitor.was_told_to(x => x.visit(sut));
32
33        context c = () =>
34        {
35            visitor = an<Visitor<ITreeBranch>>();
36            var tree_view = dependency<TreeView>();
37            when_the(tree_node).is_told_to(x => x.TreeView).it_will_return(tree_view);
38        };
39
40        because b = () => sut.accept(visitor);
41
42        static Visitor<ITreeBranch> visitor;
43    }
44
45    public class when_a_tree_node_is_clicked : behaves_like_a_tree_branch
46    {
47        it should_execute_the_command_that_is_bound_to_the_node = () => command.was_told_to(x => x.run());
48
49        context c = () =>
50        {
51            tree = dependency<TreeView>();
52            when_the(tree_node).is_told_to(x => x.TreeView).it_will_return(tree);
53            when_the(tree).is_told_to(x => x.SelectedNode).it_will_return(tree_node);
54        };
55
56        because b = () => tree.Raise(x => x.DoubleClick += null, tree, null);
57
58        static TreeView tree;
59    }
60}