Commit c2c1fb7
Changed files (7)
src
src/domain/domain.csproj
@@ -1,79 +1,79 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{4E400E9B-C985-49D3-BD7F-2C1D1022ECED}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>domain</RootNamespace>
- <AssemblyName>domain</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" Condition=" '$(OS)' == 'Windows_NT' " />
- <Reference Include="Microsoft.CSharp" Condition=" '$(OS)' == 'Windows_NT' " />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Greeting.cs" />
- <Compile Include="BOED.cs" />
- <Compile Include="Clock.cs" />
- <Compile Include="Capacity.cs" />
- <Compile Include="Commodity.cs" />
- <Compile Include="CommoditySplits.cs" />
- <Compile Include="DeclineCurve.cs" />
- <Compile Include="EstimatedNetProductionFor.cs" />
- <Compile Include="GasPlant.cs" />
- <Compile Include="MCF.cs" />
- <Compile Include="Month.cs" />
- <Compile Include="Months.cs" />
- <Compile Include="Oppurtunity.cs" />
- <Compile Include="Percent.cs" />
- <Compile Include="Production.cs" />
- <Compile Include="ProductionSchedule.cs" />
- <Compile Include="Quantity.cs" />
- <Compile Include="Range.cs" />
- <Compile Include="Summation.cs" />
- <Compile Include="TypeCurve.cs" />
- <Compile Include="Units.cs" />
- <Compile Include="Well.cs" />
- <Compile Include="IUnitOfMeasure.cs" />
- <Compile Include="utility\IVisitor.cs" />
- <Compile Include="utility\iterating.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(OS)' == 'Windows_NT' " />
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{4E400E9B-C985-49D3-BD7F-2C1D1022ECED}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>domain</RootNamespace>
+ <AssemblyName>domain</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" Condition=" '$(OS)' == 'Windows_NT' " />
+ <Reference Include="Microsoft.CSharp" Condition=" '$(OS)' == 'Windows_NT' " />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Greeting.cs" />
+ <Compile Include="BOED.cs" />
+ <Compile Include="Clock.cs" />
+ <Compile Include="Capacity.cs" />
+ <Compile Include="Commodity.cs" />
+ <Compile Include="CommoditySplits.cs" />
+ <Compile Include="DeclineCurve.cs" />
+ <Compile Include="EstimatedNetProductionFor.cs" />
+ <Compile Include="GasPlant.cs" />
+ <Compile Include="MCF.cs" />
+ <Compile Include="Month.cs" />
+ <Compile Include="Months.cs" />
+ <Compile Include="Oppurtunity.cs" />
+ <Compile Include="Percent.cs" />
+ <Compile Include="Production.cs" />
+ <Compile Include="ProductionSchedule.cs" />
+ <Compile Include="Quantity.cs" />
+ <Compile Include="Range.cs" />
+ <Compile Include="Summation.cs" />
+ <Compile Include="TypeCurve.cs" />
+ <Compile Include="Units.cs" />
+ <Compile Include="Well.cs" />
+ <Compile Include="IUnitOfMeasure.cs" />
+ <Compile Include="utility\IVisitor.cs" />
+ <Compile Include="utility\iterating.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(OS)' == 'Windows_NT' " />
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
src/domain/GasPlant.cs
@@ -5,7 +5,12 @@ namespace domain
using System.Collections.Generic;
using utility;
- public class GasPlant
+ public interface IFacility
+ {
+ void AcceptFlowFrom(IWell well);
+ }
+
+ public class GasPlant : IFacility
{
IList<IWell> wells;
Capacity capacity;
src/domain/TypeCurve.cs
@@ -7,6 +7,8 @@ namespace domain
{
IEnumerable<Production> production;
+ protected TypeCurve() { }
+
public TypeCurve(IEnumerable<Production> production)
{
this.production = production.ToList();
src/domain/Well.cs
@@ -10,6 +10,7 @@ namespace domain
Month initialProductionMonth;
Percent workingInterest;
TypeCurve curve;
+ IFacility facility;
public Well(Month initialProductionMonth, Percent workingInterest, TypeCurve curve)
{
@@ -27,11 +28,24 @@ namespace domain
{
return workingInterest.Reduce(GrossProductionFor<Commodity>(month));
}
+
+ public void FlowInto(IFacility facility)
+ {
+ ensure_that_this_well_is_not_already_flowing_into_a_plant();
+ this.facility = facility;
+ facility.AcceptFlowFrom(this);
+ }
+
+ void ensure_that_this_well_is_not_already_flowing_into_a_plant()
+ {
+ if(null != this.facility) throw new Exception();
+ }
}
public interface IWell
{
IQuantity GrossProductionFor<Commodity>(Month month) where Commodity : ICommodity, new();
IQuantity NetProductionFor<Commodity>(Month month) where Commodity : ICommodity, new();
+ void FlowInto(IFacility facility);
}
}
src/test/Mock.cs
@@ -9,4 +9,11 @@ namespace test
return MockRepository.GenerateMock<T>();
}
}
+ public static class Assertsions
+ {
+ public static void received<T>(this T mock,System.Action<T> action)
+ {
+ mock.AssertWasCalled(action);
+ }
+ }
}
src/test/test.csproj
@@ -1,80 +1,81 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{243D66C3-5F67-4B54-86B5-B6B76009B7FF}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>test</RootNamespace>
- <AssemblyName>test</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <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" />
- <Reference Include="System.Data.DataSetExtensions" Condition=" '$(OS)' == 'Windows_NT' " />
- <Reference Include="Microsoft.CSharp" Condition=" '$(OS)' == 'Windows_NT' " />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="GreetingSpecs.cs" />
- <Compile Include="BOEDSpecs.cs" />
- <Compile Include="CalculatorSpecs.cs" />
- <Compile Include="CapacitySpecs.cs" />
- <Compile Include="GasPlantSpecs.cs" />
- <Compile Include="MCFSpecs.cs" />
- <Compile Include="Mock.cs" />
- <Compile Include="MonthSpecs.cs" />
- <Compile Include="ProductionScheduleSpecs.cs" />
- <Compile Include="QuantitySpecs.cs" />
- <Compile Include="RangeSpecs.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\domain\domain.csproj">
- <Project>{4E400E9B-C985-49D3-BD7F-2C1D1022ECED}</Project>
- <Name>domain</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(OS)' == 'Windows_NT' " />
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{243D66C3-5F67-4B54-86B5-B6B76009B7FF}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>test</RootNamespace>
+ <AssemblyName>test</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <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" />
+ <Reference Include="System.Data.DataSetExtensions" Condition=" '$(OS)' == 'Windows_NT' " />
+ <Reference Include="Microsoft.CSharp" Condition=" '$(OS)' == 'Windows_NT' " />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="GreetingSpecs.cs" />
+ <Compile Include="BOEDSpecs.cs" />
+ <Compile Include="CalculatorSpecs.cs" />
+ <Compile Include="CapacitySpecs.cs" />
+ <Compile Include="GasPlantSpecs.cs" />
+ <Compile Include="MCFSpecs.cs" />
+ <Compile Include="Mock.cs" />
+ <Compile Include="MonthSpecs.cs" />
+ <Compile Include="ProductionScheduleSpecs.cs" />
+ <Compile Include="QuantitySpecs.cs" />
+ <Compile Include="RangeSpecs.cs" />
+ <Compile Include="WellSpecs.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\domain\domain.csproj">
+ <Project>{4E400E9B-C985-49D3-BD7F-2C1D1022ECED}</Project>
+ <Name>domain</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(OS)' == 'Windows_NT' " />
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
src/test/WellSpecs.cs
@@ -0,0 +1,60 @@
+namespace test
+{
+ using Machine.Specifications;
+ using domain;
+ using System;
+
+ public class WellSpecs
+ {
+ Establish context = () =>
+ {
+ var typeCurve = Mock.An<TypeCurve>();
+ sut = new Well(Month.Now(), 100m.Percent(), typeCurve );
+ };
+ static IWell sut;
+
+ public class when_flowing_a_gas_well_into_a_gas_plant
+ {
+ Establish context = ()=>
+ {
+ gasPlant = Mock.An<IFacility>();
+ };
+
+ static IFacility gasPlant;
+
+ public class when_the_plant_has_enough_capacity_to_accept_flow
+ {
+ It should_attempt_to_flow_in_to_the_plant=()=>
+ {
+ gasPlant.received(x => x.AcceptFlowFrom(sut));
+ };
+
+ Because of = ()=>
+ {
+ sut.FlowInto(gasPlant);
+ };
+ }
+
+ public class when_a_well_is_already_flowing_into_a_facility
+ {
+ It should_not_allow_you_to_flow_into_another_plant=()=>
+ {
+ exception.ShouldNotBeNull();
+ };
+ Establish context = ()=>
+ {
+ otherFacility = Mock.An<IFacility>();
+ };
+
+ Because of = ()=>
+ {
+ sut.FlowInto(gasPlant);
+ exception = Catch.Exception(()=> sut.FlowInto(otherFacility));
+ };
+
+ static IFacility otherFacility;
+ static Exception exception;
+ }
+ }
+ }
+}