Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created January 14, 2025 03:31
Show Gist options
  • Save trikitrok/172c74b4fb547dcf3e7c2bde4dad8431 to your computer and use it in GitHub Desktop.
Save trikitrok/172c74b4fb547dcf3e7c2bde4dad8431 to your computer and use it in GitHub Desktop.
Legacy Argent Rose tests with 100% coverage but many mutants still alive
using NUnit.Framework;
using static ArgentRose.Tests.ArgentRoseStoreForTesting;
namespace ArgentRose.Tests;
public class ArgentRoseStoreTest
{
[Test]
public void Regular_Product_Decreases_Quality_By_Two()
{
var store = StoreIncluding(RegularProduct(1, 10));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(RegularProduct(0, 8))));
}
[Test]
public void Expired_Regular_Product_Decreases_Quality_Twice_As_Fast()
{
var store = StoreIncluding(RegularProduct(-1, 10));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(RegularProduct(-2, 6))));
}
[Test]
public void Lanzarote_Wine_Increases_Quality_By_One()
{
var store = StoreIncluding(LanzaroteWine(3, 10));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(LanzaroteWine(2, 12))));
}
[Test]
public void Expired_Lanzarote_Wine_Increases_Quality_Twice_As_Fast()
{
var store = StoreIncluding(LanzaroteWine(-5, 10));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(LanzaroteWine(-6, 14))));
}
[Test]
public void Expired_Theatre_Passes_Drop_Quality_To_Zero()
{
var store = StoreIncluding(TheatrePasses(0, 5));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(TheatrePasses(-1, 0))));
}
[Test]
public void Theatre_Passes_Increase_Quality_By_Three_When_Sell_In_Is_Near()
{
var store = StoreIncluding(TheatrePasses(3, 12));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(TheatrePasses(2, 15))));
}
[Test]
public void Theatre_Passes_Increase_Quality_By_One_When_Sell_In_Is_Far_Away()
{
var store = StoreIncluding(TheatrePasses(9, 12));
store.Update();
Assert.That(
store.SavedInventory,
Is.EqualTo(InventoryIncluding(TheatrePasses(8, 13))));
}
private static Product RegularProduct(int sellIn, int quality)
{
return new Product("RegularProduct", sellIn, quality);
}
private static Product LanzaroteWine(int sellIn, int quality)
{
return new Product("Lanzarote Wine", sellIn, quality);
}
private static Product TheatrePasses(int sellIn, int quality)
{
return new Product("Theatre Passes", sellIn, quality);
}
private static List<Product> InventoryIncluding(params Product[] products)
{
return products.ToList();
}
}
public class ArgentRoseStoreForTesting : ArgentRoseStore
{
private List<Product> _savedInventory;
private readonly List<Product> _initialInventory;
public static ArgentRoseStoreForTesting StoreIncluding(params Product[] products)
{
return new ArgentRoseStoreForTesting(products.ToList());
}
private ArgentRoseStoreForTesting(List<Product> initialInventory)
{
_savedInventory = new List<Product>();
_initialInventory = initialInventory;
}
protected override List<Product> GetInventoryFromDb()
{
return _initialInventory;
}
protected override void SaveInventory(List<Product> inventory)
{
_savedInventory = inventory;
}
public List<Product> SavedInventory => _savedInventory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment