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
27 changes: 24 additions & 3 deletions csharpcore60/ShiMart/ShiMart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;

using System.Collections.Generic;

namespace ShiMartKata
{
Expand All @@ -10,6 +11,17 @@ public ShiMart(IList<Item> Items)
this.Items = Items;
}

// TODO:Increase code readbility
// 1. Reduce if conditions
// 2. Refacor code in more methods
// 3. Refactor SellIn logic in a new method : UpdateSellIn. Note: QualityCalulation is dependent on SellIn Value


// Make the program item independent
// 1. Item.cs in a class ItemWithType.cs, inherits Item.cs
// 2. Use Builder pattern for BuildingItem
// 3. It requires creation of centeraliztion of multiple type of items and handle related busisness logic,
// I would prefer, use Abstarct Factory Pattern for different type of items
public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
Expand All @@ -30,10 +42,15 @@ public void UpdateQuality()
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Canned Beans")
if (Items[i].Name != "Canned Beans" && !Items[i].Name.Contains("Baked"))
{
Items[i].Quality = Items[i].Quality - 1;
}

if (Items[i].Name.Contains("Baked"))
{
Items[i].Quality = Items[i].Quality - 2;
}
}
}

Expand All @@ -50,10 +67,14 @@ public void UpdateQuality()
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Canned Beans")
if (Items[i].Name != "Canned Beans" && !Items[i].Name.Contains("Baked"))
{
Items[i].Quality = Items[i].Quality - 1;
}
if (Items[i].Name.Contains("Baked"))
{
Items[i].Quality = Items[i].Quality - 2;
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions csharpcore60/ShiMartTest/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,29 @@ public void Test1()
Assert.Equal(9, items.First().SellIn);
Assert.Equal(19, items.First().Quality);
}

[Fact]
public void VerifyBakedItem()
{
var items = new List<Item> { new Item { Name = "Baked Sourdough Bread", SellIn = 10, Quality = 20 } };
var app = new ShiMart(items);

app.UpdateQuality();

Assert.Equal(9, items.First().SellIn);
Assert.Equal(18, items.First().Quality);
}

[Fact]
public void VerifyBakedItemAfterExpiry()
{
var items = new List<Item> { new Item { Name = "Baked Sourdough Bread", SellIn = -1, Quality = 20 } };
var app = new ShiMart(items);

app.UpdateQuality();

Assert.Equal(-2, items.First().SellIn);
Assert.Equal(16, items.First().Quality);
}
}
}