mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 17:21:38 +00:00
Refactoring c# projects
This commit is contained in:
parent
ad19854a2f
commit
786dd3c5cd
@ -1,7 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>GildedRoseKata</RootNamespace>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GildedRoseKata;
|
||||
|
||||
namespace GildedRoseTests;
|
||||
namespace GildedRoseKata;
|
||||
|
||||
public static class TextTestFixture
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("OMGHAI!");
|
||||
|
||||
var items = new List<Item>{
|
||||
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},
|
||||
@ -34,19 +34,15 @@ public static class TextTestFixture
|
||||
SellIn = 5,
|
||||
Quality = 49
|
||||
},
|
||||
|
||||
// this conjured item does not work properly yet
|
||||
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
|
||||
};
|
||||
|
||||
var app = new GildedRose(items);
|
||||
|
||||
int days = 2;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
days = int.Parse(args[0]) + 1;
|
||||
}
|
||||
|
||||
for (var i = 0; i < days; i++)
|
||||
for (var i = 0; i < 31; i++)
|
||||
{
|
||||
Console.WriteLine("-------- day " + i + " --------");
|
||||
Console.WriteLine("name, sellIn, quality");
|
||||
@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GildedRoseKata;
|
||||
using NUnit.Framework;
|
||||
using VerifyNUnit;
|
||||
|
||||
@ -16,7 +17,7 @@ public class ApprovalTest
|
||||
Console.SetOut(new StringWriter(fakeOutput));
|
||||
Console.SetIn(new StringReader($"a{Environment.NewLine}"));
|
||||
|
||||
TextTestFixture.Main(new string[] { "30" });
|
||||
Program.Main(new string[] { "30" });
|
||||
var output = fakeOutput.ToString();
|
||||
|
||||
return Verifier.Verify(output);
|
||||
|
||||
@ -1,89 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GildedRoseKata
|
||||
namespace GildedRoseKata;
|
||||
|
||||
public class GildedRose
|
||||
{
|
||||
public class GildedRose
|
||||
private readonly IList<Item> _items;
|
||||
|
||||
public GildedRose(IList<Item> items)
|
||||
{
|
||||
IList<Item> Items;
|
||||
public GildedRose(IList<Item> Items)
|
||||
{
|
||||
this.Items = Items;
|
||||
}
|
||||
_items = items;
|
||||
}
|
||||
|
||||
public void UpdateQuality()
|
||||
public void UpdateQuality()
|
||||
{
|
||||
for (var i = 0; i < _items.Count; i++)
|
||||
{
|
||||
for (var i = 0; i < Items.Count; i++)
|
||||
if (_items[i].Name != "Aged Brie" && _items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
if (_items[i].Quality > 0)
|
||||
{
|
||||
if (Items[i].Quality > 0)
|
||||
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 1;
|
||||
}
|
||||
_items[i].Quality = _items[i].Quality - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
|
||||
if (_items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
|
||||
if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
|
||||
if (_items[i].SellIn < 11)
|
||||
{
|
||||
if (Items[i].SellIn < 11)
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
}
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Items[i].SellIn < 6)
|
||||
if (_items[i].SellIn < 6)
|
||||
{
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
}
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].SellIn = Items[i].SellIn - 1;
|
||||
}
|
||||
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
_items[i].SellIn = _items[i].SellIn - 1;
|
||||
}
|
||||
|
||||
if (Items[i].SellIn < 0)
|
||||
if (_items[i].SellIn < 0)
|
||||
{
|
||||
if (_items[i].Name != "Aged Brie")
|
||||
{
|
||||
if (Items[i].Name != "Aged Brie")
|
||||
if (_items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
if (_items[i].Quality > 0)
|
||||
{
|
||||
if (Items[i].Quality > 0)
|
||||
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 1;
|
||||
}
|
||||
_items[i].Quality = _items[i].Quality - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - Items[i].Quality;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
}
|
||||
_items[i].Quality = _items[i].Quality - _items[i].Quality;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<StartupObject>GildedRoseKata.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>GildedRoseKata</RootNamespace>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<StartupObject>GildedRoseKata.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
@ -1,9 +1,8 @@
|
||||
namespace GildedRoseKata
|
||||
namespace GildedRoseKata;
|
||||
|
||||
public class Item
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int SellIn { get; set; }
|
||||
public int Quality { get; set; }
|
||||
}
|
||||
}
|
||||
public string Name { get; set; }
|
||||
public int SellIn { get; set; }
|
||||
public int Quality { get; set; }
|
||||
}
|
||||
@ -1,56 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GildedRoseKata
|
||||
namespace GildedRoseKata;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public class Program
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
Console.WriteLine("OMGHAI!");
|
||||
|
||||
IList<Item> items = new List<Item>
|
||||
{
|
||||
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
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 15,
|
||||
Quality = 20
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 10,
|
||||
Quality = 49
|
||||
},
|
||||
new Item
|
||||
{
|
||||
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}
|
||||
};
|
||||
|
||||
var app = new GildedRose(Items);
|
||||
|
||||
|
||||
for (var i = 0; i < 31; i++)
|
||||
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
|
||||
{
|
||||
Console.WriteLine("-------- day " + i + " --------");
|
||||
Console.WriteLine("name, sellIn, quality");
|
||||
for (var j = 0; j < Items.Count; j++)
|
||||
{
|
||||
System.Console.WriteLine(Items[j].Name + ", " + Items[j].SellIn + ", " + Items[j].Quality);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
app.UpdateQuality();
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 15,
|
||||
Quality = 20
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 10,
|
||||
Quality = 49
|
||||
},
|
||||
new Item
|
||||
{
|
||||
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}
|
||||
};
|
||||
|
||||
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++)
|
||||
{
|
||||
Console.WriteLine(items[j].Name + ", " + items[j].SellIn + ", " + items[j].Quality);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
app.UpdateQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
|
||||
using GildedRoseKata;
|
||||
using GildedRoseKata;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
@ -10,21 +9,20 @@ using VerifyXunit;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace GildedRoseTests
|
||||
namespace GildedRoseTests;
|
||||
|
||||
public class ApprovalTest
|
||||
{
|
||||
public class ApprovalTest
|
||||
[Fact]
|
||||
public Task ThirtyDays()
|
||||
{
|
||||
[Fact]
|
||||
public Task ThirtyDays()
|
||||
{
|
||||
var fakeoutput = new StringBuilder();
|
||||
Console.SetOut(new StringWriter(fakeoutput));
|
||||
Console.SetIn(new StringReader("a\n"));
|
||||
var fakeoutput = new StringBuilder();
|
||||
Console.SetOut(new StringWriter(fakeoutput));
|
||||
Console.SetIn(new StringReader("a\n"));
|
||||
|
||||
Program.Main(new string[] { "30" });
|
||||
var output = fakeoutput.ToString();
|
||||
Program.Main(new string[] { "30" });
|
||||
var output = fakeoutput.ToString();
|
||||
|
||||
return Verifier.Verify(output);
|
||||
}
|
||||
return Verifier.Verify(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,17 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using GildedRoseKata;
|
||||
|
||||
namespace GildedRoseTests
|
||||
namespace GildedRoseTests;
|
||||
|
||||
public class GildedRoseTest
|
||||
{
|
||||
public class GildedRoseTest
|
||||
[Fact]
|
||||
public void foo()
|
||||
{
|
||||
[Fact]
|
||||
public void foo()
|
||||
{
|
||||
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
||||
GildedRose app = new GildedRose(Items);
|
||||
app.UpdateQuality();
|
||||
Assert.Equal("fixme", Items[0].Name);
|
||||
}
|
||||
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
||||
GildedRose app = new GildedRose(Items);
|
||||
app.UpdateQuality();
|
||||
Assert.Equal("fixme", Items[0].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user