main
 1namespace domain
 2{
 3  using System.Linq;
 4  using System.Collections.Generic;
 5  using domain;
 6  using utility;
 7
 8  public class Capacity
 9  {
10    IList<Increase> increases;
11
12    public Capacity(IQuantity initialCapacity):this(initialCapacity, Month.Now())
13    {
14    }
15
16    public Capacity(IQuantity initialCapacity, Month month)
17    {
18      this.increases = new List<Increase>();
19      this.IncreaseCapacity(initialCapacity, month);
20    }
21
22    public void IncreaseCapacity(IQuantity quantity, Month month)
23    {
24      this.increases.Add(new Increase(quantity, month));
25    }
26
27    public IQuantity AvailableFor(Month month)
28    {
29      return this.increases.Where(x => x.IsBeforeOrOn(month)).Select(x => x.IncreasedCapacity()).Sum<MCF>();
30    }
31
32    class Increase
33    {
34      IQuantity quantity;
35      Month month;
36
37      public Increase(IQuantity quantity, Month month)
38      {
39        this.quantity = quantity;
40        this.month = month;
41      }
42
43      public bool IsBeforeOrOn(Month other)
44      {
45        return month.IsBefore(other) || month.Equals(other);
46      }
47
48      public IQuantity IncreasedCapacity()
49      {
50        return this.quantity;
51      }
52    }
53  }
54}