diff options
| author | mo k <mo@mokhan.ca> | 2012-04-24 12:47:19 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-04-24 12:47:19 -0600 |
| commit | c2c1fb71a2ad3120ce3ef3298eae9793b23d6d74 (patch) | |
| tree | 7a04184fb14028ddd36cc097b7bcd4ce3861ed0c | |
| parent | 34951186809838792232f5c204529224f2a4becd (diff) | |
start flowing a well into a facility.
| -rw-r--r-- | src/domain/GasPlant.cs | 7 | ||||
| -rw-r--r-- | src/domain/TypeCurve.cs | 2 | ||||
| -rw-r--r-- | src/domain/Well.cs | 14 | ||||
| -rwxr-xr-x | src/domain/domain.csproj | 158 | ||||
| -rw-r--r-- | src/test/Mock.cs | 7 | ||||
| -rw-r--r-- | src/test/WellSpecs.cs | 60 | ||||
| -rwxr-xr-x | src/test/test.csproj | 161 |
7 files changed, 249 insertions, 160 deletions
diff --git a/src/domain/GasPlant.cs b/src/domain/GasPlant.cs index f8b2b00..30587d5 100644 --- a/src/domain/GasPlant.cs +++ b/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; diff --git a/src/domain/TypeCurve.cs b/src/domain/TypeCurve.cs index ba3d954..c5c0f52 100644 --- a/src/domain/TypeCurve.cs +++ b/src/domain/TypeCurve.cs @@ -7,6 +7,8 @@ namespace domain { IEnumerable<Production> production; + protected TypeCurve() { } + public TypeCurve(IEnumerable<Production> production) { this.production = production.ToList(); diff --git a/src/domain/Well.cs b/src/domain/Well.cs index 498a3f9..835e8b2 100644 --- a/src/domain/Well.cs +++ b/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); } } diff --git a/src/domain/domain.csproj b/src/domain/domain.csproj index 21727d3..29ff5e2 100755 --- a/src/domain/domain.csproj +++ b/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> diff --git a/src/test/Mock.cs b/src/test/Mock.cs index bcee615..b4caf04 100644 --- a/src/test/Mock.cs +++ b/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); + } + } } diff --git a/src/test/WellSpecs.cs b/src/test/WellSpecs.cs new file mode 100644 index 0000000..4b22d59 --- /dev/null +++ b/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; + } + } + } +} diff --git a/src/test/test.csproj b/src/test/test.csproj index 1a0edec..093b20e 100755 --- a/src/test/test.csproj +++ b/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> |
