Commit 99fcf30
Changed files (12)
packages
packages/RhinoMocks.3.6
@@ -0,0 +1,1 @@
+Subproject commit 097bec08df4d4c150eae472aaf314da9c7d5358e
src/domain/BOED.cs
@@ -35,4 +35,13 @@ namespace domain
readonly string name = "BOED";
}
+
+ public class MCF : IUnitOfMeasure
+ {
+ public decimal Convert(decimal amount, IUnitOfMeasure units)
+ {
+ // need to do actual conversion here;
+ return amount;
+ }
+ }
}
src/domain/Clock.cs
@@ -0,0 +1,15 @@
+namespace domain
+{
+ using System;
+
+ public static class Clock
+ {
+ public static DateTime Now()
+ {
+ return time();
+ }
+
+ static Func<DateTime> defaultTime =()=> DateTime.Now;
+ static Func<DateTime> time = defaultTime;
+ }
+}
src/domain/domain.csproj
@@ -42,16 +42,19 @@
<ItemGroup>
<Compile Include="Greeting.cs" />
<Compile Include="BOED.cs" />
+ <Compile Include="Clock.cs" />
<Compile Include="Commodity.cs" />
<Compile Include="CommoditySplits.cs" />
<Compile Include="DeclineCurve.cs" />
<Compile Include="DrillSchedule.cs" />
<Compile Include="EstimatedNetProductionFor.cs" />
+ <Compile Include="GasPlant.cs" />
<Compile Include="Month.cs" />
<Compile Include="Oppurtunity.cs" />
<Compile Include="Percent.cs" />
<Compile Include="Production.cs" />
<Compile Include="Quantity.cs" />
+ <Compile Include="Range.cs" />
<Compile Include="TypeCurve.cs" />
<Compile Include="Units.cs" />
<Compile Include="Well.cs" />
src/domain/GasPlant.cs
@@ -0,0 +1,74 @@
+namespace domain
+{
+ using System;
+ using System.Linq;
+ using System.Collections.Generic;
+
+ public class GasPlant
+ {
+ IList<IWell> wells;
+ Capacity capacity;
+
+ public GasPlant()
+ {
+ this.wells = new List<IWell>();
+ this.capacity = new Capacity(0m.ToQuantity<MCF>());
+ }
+
+ public void IncreaseCapacityTo(IQuantity quantity, Month month)
+ {
+ this.capacity.IncreaseCapacity(quantity, month);
+ }
+
+ public void AcceptFlowFrom(IWell well)
+ {
+ this.wells.Add(well);
+ }
+
+ public IEnumerable<Month> MonthsOverAvailableCapacity()
+ {
+ return MonthsOverAvailableCapacity(Month.Now());
+ }
+
+ public IEnumerable<Month> MonthsOverAvailableCapacity(Month month)
+ {
+ return MonthsOverAvailableCapacity(Month.Now().UpTo(month));
+ }
+
+ public IEnumerable<Month> MonthsOverAvailableCapacity(IRange<Month> months)
+ {
+ return Enumerable.Empty<Month>();
+ }
+ }
+
+ public class Capacity
+ {
+ IList<Increase> increases;
+
+ public Capacity(IQuantity initialCapacity):this(initialCapacity, Month.Now())
+ {
+ }
+
+ public Capacity(IQuantity initialCapacity, Month month)
+ {
+ this.increases = new List<Increase>();
+ this.IncreaseCapacity(initialCapacity, month);
+ }
+
+ public void IncreaseCapacity(IQuantity quantity, Month month)
+ {
+ this.increases.Add(new Increase(quantity, month));
+ }
+
+ class Increase
+ {
+ public Increase(IQuantity quantity, Month month)
+ {
+ }
+ }
+ }
+
+ public interface IRange<T> where T : IComparable<T>
+ {
+ }
+}
src/domain/Month.cs
@@ -2,7 +2,7 @@ namespace domain
{
using System;
- public class Month
+ public class Month : IComparable<Month>
{
int year;
int month;
@@ -13,6 +13,23 @@ namespace domain
this.month = month;
}
+ public Month Plus(int months)
+ {
+ var newMonth = new DateTime(year, month, 01).AddMonths(months);
+ return new Month(newMonth.Year, newMonth.Month);
+ }
+
+ static public Month Now()
+ {
+ var now = Clock.Now();
+ return new Month(now.Year, now.Month);
+ }
+
+ public int CompareTo(Month other)
+ {
+ return new DateTime(year, month, 01).CompareTo(new DateTime(other.year, other.month, 01));
+ }
+
public bool Equals(Month other)
{
if (ReferenceEquals(null, other)) return false;
@@ -36,15 +53,16 @@ namespace domain
}
}
- public Month Plus(int months)
- {
- var newMonth = new DateTime(year, month, 01).AddMonths(months);
- return new Month(newMonth.Year, newMonth.Month);
- }
-
public override string ToString()
{
return string.Format("{0} {1}", year, month);
}
}
+ public static class Months
+ {
+ public static Month January(this int year)
+ {
+ return new Month(year,01);
+ }
+ }
}
src/domain/Range.cs
@@ -0,0 +1,12 @@
+namespace domain
+{
+ using System;
+
+ public static class Ranges
+ {
+ public static IRange<T> UpTo<T>(this T start, T end) where T: IComparable<T>
+ {
+ return null;
+ }
+ }
+}
src/domain/Units.cs
@@ -16,7 +16,17 @@ namespace domain
public static IQuantity BOED(this decimal quantity)
{
- return new Quantity(quantity, new BOED());
+ return quantity.ToQuantity<BOED>();
+ }
+
+ static public IQuantity MCF(this decimal quantity)
+ {
+ return quantity.ToQuantity<MCF>();
+ }
+
+ static public IQuantity ToQuantity<T>(this decimal quantity) where T: IUnitOfMeasure,new()
+ {
+ return new Quantity(quantity, new T());
}
}
}
src/test/GasPlantSpecs.cs
@@ -2,7 +2,10 @@ namespace test
{
using System.Linq;
using System.Collections.Generic;
+ using Machine.Specifications;
using Rhino.Mocks;
+ using domain;
+ using utility;
public class GasPlantSpecs
{
@@ -37,7 +40,9 @@ namespace test
results = sut.MonthsOverAvailableCapacity().ToList();
};
- IEnumerable<Month> results;
+ static IEnumerable<Month> results;
+ static IWell firstWell;
+ static IWell secondWell;
}
}
}
src/test/Mock.cs
@@ -1,8 +1,10 @@
namespace test
{
+ using Rhino.Mocks;
+
public static class Mock
{
- public static T An<T>()
+ public static T An<T>() where T : class
{
return MockRepository.GenerateMock<T>();
}
src/test/MonthSpecs.cs
@@ -0,0 +1,24 @@
+namespace test
+{
+ using Machine.Specifications;
+ using domain;
+
+ public class MonthSpecs
+ {
+ public class when_comparing_months
+ {
+ It should_return_a_positive_number_when_the_first_month_is_greater_than_the_second_month =()=>
+ {
+ new Month(2012, 05).CompareTo(new Month(2012, 04)).ShouldBeGreaterThan(0);
+ };
+ It should_return_a_negative_number_when_the_first_month_is_less_than_the_second_month =()=>
+ {
+ new Month(2012, 04).CompareTo(new Month(2012, 05)).ShouldBeLessThan(0);
+ };
+ It should_return_a_zero_when_the_first_month_is_equal_to_the_second_month =()=>
+ {
+ new Month(2012, 04).CompareTo(new Month(2012, 04)).ShouldEqual(0);
+ };
+ }
+ }
+}
src/test/test.csproj
@@ -34,6 +34,9 @@
<Reference Include="Machine.Specifications">
<HintPath>..\..\packages\Machine.Specifications.0.5.3.0\lib\Machine.Specifications.dll</HintPath>
</Reference>
+ <Reference Include="Rhino.Mocks">
+ <HintPath>..\..\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -46,6 +49,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GreetingSpecs.cs" />
<Compile Include="CalculatorSpecs.cs" />
+ <Compile Include="GasPlantSpecs.cs" />
+ <Compile Include="MonthSpecs.cs" />
<Compile Include="ProductionScheduleSpecs.cs" />
<Compile Include="Mock.cs" />
</ItemGroup>