Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fin #584

Closed
wants to merge 1 commit into from
Closed

fin #584

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
17 changes: 0 additions & 17 deletions csharp.NUnit/GildedRoseTests/GildedRoseTest.cs

This file was deleted.

156 changes: 156 additions & 0 deletions csharp.NUnit/GildedRoseTests/GildedRoseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System.Collections.Generic;
using GildedRoseKata;
using NUnit.Framework;

namespace GildedRoseTests;

[TestFixture]
public class GildedRoseTests
{
[TestCase(10, 20, 19, Description = "Regular item before sell date")]
[TestCase(0, 20, 18, Description = "Regular item on sell date")]
[TestCase(-1, 20, 18, Description = "Regular item after sell date")]
[TestCase(10, QualityConstants.MinQuality, QualityConstants.MinQuality,
Description = "Regular item at minimum quality")]
[TestCase(-5, QualityConstants.MinQuality, QualityConstants.MinQuality,
Description = "Regular item at minimum quality after sell date")]
public void RegularItem_QualityProgression(int sellIn, int quality, int expectedQuality)
{
// Arrange
var items = new List<Item> { TestHelper.ItemFactory.RegularItem(sellIn, quality) };
var app = new GildedRose(items);

// Act
app.UpdateQuality();

// Assert
Assert.Multiple(() =>
{
Assert.That(items[0].Quality, Is.EqualTo(expectedQuality),
$"Quality should be {expectedQuality} after update");
Assert.That(items[0].SellIn, Is.EqualTo(sellIn - 1),
"SellIn should decrease by 1");
});
}

[TestCase(5, 10, 11, Description = "Before sell date")]
[TestCase(0, 10, 12, Description = "On sell date")]
[TestCase(-1, 10, 12, Description = "After sell date")]
[TestCase(5, QualityConstants.MaxQuality, QualityConstants.MaxQuality, Description = "At maximum quality")]
[TestCase(5, QualityConstants.MaxQuality - 1, QualityConstants.MaxQuality,
Description = "Approaching maximum quality")]
[TestCase(-5, QualityConstants.MaxQuality - 2, QualityConstants.MaxQuality,
Description = "Double increase near maximum")]
public void AgedBrie_QualityProgression(int sellIn, int quality, int expectedQuality)
{
// Arrange
var items = new List<Item> { TestHelper.ItemFactory.AgedBrie(sellIn, quality) };
var app = new GildedRose(items);

// Act
app.UpdateQuality();

// Assert
Assert.Multiple(() =>
{
Assert.That(items[0].Quality, Is.EqualTo(expectedQuality));
Assert.That(items[0].SellIn, Is.EqualTo(sellIn - 1));
});
}

[TestCase(11, 20, 21, Description = ">10 days: +1")]
[TestCase(10, 20, 22, Description = "10 days: +2")]
[TestCase(5, 20, 23, Description = "5 days: +3")]
[TestCase(0, 20, 0, Description = "On concert: drops to 0")]
[TestCase(-1, 20, 0, Description = "After concert: remains 0")]
[TestCase(5, QualityConstants.MaxQuality - 1, QualityConstants.MaxQuality, Description = "Approaching maximum")]
[TestCase(5, QualityConstants.MaxQuality, QualityConstants.MaxQuality, Description = "At maximum")]
public void BackstagePasses_QualityProgression(int sellIn, int quality, int expectedQuality)
{
// Arrange
var items = new List<Item> { TestHelper.ItemFactory.BackstagePasses(sellIn, quality) };
var app = new GildedRose(items);

// Act
app.UpdateQuality();

// Assert
Assert.Multiple(() =>
{
Assert.That(items[0].Quality, Is.EqualTo(expectedQuality));
Assert.That(items[0].SellIn, Is.EqualTo(sellIn - 1));
});
}

[Test]
public void Sulfuras_NeverChanges()
{
// Arrange
var items = new List<Item> { TestHelper.ItemFactory.Sulfuras() };
var app = new GildedRose(items);

// Act
TestHelper.UpdateQualityForDays(app, 10); // Test multiple days

// Assert
Assert.Multiple(() =>
{
Assert.That(items[0].Quality, Is.EqualTo(QualityConstants.SulfurasQuality));
Assert.That(items[0].SellIn, Is.EqualTo(0));
});
}

[Test]
public void MultipleItems_UpdatedCorrectly()
{
// Arrange
var items = TestHelper.TestDataBuilder.CreateMixedInventory();
items.Add(TestHelper.ItemFactory.Sulfuras()); // Add Sulfuras to test all item types
var app = new GildedRose(items);

// Act
app.UpdateQuality();

// Assert
Assert.Multiple(() =>
{
Assert.That(items[0].Quality, Is.EqualTo(19), "Regular item");
Assert.That(items[1].Quality, Is.EqualTo(21), "Aged Brie");
Assert.That(items[2].Quality, Is.EqualTo(22), "Backstage passes");
Assert.That(items[3].Quality, Is.EqualTo(QualityConstants.SulfurasQuality), "Sulfuras");
});
}

[Test]
public void QualityThresholds_HandledCorrectly()
{
// Arrange
var items = new List<Item>
{
TestHelper.ItemFactory.CreateAtQualityThreshold(ItemNames.AgedBrie, 5, true),
TestHelper.ItemFactory.CreateAtQualityThreshold(ItemNames.BackstagePasses, 5, false)
};
var app = new GildedRose(items);

// Act
app.UpdateQuality();

// Assert
Assert.Multiple(() =>
{
Assert.That(items[0].Quality, Is.EqualTo(QualityConstants.MaxQuality), "Aged Brie at max");
Assert.That(items[1].Quality, Is.EqualTo(QualityConstants.MaxQuality), "Backstage passes reaching max");
});
}

[Test]
public void EmptyInventory_HandledGracefully()
{
// Arrange
var app = new GildedRose(new List<Item>());

// Act & Assert
Assert.DoesNotThrow(() => TestHelper.UpdateQualityForDays(app, 5),
"Should handle empty inventory for multiple days");
}
}
9 changes: 9 additions & 0 deletions csharp.NUnit/GildedRoseTests/ItemNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GildedRoseTests;

