main
 1namespace test
 2{
 3  using Machine.Specifications;
 4  using domain;
 5  using System;
 6  using Rhino.Mocks;
 7
 8  public class WellSpecs
 9  {
10    Establish context = () =>
11    {
12      typeCurve = Mock.An<TypeCurve>();
13      sut = new Well(Month.Now(), 100m.Percent(), typeCurve );
14    };
15    static IWell sut;
16    static TypeCurve typeCurve;
17
18    public class when_flowing_a_gas_well_into_a_gas_plant
19    {
20      Establish context = ()=>
21      {
22        gasPlant = Mock.An<IFacility>();
23      };
24
25      static IFacility gasPlant;
26
27      public class when_the_plant_has_enough_capacity_to_accept_flow
28      {
29        It should_attempt_to_flow_in_to_the_plant=()=>
30        {
31          gasPlant.received(x => x.AcceptFlowFrom(sut));
32        };
33
34        Because of = ()=>
35        {
36          sut.FlowInto(gasPlant);
37        };
38      }
39
40      public class when_the_plant_would_overflow_if_it_accepted_flow_from_this_well
41      {
42        It should_not_let_you_flow_this_well_into_the_facility=()=>
43        {
44          exception.ShouldNotBeNull();
45        };
46
47        Establish context = ()=>
48        {
49          var jan2013 = 2013.January();
50          var feb2013 = 2013.February();
51          typeCurve
52            .Stub(x => x.Accept( Arg<Action<Production>>.Is.Anything ))
53            .WhenCalled(x => 
54            {
55              var splits = new CommoditySplits();
56              splits.SplitFor<Gas>(100m.Percent());
57              var action = x.Arguments[0] as Action<Production>;
58              action(new Production(jan2013,100m.BOED(),splits ));
59              action(new Production(feb2013, 91m.BOED(), splits));
60            });
61          gasPlant.Stub(x => x.AvailableCapacityFor(jan2013)).Return(100m.BOED());
62          gasPlant.Stub(x => x.AvailableCapacityFor(feb2013)).Return(90m.BOED());
63        };
64
65        Because of = ()=>
66        {
67          exception = Catch.Exception(()=> sut.FlowInto(gasPlant));
68        };
69
70        static Exception exception;
71      }
72
73      public class when_a_well_is_already_flowing_into_a_facility 
74      {
75        It should_not_allow_you_to_flow_into_another_plant=()=>
76        {
77          exception.ShouldNotBeNull();
78        };
79        Establish context = ()=>
80        {
81          otherFacility = Mock.An<IFacility>();
82        };
83
84        Because of = ()=>
85        {
86          sut.FlowInto(gasPlant);
87          exception = Catch.Exception(()=> sut.FlowInto(otherFacility));
88        };
89
90        static IFacility otherFacility;
91        static Exception exception;
92      }
93    }
94  }
95}