Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions BPCalculator.BddTests/BMICalculator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: BMI Calculator
In order to know my BMI category
As a user
I want the system to calculate BMI correctly

Scenario Outline: BMI category scenarios
Given a height of <heightCm> cm
And a weight of <weightKg> kg
When I calculate BMI
Then the BMI category should be "<expectedCategory>"

Examples:
| heightCm | weightKg | expectedCategory |
| 170 | 50 | Underweight |
| 170 | 65 | Normal |
| 170 | 80 | Overweight |
| 170 | 100 | Obese |

Scenario: BMI borderline between Normal and Overweight
Given a height of 170 cm
And a weight of 72 kg
When I calculate BMI
Then the BMI category should be "Normal"
177 changes: 177 additions & 0 deletions BPCalculator.BddTests/BMICalculator.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions BPCalculator.BddTests/BMICalculatorSteps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using BPCalculator; // to use BMICalculator
using FluentAssertions;
using TechTalk.SpecFlow;

namespace BPCalculator.BddTests.StepDefinitions
{
[Binding]
public class BMICalculatorSteps
{
private double _heightCm;
private double _weightKg;
private (double bmi, string category) _result;

// Matches: "Given a height of <heightCm> cm"
[Given(@"a height of (.*) cm")]
public void GivenAHeightOfCm(double heightCm)
{
_heightCm = heightCm;
}

// Matches: "And a weight of <weightKg> kg"
[Given(@"a weight of (.*) kg")]
public void GivenAWeightOfKg(double weightKg)
{
_weightKg = weightKg;
}

// Matches: "When I calculate BMI"
[When(@"I calculate BMI")]
public void WhenICalculateBMI()
{
_result = BMICalculator.Calculate(_heightCm, _weightKg);
}

// Matches: Then the BMI category should be "<expectedCategory>"
[Then(@"the BMI category should be ""(.*)""")]
public void ThenTheBMICategoryShouldBe(string expectedCategory)
{
_result.category.Should().Be(expectedCategory);
_result.bmi.Should().BeGreaterThan(0);
}
}
}
36 changes: 36 additions & 0 deletions BPCalculator.BddTests/BPCalculator.BddTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<SpecFlowFeatureFiles Remove="BloodPressureCategory.feature" />
</ItemGroup>

<ItemGroup>
<None Include="BloodPressureCategory.feature" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="FluentAssertions" Version="8.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.74" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPCalculator\BPCalculator.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions BPCalculator.BddTests/BloodPressureCategory.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Blood pressure category
In order to understand my blood pressure
As a patient
I want to see the correct category for my readings

Scenario Outline: Categorise blood pressure
Given a systolic value of <Systolic>
And a diastolic value of <Diastolic>
When I calculate the blood pressure category
Then the result should be <Category>

Examples:
| Systolic | Diastolic | Category |
| 90 | 60 | Ideal |
| 110 | 70 | Ideal |
| 135 | 85 | PreHigh |
| 150 | 95 | High |
30 changes: 30 additions & 0 deletions BPCalculator.BddTests/BloodPressureCategoryBddTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using BPCalculator;
using Xunit;

namespace BPCalculator.BddTests
{
public class BloodPressureCategoryBddTests
{
[Theory(DisplayName = "BDD: Blood pressure category scenarios")]
[InlineData(90, 60, BPCategory.Ideal)]
[InlineData(110, 70, BPCategory.Ideal)]
[InlineData(135, 85, BPCategory.PreHigh)]
[InlineData(150, 95, BPCategory.High)]
public void BloodPressureCategory_Scenarios(
int systolic, int diastolic, BPCategory expectedCategory)
{
// GIVEN a blood pressure reading
var bp = new BloodPressure
{
Systolic = systolic,
Diastolic = diastolic
};

// WHEN I calculate the category
var actual = bp.Category;

// THEN the result should match the expected category
Assert.Equal(expectedCategory, actual);
}
}
}
49 changes: 49 additions & 0 deletions BPCalculator.BddTests/BloodPressureCategorySteps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using BPCalculator;
using FluentAssertions;
using TechTalk.SpecFlow;

namespace BPCalculator.BddTests.StepDefinitions
{
[Binding]
public class BloodPressureCategorySteps
{
private readonly ScenarioContext _scenarioContext;

public BloodPressureCategorySteps(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}

[Given(@"a systolic value of (.*)")]
public void GivenASystolicValueOf(int systolic)
{
var bp = new BloodPressure
{
Systolic = systolic
};

_scenarioContext["bp"] = bp;
}

[Given(@"a diastolic value of (.*)")]
public void GivenADiastolicValueOf(int diastolic)
{
var bp = (BloodPressure)_scenarioContext["bp"];
bp.Diastolic = diastolic;
}

[When(@"I calculate the blood pressure category")]
public void WhenICalculateTheBloodPressureCategory()
{
var bp = (BloodPressure)_scenarioContext["bp"];
_scenarioContext["category"] = bp.Category;
}

[Then(@"the result should be (.*)")]
public void ThenTheResultShouldBe(string expectedCategory)
{
var actual = (BPCategory)_scenarioContext["category"];
actual.ToString().Should().Be(expectedCategory);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions BPCalculator.PerformanceTests/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BPCalculator.PerformanceTests
{
public class Class1
{

}
}
Loading