- Updated CustomMethod
- Updated implementation of update quality and sellin in derived classes
This commit is contained in:
Adefolarin Adeniji 2021-08-27 15:01:36 +01:00
parent 3ff47ce2db
commit e625aed95a
12 changed files with 159 additions and 48 deletions

View File

@ -1,6 +0,0 @@
public abstract class GuidedRoseItem {
abstract void UpdateQuality();
abstract void UpdateSellIn();
}

View File

@ -0,0 +1,10 @@
namespace GildedRose.Abstraction
{
public interface ICustomMethod
{
public int SellDaysGone { get; set; }
public abstract void UpdateQuality();
public abstract void UpdateSellIn();
}
}

View File

@ -1,4 +1,6 @@
namespace GildedRoseKata
using System;
namespace GildedRoseKata
{
public class Item
{

View File

@ -1,9 +1,23 @@
public class AgedBrie : Item, GuidedRoseItem {
public override void UpdateQuality() {
using GildedRose.Abstraction;
using GildedRoseKata;
namespace GildedRose.Models
{
public class AgedBrie : Item, ICustomMethod
{
public int SellDaysGone { get; set; }
public void UpdateQuality() {
if (this.Quality < 51)
{
this.Quality++;
}
}
public void UpdateSellIn()
{
if (this.SellIn > 0)
this.SellIn--;
}
}
}

View File

@ -1,9 +1,36 @@
public class BackStagePasses : Item, GuidedRoseItem {
using GildedRose.Abstraction;
using GildedRoseKata;
public override void UpdateQuality() {
namespace GildedRose.Models
{
public class BackStagePasses : Item, ICustomMethod
{
public int SellDaysGone { get; set; }
public void UpdateQuality()
{
if (this.SellDaysGone > this.SellIn)
{
this.Quality = 0;
}
if ((this.SellIn - this.SellDaysGone) <= 5)
{
if (this.Quality < 51)
this.Quality += 3;
}
if ((this.SellIn - this.SellDaysGone) <= 10)
{
if (this.Quality < 51)
this.Quality += 2;
}
}
public void UpdateSellIn()
{
if (this.SellIn > 0)
this.SellIn--;
}
}
}

View File

@ -1,9 +1,22 @@
public class Conjured : Item, GuidedRoseItem {
public override void UpdateQuality() {
using GildedRose.Abstraction;
using GildedRoseKata;
namespace GildedRose.Models
{
public class Conjured : Item, ICustomMethod
{
public int SellDaysGone { get; set; }
public void UpdateQuality()
{
if (this.SellDaysGone > this.SellIn && this.Quality > 1)
this.Quality -= 2;
}
public void UpdateSellIn()
{
if (this.SellIn > 0)
this.SellIn--;
}
}
}

View File

@ -1,9 +1,22 @@
public class Dexterity : Item, GuidedRoseItem {
public override void UpdateQuality() {
using GildedRose.Abstraction;
using GildedRoseKata;
namespace GildedRose.Models
{
public class Dexterity : Item, ICustomMethod
{
public int SellDaysGone { get; set; }
public void UpdateQuality()
{
if (this.SellDaysGone > this.SellIn && this.Quality > 0)
this.Quality--;
}
public void UpdateSellIn()
{
if (this.SellIn > 0)
this.SellIn--;
}
}
}

View File

@ -0,0 +1,22 @@
using GildedRose.Abstraction;
using GildedRoseKata;
namespace GildedRose.Models
{
public class Elixir : Item, ICustomMethod
{
public int SellDaysGone { get; set; }
public void UpdateQuality()
{
if (this.SellDaysGone > this.SellIn && this.Quality > 0)
this.Quality --;
}
public void UpdateSellIn()
{
if (this.SellIn > 0)
this.SellIn--;
}
}
}

View File

@ -0,0 +1,20 @@
using GildedRose.Abstraction;
using GildedRoseKata;
namespace GildedRose.Models
{
public class Sulfuras : Item, ICustomMethod
{
public int SellDaysGone { get; set; }
public void UpdateQuality()
{
// do thing
}
public void UpdateSellIn()
{
// do nothing
}
}
}

View File

@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using GildedRose.Models;
namespace GildedRoseKata
{
@ -9,45 +12,47 @@ namespace GildedRoseKata
{
Console.WriteLine("OMGHAI!");
IList<Item> Items = new List<Item>{
new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80},
new Item
IList<Item> items = new List<Item>{
new Dexterity() {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
new AgedBrie() {Name = "Aged Brie", SellIn = 2, Quality = 0},
new Elixir() {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},
new Sulfuras() {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
new Sulfuras {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80},
new BackStagePasses()
{
Name = "Backstage passes to a TAFKAL80ETC concert",
SellIn = 15,
Quality = 20
},
new Item
new BackStagePasses
{
Name = "Backstage passes to a TAFKAL80ETC concert",
SellIn = 10,
Quality = 49
},
new Item
new BackStagePasses
{
Name = "Backstage passes to a TAFKAL80ETC concert",
SellIn = 5,
Quality = 49
},
// this conjured item does not work properly yet
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
new Conjured() {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
};
var app = new GildedRose(Items);
var app = new GildedRose(items);
for (var i = 0; i < 31; i++)
{
Console.WriteLine("-------- day " + i + " --------");
Console.WriteLine("name, sellIn, quality");
for (var j = 0; j < Items.Count; j++)
foreach (Item t in items)
{
System.Console.WriteLine(Items[j].Name + ", " + Items[j].SellIn + ", " + Items[j].Quality);
Console.WriteLine(t.Name + ", " + t.SellIn + ", " + t.Quality);
}
Console.WriteLine("");
app.UpdateQuality();
}

View File

@ -1,9 +0,0 @@
public class Sulfuras : Item, GuidedRoseItem {
public override void UpdateQuality() {
}
}

View File

@ -10,7 +10,7 @@ namespace GildedRoseTests
public void foo()
{
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
GildedRose app = new GildedRose(Items);
GildedRoseKata.GildedRose app = new GildedRoseKata.GildedRose(Items);
app.UpdateQuality();
Assert.Equal("fixme", Items[0].Name);
}