mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Updates
- Updated CustomMethod - Updated implementation of update quality and sellin in derived classes
This commit is contained in:
parent
3ff47ce2db
commit
e625aed95a
@ -1,6 +0,0 @@
|
||||
public abstract class GuidedRoseItem {
|
||||
|
||||
abstract void UpdateQuality();
|
||||
abstract void UpdateSellIn();
|
||||
|
||||
}
|
||||
10
csharpcore/GildedRose/Abstraction/ICustomMethod.cs
Normal file
10
csharpcore/GildedRose/Abstraction/ICustomMethod.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace GildedRose.Abstraction
|
||||
{
|
||||
public interface ICustomMethod
|
||||
{
|
||||
public int SellDaysGone { get; set; }
|
||||
public abstract void UpdateQuality();
|
||||
public abstract void UpdateSellIn();
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
namespace GildedRoseKata
|
||||
using System;
|
||||
|
||||
namespace GildedRoseKata
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
|
||||
@ -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--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
csharpcore/GildedRose/Models/Elixir.cs
Normal file
22
csharpcore/GildedRose/Models/Elixir.cs
Normal 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--;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
csharpcore/GildedRose/Models/Sulfuras.cs
Normal file
20
csharpcore/GildedRose/Models/Sulfuras.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
public class Sulfuras : Item, GuidedRoseItem {
|
||||
|
||||
public override void UpdateQuality() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user