public static class ItemNames
{
public const string RegularItem = "+5 Dexterity Vest";
public const string AgedBrie = "Aged Brie";
public const string Sulfuras = "Sulfuras, Hand of Ragnaros";
public const string BackstagePasses = "Backstage passes to a TAFKAL80ETC concert";
}
8 changes: 8 additions & 0 deletions csharp.NUnit/GildedRoseTests/QualityConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GildedRoseTests;

public static class QualityConstants
{
public const int MinQuality = 0;
public const int MaxQuality = 50;
public const int SulfurasQuality = 80;
}
54 changes: 54 additions & 0 deletions csharp.NUnit/GildedRoseTests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using GildedRoseKata;

namespace GildedRoseTests;

public static class TestHelper
{
public static void UpdateQualityForDays(GildedRose app, int days)
{
for (int i = 0; i < days; i++)
{
app.UpdateQuality();
}
}

public static class ItemFactory
{
private static Item CreateItem(string name, int sellIn, int quality)
{
return new Item { Name = name, SellIn = sellIn, Quality = quality };
}

public static Item RegularItem(int sellIn = 10, int quality = 20)
=> CreateItem(ItemNames.RegularItem, sellIn, quality);

public static Item AgedBrie(int sellIn = 10, int quality = 20)
=> CreateItem(ItemNames.AgedBrie, sellIn, quality);

public static Item Sulfuras(int sellIn = 0)
=> CreateItem(ItemNames.Sulfuras, sellIn, QualityConstants.SulfurasQuality);

public static Item BackstagePasses(int sellIn = 10, int quality = 20)
=> CreateItem(ItemNames.BackstagePasses, sellIn, quality);

public static Item CreateAtQualityThreshold(string itemType, int sellIn, bool atMaximum)
{
var quality = atMaximum ? QualityConstants.MaxQuality : QualityConstants.MaxQuality - 1;
return CreateItem(itemType, sellIn, quality);
}
}

public static class TestDataBuilder
{
public static List<Item> CreateMixedInventory()
{
return new List<Item>
{
ItemFactory.RegularItem(),
ItemFactory.AgedBrie(),
ItemFactory.BackstagePasses()
};
}
}
}