main
 1namespace domain
 2{
 3  using System;
 4  using System.Linq;
 5  using System.Collections.Generic;
 6  using utility;
 7
 8  public interface IFacility 
 9  {
10    void AcceptFlowFrom(IWell well);
11    IQuantity AvailableCapacityFor(Month month);
12  }
13
14  public class GasPlant : IFacility
15  {
16    IList<IWell> wells;
17    Capacity capacity;
18
19    public GasPlant()
20    {
21      this.wells = new List<IWell>();
22      this.capacity = new Capacity(0m.ToQuantity<MCF>());
23    }
24
25    public void IncreaseCapacityTo(IQuantity quantity, Month month)
26    {
27      this.capacity.IncreaseCapacity(quantity, month);
28    }
29
30    public void AcceptFlowFrom(IWell well)
31    {
32      this.wells.Add(well);
33    }
34
35    public IEnumerable<Month> MonthsOverAvailableCapacity()
36    {
37      return MonthsOverAvailableCapacity(Month.Now().UpTo(Month.Infinity));
38    }
39
40    public virtual IQuantity AvailableCapacityFor(Month month)
41    {
42      return capacity.AvailableFor(month);
43    }
44
45    public IEnumerable<Month> MonthsOverAvailableCapacity(IRange<Month> months)
46    {
47      return months.Collect( month =>
48      {
49        return IsOverCapacity(month);
50      });
51    }
52
53    bool IsOverCapacity(Month month)
54    {
55      return AvailableCapacityFor(month).IsGreaterThan(TotalProductionFor(month));
56    }
57
58    IQuantity TotalProductionFor(Month month)
59    {
60      return wells.Select(well => well.GrossProductionFor<Gas>(month)).Sum<BOED>();
61    }
62  }
63}