Initial commit

This commit is contained in:
Your Name
2026-09-29 16:28:20 +00:00
commit 17e5d25b39
28 changed files with 961 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
using IceCreamBuyers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace IceCreamBuyers.Tests
{
[TestClass]
public class BuyersTests
{
[TestMethod]
public void ShoppingListTotalUsesThePricingWePassIn()
{
// pure pricing function: everything costs 2.
// Anke: 2 flavours x 2 scoops x 2 = 8 — deterministic, glanceable.
var buyers = new Buyers();
var anke = new Buyer("Anke", new List<IceCream> { IceCream.Strawberry, IceCream.Vanilla });
Assert.AreEqual(8, buyers.ShoppingListTotal(anke, _ => 2));
}
}
}
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\solution\Buyers\Buyers.csproj" />
</ItemGroup>
</Project>
+19
View File
@@ -0,0 +1,19 @@
using IceCreamBuyers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IceCreamBuyers.Tests
{
[TestClass]
public class BuyersTests
{
[TestMethod]
public void ShoppingListTotal()
{
// Anke: 2 flavours x 2 scoops x base prices (3 + 2) = 10.
// Red or flaky — why? (PriceList adds random surge pricing;
// it stands for the external pricing service.)
var buyers = new Buyers();
Assert.AreEqual(10, buyers.ShoppingListTotal("Anke"));
}
}
}
+20
View File
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Buyers\Buyers.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,82 @@
// Tests for the three Slice-with-Lambda solutions — step 4: the lambda as a stub.
//
// Condensed mechanics: https://sammancoaching.org/refactorings/slice.html
// (where that page says mock, we use a lambda instead).
using System;
using Xunit;
public class SliceWithLambdaTests
{
// --- Example 1: metaphor-free (Calculator) ---
[Fact]
public void Guards_against_negative_input()
{
var calc = new Calculator(new SomeDependency()); // the real, flaky one...
Assert.Equal(0, calc.Calculate(-1, a => 42)); // ...never asked: stub not invoked
}
[Fact]
public void Throws_when_precondition_not_satisfied()
{
var calc = new Calculator(new SomeDependency());
Assert.Throws<InvalidOperationException>(
() => calc.Calculate(7, a => throw new InvalidOperationException()));
}
[Fact]
public void Combines_input_and_the_stubbed_value()
{
var calc = new Calculator(new SomeDependency());
Assert.Equal(84, calc.Calculate(0, a => 42)); // stub through the seam
}
// --- Example 2: Weather Station (SprinklerController) ---
[Fact]
public void Skips_watering_when_already_watered()
{
var controller = new SprinklerController(() => 200); // pure lambda: no sensor
controller.ScheduleWatering(); // water once...
Assert.Equal(WateringDuration.None, controller.ScheduleWatering());
}
[Fact]
public void Waters_longer_in_full_sun()
{
var controller = new SprinklerController(() => 200); // sunny: > 128
Assert.Equal(WateringDuration.Medium, controller.ScheduleWatering());
}
[Fact]
public void Waters_less_in_the_shade()
{
var controller = new SprinklerController(() => 10); // shady: ≤ 128
Assert.Equal(WateringDuration.Short, controller.ScheduleWatering());
}
// --- Example 3: Ice Cream Shop (IceCreamShop) ---
[Fact]
public void Skips_thawing_when_already_thawed()
{
var shop = new IceCreamShop(() => 30); // pure lambda: no freezer
shop.ThawStock(); // thaw once...
Assert.Equal(ThawAmount.None, shop.ThawStock());
}
[Fact]
public void Thaws_more_when_warm()
{
var shop = new IceCreamShop(() => 30); // warm: > 25
Assert.Equal(ThawAmount.Medium, shop.ThawStock());
}
[Fact]
public void Thaws_less_when_cold()
{
var shop = new IceCreamShop(() => 5); // cold: ≤ 25
Assert.Equal(ThawAmount.Low, shop.ThawStock());
}
}
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\solution\SliceWithLambda\SliceWithLambda.csproj" />
</ItemGroup>
</Project>