Commit d1a589f
Changed files (7)
src
domain
src/domain/utility/iterating.cs
@@ -6,9 +6,9 @@ namespace utility
public static class Iterating
{
- public static void Each<T>(this IEnumerable<T> items, Action<T> visitor){
- foreach (var item in items ?? Enumerable.Empty<T>())
- visitor(item);
+ public static void Each<T>(this IEnumerable<T> items, Action<T> visitor)
+ {
+ foreach (var item in items ?? Enumerable.Empty<T>()) visitor(item);
}
}
}
src/domain/utility/IVisitor.cs
@@ -13,7 +13,8 @@ namespace utility
{
TResult Result();
}
- public static class Visiting{
+ public static class Visiting
+ {
public static TResult AcceptAndReturnResultFrom<T, TResult>(this IVisitable<T> visitable, IValueReturningVisitor<T, TResult> visitor)
{
visitable.Accept(visitor);
src/domain/Capacity.cs
@@ -1,6 +1,9 @@
namespace domain
{
+ using System.Linq;
using System.Collections.Generic;
+ using domain;
+ using utility;
public class Capacity
{
@@ -23,12 +26,15 @@ namespace domain
public IQuantity AvailableFor(Month month)
{
- return new Quantity(0, new BOED());
- //return this
- //.increases
- //.Where(x => x.IsBeforeOrOn(month))
- //.Sum(x => x.IncreasedCapacity());
- return null;
+ IQuantity result = new Quantity(0, new MCF());
+ this
+ .increases
+ .Where(x => x.IsBeforeOrOn(month))
+ .Each(x =>
+ {
+ result = result.Plus(x.IncreasedCapacity());
+ });
+ return result;
}
class Increase
src/domain/Quantity.cs
@@ -46,7 +46,7 @@ namespace domain
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
- return other.Amount == Amount && Equals(other.Units, Units);
+ return other.Amount == Amount && Equals(other.Units.GetType(), Units.GetType());
}
public override bool Equals(object obj)
src/test/CapacitySpecs.cs
@@ -0,0 +1,32 @@
+namespace test
+{
+ using domain;
+ using Machine.Specifications;
+
+ public class CapacitySpecs
+ {
+ Establish context = () =>
+ {
+ sut = new Capacity(0m.MCF());
+ };
+
+ static Capacity sut;
+
+ public class when_checking_what_the_available_capacity_is_for_a_given_month
+ {
+ It should_return_the_correct_capacity=()=>
+ {
+ result.ShouldEqual(120m.MCF());
+ };
+
+ Because of = () =>
+ {
+ sut.IncreaseCapacity(60m.MCF(), Month.Now());
+ sut.IncreaseCapacity(60m.MCF(), Month.Now().Next());
+ result = sut.AvailableFor(Month.Now().Next());
+ };
+
+ static IQuantity result;
+ }
+ }
+}
src/test/QuantitySpecs.cs
@@ -44,5 +44,12 @@ namespace test
};
}
}
+ public class when_two_quantities_are_equal
+ {
+ It should_return_true=()=>
+ {
+ new Quantity(120, new MCF()).ShouldEqual(new Quantity(120, new MCF()));
+ };
+ }
}
}
src/test/test.csproj
@@ -56,7 +56,8 @@
<Compile Include="ProductionScheduleSpecs.cs" />
<Compile Include="QuantitySpecs.cs" />
<Compile Include="RangeSpecs.cs" />
- <!--<Compile Include="GasPlantSpecs.cs" />-->
+ <Compile Include="GasPlantSpecs.cs" />
+ <Compile Include="CapacitySpecs.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />