Skip to content

Commit

Permalink
Mocked the Sensor in the test.
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin28 committed Apr 16, 2014
1 parent 5527b9d commit 01aa6f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TDDMicroExercises</RootNamespace>
<AssemblyName>TDDMicroExercises</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -24,6 +25,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,8 +34,12 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq">
<HintPath>packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\..\..\Program Files\NUnit 2.6.3\bin\nunit.framework.dll</HintPath>
Expand All @@ -58,6 +64,9 @@
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Moq;
using NUnit.Framework;

namespace TDDMicroExercises.TirePressureMonitoringSystem.Tests
Expand All @@ -11,8 +12,14 @@ public class AlarmTest
[Test]
public void WHEN_check_pressure_value_in_alarm_THEN_get_characterization_of_whether_alarm_is_on()
{
Alarm alarm = new Alarm(simulatedSensor);
// Given
var sensor = new Mock<Sensor>();
var alarm = new Alarm(sensor.Object);

// When
alarm.Check();

// Then
Assert.AreEqual(true, alarm.AlarmOn);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Moq;

namespace TDDMicroExercises.TirePressureMonitoringSystem
{
public class Alarm
Expand All @@ -9,6 +11,11 @@ public class Alarm

bool _alarmOn = false;

public Alarm(Sensor sensor)
{
this._sensor = sensor;
}

public void Check()
{
double psiPressureValue = _sensor.PopNextPressurePsiValue();
Expand Down

0 comments on commit 01aa6f4

Please sign in to comment.