From b6536a2cfcd6de7bf3e106b86c4bb5138770ca7c Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 27 Apr 2021 11:15:31 +0200 Subject: [PATCH] Unit Tests - Still completing unit tests - modified very minor things with comments. - check readme.md for more comments --- csharp/ApprovalTest.ThirtyDays.received.txt | 373 ++++++++++++++++++++ csharp/ApprovalTest.cs | 48 +-- csharp/GildedRose.cs | 50 +-- csharp/GildedRoseTest.cs | 34 +- csharp/Program.cs | 4 +- csharp/README.md | 9 + csharp/csharp.sln | 13 +- csharpTests/GildedRoseUnitTests.cs | 69 ++++ csharpTests/Properties/AssemblyInfo.cs | 36 ++ csharpTests/csharpTests.csproj | 106 ++++++ csharpTests/packages.config | 5 + 11 files changed, 678 insertions(+), 69 deletions(-) create mode 100644 csharp/ApprovalTest.ThirtyDays.received.txt create mode 100644 csharpTests/GildedRoseUnitTests.cs create mode 100644 csharpTests/Properties/AssemblyInfo.cs create mode 100644 csharpTests/csharpTests.csproj create mode 100644 csharpTests/packages.config diff --git a/csharp/ApprovalTest.ThirtyDays.received.txt b/csharp/ApprovalTest.ThirtyDays.received.txt new file mode 100644 index 00000000..cd66984f --- /dev/null +++ b/csharp/ApprovalTest.ThirtyDays.received.txt @@ -0,0 +1,373 @@ +OMGHAI! +-------- day 0 -------- +name, sellIn, quality ++5 Dexterity Vest, 10, 20 +Aged Brie, 2, 0 +Elixir of the Mongoose, 5, 7 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 15, 20 +Backstage passes to a TAFKAL80ETC concert, 10, 49 +Backstage passes to a TAFKAL80ETC concert, 5, 49 +Conjured Mana Cake, 3, 6 + +-------- day 1 -------- +name, sellIn, quality ++5 Dexterity Vest, 9, 19 +Aged Brie, 1, 1 +Elixir of the Mongoose, 4, 6 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 14, 21 +Backstage passes to a TAFKAL80ETC concert, 9, 50 +Backstage passes to a TAFKAL80ETC concert, 4, 50 +Conjured Mana Cake, 2, 5 + +-------- day 2 -------- +name, sellIn, quality ++5 Dexterity Vest, 8, 18 +Aged Brie, 0, 2 +Elixir of the Mongoose, 3, 5 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 13, 22 +Backstage passes to a TAFKAL80ETC concert, 8, 50 +Backstage passes to a TAFKAL80ETC concert, 3, 50 +Conjured Mana Cake, 1, 4 + +-------- day 3 -------- +name, sellIn, quality ++5 Dexterity Vest, 7, 17 +Aged Brie, -1, 4 +Elixir of the Mongoose, 2, 4 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 12, 23 +Backstage passes to a TAFKAL80ETC concert, 7, 50 +Backstage passes to a TAFKAL80ETC concert, 2, 50 +Conjured Mana Cake, 0, 3 + +-------- day 4 -------- +name, sellIn, quality ++5 Dexterity Vest, 6, 16 +Aged Brie, -2, 6 +Elixir of the Mongoose, 1, 3 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 11, 24 +Backstage passes to a TAFKAL80ETC concert, 6, 50 +Backstage passes to a TAFKAL80ETC concert, 1, 50 +Conjured Mana Cake, -1, 1 + +-------- day 5 -------- +name, sellIn, quality ++5 Dexterity Vest, 5, 15 +Aged Brie, -3, 8 +Elixir of the Mongoose, 0, 2 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 10, 25 +Backstage passes to a TAFKAL80ETC concert, 5, 50 +Backstage passes to a TAFKAL80ETC concert, 0, 50 +Conjured Mana Cake, -2, 0 + +-------- day 6 -------- +name, sellIn, quality ++5 Dexterity Vest, 4, 14 +Aged Brie, -4, 10 +Elixir of the Mongoose, -1, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 9, 27 +Backstage passes to a TAFKAL80ETC concert, 4, 50 +Backstage passes to a TAFKAL80ETC concert, -1, 0 +Conjured Mana Cake, -3, 0 + +-------- day 7 -------- +name, sellIn, quality ++5 Dexterity Vest, 3, 13 +Aged Brie, -5, 12 +Elixir of the Mongoose, -2, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 8, 29 +Backstage passes to a TAFKAL80ETC concert, 3, 50 +Backstage passes to a TAFKAL80ETC concert, -2, 0 +Conjured Mana Cake, -4, 0 + +-------- day 8 -------- +name, sellIn, quality ++5 Dexterity Vest, 2, 12 +Aged Brie, -6, 14 +Elixir of the Mongoose, -3, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 7, 31 +Backstage passes to a TAFKAL80ETC concert, 2, 50 +Backstage passes to a TAFKAL80ETC concert, -3, 0 +Conjured Mana Cake, -5, 0 + +-------- day 9 -------- +name, sellIn, quality ++5 Dexterity Vest, 1, 11 +Aged Brie, -7, 16 +Elixir of the Mongoose, -4, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 6, 33 +Backstage passes to a TAFKAL80ETC concert, 1, 50 +Backstage passes to a TAFKAL80ETC concert, -4, 0 +Conjured Mana Cake, -6, 0 + +-------- day 10 -------- +name, sellIn, quality ++5 Dexterity Vest, 0, 10 +Aged Brie, -8, 18 +Elixir of the Mongoose, -5, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 5, 35 +Backstage passes to a TAFKAL80ETC concert, 0, 50 +Backstage passes to a TAFKAL80ETC concert, -5, 0 +Conjured Mana Cake, -7, 0 + +-------- day 11 -------- +name, sellIn, quality ++5 Dexterity Vest, -1, 8 +Aged Brie, -9, 20 +Elixir of the Mongoose, -6, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 4, 38 +Backstage passes to a TAFKAL80ETC concert, -1, 0 +Backstage passes to a TAFKAL80ETC concert, -6, 0 +Conjured Mana Cake, -8, 0 + +-------- day 12 -------- +name, sellIn, quality ++5 Dexterity Vest, -2, 6 +Aged Brie, -10, 22 +Elixir of the Mongoose, -7, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 3, 41 +Backstage passes to a TAFKAL80ETC concert, -2, 0 +Backstage passes to a TAFKAL80ETC concert, -7, 0 +Conjured Mana Cake, -9, 0 + +-------- day 13 -------- +name, sellIn, quality ++5 Dexterity Vest, -3, 4 +Aged Brie, -11, 24 +Elixir of the Mongoose, -8, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 2, 44 +Backstage passes to a TAFKAL80ETC concert, -3, 0 +Backstage passes to a TAFKAL80ETC concert, -8, 0 +Conjured Mana Cake, -10, 0 + +-------- day 14 -------- +name, sellIn, quality ++5 Dexterity Vest, -4, 2 +Aged Brie, -12, 26 +Elixir of the Mongoose, -9, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 1, 47 +Backstage passes to a TAFKAL80ETC concert, -4, 0 +Backstage passes to a TAFKAL80ETC concert, -9, 0 +Conjured Mana Cake, -11, 0 + +-------- day 15 -------- +name, sellIn, quality ++5 Dexterity Vest, -5, 0 +Aged Brie, -13, 28 +Elixir of the Mongoose, -10, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 0, 50 +Backstage passes to a TAFKAL80ETC concert, -5, 0 +Backstage passes to a TAFKAL80ETC concert, -10, 0 +Conjured Mana Cake, -12, 0 + +-------- day 16 -------- +name, sellIn, quality ++5 Dexterity Vest, -6, 0 +Aged Brie, -14, 30 +Elixir of the Mongoose, -11, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -1, 0 +Backstage passes to a TAFKAL80ETC concert, -6, 0 +Backstage passes to a TAFKAL80ETC concert, -11, 0 +Conjured Mana Cake, -13, 0 + +-------- day 17 -------- +name, sellIn, quality ++5 Dexterity Vest, -7, 0 +Aged Brie, -15, 32 +Elixir of the Mongoose, -12, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -2, 0 +Backstage passes to a TAFKAL80ETC concert, -7, 0 +Backstage passes to a TAFKAL80ETC concert, -12, 0 +Conjured Mana Cake, -14, 0 + +-------- day 18 -------- +name, sellIn, quality ++5 Dexterity Vest, -8, 0 +Aged Brie, -16, 34 +Elixir of the Mongoose, -13, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -3, 0 +Backstage passes to a TAFKAL80ETC concert, -8, 0 +Backstage passes to a TAFKAL80ETC concert, -13, 0 +Conjured Mana Cake, -15, 0 + +-------- day 19 -------- +name, sellIn, quality ++5 Dexterity Vest, -9, 0 +Aged Brie, -17, 36 +Elixir of the Mongoose, -14, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -4, 0 +Backstage passes to a TAFKAL80ETC concert, -9, 0 +Backstage passes to a TAFKAL80ETC concert, -14, 0 +Conjured Mana Cake, -16, 0 + +-------- day 20 -------- +name, sellIn, quality ++5 Dexterity Vest, -10, 0 +Aged Brie, -18, 38 +Elixir of the Mongoose, -15, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -5, 0 +Backstage passes to a TAFKAL80ETC concert, -10, 0 +Backstage passes to a TAFKAL80ETC concert, -15, 0 +Conjured Mana Cake, -17, 0 + +-------- day 21 -------- +name, sellIn, quality ++5 Dexterity Vest, -11, 0 +Aged Brie, -19, 40 +Elixir of the Mongoose, -16, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -6, 0 +Backstage passes to a TAFKAL80ETC concert, -11, 0 +Backstage passes to a TAFKAL80ETC concert, -16, 0 +Conjured Mana Cake, -18, 0 + +-------- day 22 -------- +name, sellIn, quality ++5 Dexterity Vest, -12, 0 +Aged Brie, -20, 42 +Elixir of the Mongoose, -17, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -7, 0 +Backstage passes to a TAFKAL80ETC concert, -12, 0 +Backstage passes to a TAFKAL80ETC concert, -17, 0 +Conjured Mana Cake, -19, 0 + +-------- day 23 -------- +name, sellIn, quality ++5 Dexterity Vest, -13, 0 +Aged Brie, -21, 44 +Elixir of the Mongoose, -18, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -8, 0 +Backstage passes to a TAFKAL80ETC concert, -13, 0 +Backstage passes to a TAFKAL80ETC concert, -18, 0 +Conjured Mana Cake, -20, 0 + +-------- day 24 -------- +name, sellIn, quality ++5 Dexterity Vest, -14, 0 +Aged Brie, -22, 46 +Elixir of the Mongoose, -19, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -9, 0 +Backstage passes to a TAFKAL80ETC concert, -14, 0 +Backstage passes to a TAFKAL80ETC concert, -19, 0 +Conjured Mana Cake, -21, 0 + +-------- day 25 -------- +name, sellIn, quality ++5 Dexterity Vest, -15, 0 +Aged Brie, -23, 48 +Elixir of the Mongoose, -20, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -10, 0 +Backstage passes to a TAFKAL80ETC concert, -15, 0 +Backstage passes to a TAFKAL80ETC concert, -20, 0 +Conjured Mana Cake, -22, 0 + +-------- day 26 -------- +name, sellIn, quality ++5 Dexterity Vest, -16, 0 +Aged Brie, -24, 50 +Elixir of the Mongoose, -21, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -11, 0 +Backstage passes to a TAFKAL80ETC concert, -16, 0 +Backstage passes to a TAFKAL80ETC concert, -21, 0 +Conjured Mana Cake, -23, 0 + +-------- day 27 -------- +name, sellIn, quality ++5 Dexterity Vest, -17, 0 +Aged Brie, -25, 50 +Elixir of the Mongoose, -22, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -12, 0 +Backstage passes to a TAFKAL80ETC concert, -17, 0 +Backstage passes to a TAFKAL80ETC concert, -22, 0 +Conjured Mana Cake, -24, 0 + +-------- day 28 -------- +name, sellIn, quality ++5 Dexterity Vest, -18, 0 +Aged Brie, -26, 50 +Elixir of the Mongoose, -23, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -13, 0 +Backstage passes to a TAFKAL80ETC concert, -18, 0 +Backstage passes to a TAFKAL80ETC concert, -23, 0 +Conjured Mana Cake, -25, 0 + +-------- day 29 -------- +name, sellIn, quality ++5 Dexterity Vest, -19, 0 +Aged Brie, -27, 50 +Elixir of the Mongoose, -24, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -14, 0 +Backstage passes to a TAFKAL80ETC concert, -19, 0 +Backstage passes to a TAFKAL80ETC concert, -24, 0 +Conjured Mana Cake, -26, 0 + +-------- day 30 -------- +name, sellIn, quality ++5 Dexterity Vest, -20, 0 +Aged Brie, -28, 50 +Elixir of the Mongoose, -25, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, -15, 0 +Backstage passes to a TAFKAL80ETC concert, -20, 0 +Backstage passes to a TAFKAL80ETC concert, -25, 0 +Conjured Mana Cake, -27, 0 + diff --git a/csharp/ApprovalTest.cs b/csharp/ApprovalTest.cs index 5334147e..9b0ad586 100644 --- a/csharp/ApprovalTest.cs +++ b/csharp/ApprovalTest.cs @@ -1,28 +1,28 @@ -using System; -using System.IO; -using System.Text; -using ApprovalTests; -using ApprovalTests.Reporters; -using NUnit.Framework; +//using System; +//using System.IO; +//using System.Text; +//using ApprovalTests; +//using ApprovalTests.Reporters; +//using NUnit.Framework; -namespace csharp -{ - [UseReporter(typeof(DiffReporter))] - [TestFixture] - public class ApprovalTest - { - [Test] - public void ThirtyDays() - { +//namespace csharp +//{ +// [UseReporter(typeof(DiffReporter))] +// [TestFixture] +// public class ApprovalTest +// { +// [Test] +// public void ThirtyDays() +// { - StringBuilder fakeoutput = new StringBuilder(); - Console.SetOut(new StringWriter(fakeoutput)); - Console.SetIn(new StringReader("a\n")); +// StringBuilder fakeoutput = new StringBuilder(); +// Console.SetOut(new StringWriter(fakeoutput)); +// Console.SetIn(new StringReader("a\n")); - Program.Main(new string[] { }); - var output = fakeoutput.ToString(); +// Program.Main(new string[] { }); +// var output = fakeoutput.ToString(); - Approvals.Verify(output); - } - } -} +// Approvals.Verify(output); +// } +// } +//} diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index c60d97a0..ee63454b 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -12,74 +12,74 @@ namespace csharp public void UpdateQuality() { - for (var i = 0; i < Items.Count; i++) + foreach(var Item in Items) // Changed this to a simpler loop { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (Item.Name != "Aged Brie" && Item.Name != "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].Quality > 0) + if (Item.Quality > 0) { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + if (Item.Name != "Sulfuras, Hand of Ragnaros") { - Items[i].Quality = Items[i].Quality - 1; + Item.Quality = Item.Quality - 1; } } } else { - if (Items[i].Quality < 50) + if (Item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + Item.Quality = Item.Quality + 1; - if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") + if (Item.Name == "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].SellIn < 11) + if (Item.SellIn < 11) { - if (Items[i].Quality < 50) + if (Item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + Item.Quality = Item.Quality + 1; } } - if (Items[i].SellIn < 6) + if (Item.SellIn < 6) { - if (Items[i].Quality < 50) + if (Item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + Item.Quality = Item.Quality + 1; } } } } } - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + if (Item.Name != "Sulfuras, Hand of Ragnaros") { - Items[i].SellIn = Items[i].SellIn - 1; + Item.SellIn = Item.SellIn - 1; } - if (Items[i].SellIn < 0) + if (Item.SellIn < 0) { - if (Items[i].Name != "Aged Brie") + if (Item.Name != "Aged Brie") { - if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (Item.Name != "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].Quality > 0) + if (Item.Quality > 0) { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + if (Item.Name != "Sulfuras, Hand of Ragnaros") { - Items[i].Quality = Items[i].Quality - 1; + Item.Quality = Item.Quality - 1; } } } else { - Items[i].Quality = Items[i].Quality - Items[i].Quality; + Item.Quality = Item.Quality - Item.Quality; } } else { - if (Items[i].Quality < 50) + if (Item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + Item.Quality = Item.Quality + 1; } } } diff --git a/csharp/GildedRoseTest.cs b/csharp/GildedRoseTest.cs index 911df1be..c8c2e8dd 100644 --- a/csharp/GildedRoseTest.cs +++ b/csharp/GildedRoseTest.cs @@ -1,18 +1,18 @@ -using NUnit.Framework; -using System.Collections.Generic; +//using NUnit.Framework; +//using System.Collections.Generic; -namespace csharp -{ - [TestFixture] - public class GildedRoseTest - { - [Test] - public void foo() - { - IList Items = new List { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; - GildedRose app = new GildedRose(Items); - app.UpdateQuality(); - Assert.AreEqual("fixme", Items[0].Name); - } - } -} +//namespace csharp +//{ +// [TestFixture] +// public class GildedRoseTest +// { +// [Test] +// public void foo() +// { +// IList Items = new List { new Item { Name = "Aged Brie", SellIn = 0, Quality = 0 } }; +// GildedRose app = new GildedRose(Items); +// app.UpdateQuality(); +// Assert.AreEqual("Aged Brie", Items[0].Name); +// } +// } +//} diff --git a/csharp/Program.cs b/csharp/Program.cs index 36313e27..d92970a4 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -7,7 +7,7 @@ namespace csharp { public static void Main(string[] args) { - Console.WriteLine("OMGHAI!"); + //Console.WriteLine("OMGHAI!"); IList Items = new List{ new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20}, @@ -50,7 +50,9 @@ namespace csharp } Console.WriteLine(""); app.UpdateQuality(); + } + Console.Read(); // included this so I can at least see the printed results. :/ } } } diff --git a/csharp/README.md b/csharp/README.md index 6c1cdd1f..42a0fc62 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -4,11 +4,20 @@ Introduction: I will try as much as I can to write my thought processes here as it's one of the requirements. I will just write the relevant parts and not my whole thoughts. That would be weird since I was thinking of lunch just before I started. :D +SIDE COMMENTS: +- I couldn't exactly do a full TDD since the application is already written. TDD requires tests before development but this is a refactoring. +- One of the things I would ideally change if it was not explicitly said to not to is the fact that it uses strings to check. that can be really erroneous. + If I had my way, I would include IDs of some sort. + 1: One of the first things I want to do is just get the program to run. so am not fixing anything except what will make the program run. +- The program seems to run fine. except I could not see the results so added a little line to see what was printed. over than that. it looks good. + Makes sense why they kept using it. It works! :/ 2: After this I want to include some Unit tests to ensure all parts are working as they should. This may require some fixing. Not sure. +- First thing I did was separate the tests from the main application. I do not want to have the possibility of a memory leak or bulky apps +- Original unit tests were written in NUnit and I chose to use MSTest. Why? no reason! Just a choice. 3: Then when all tests are good. I can start working with an aim of not breaking any tests. \ No newline at end of file diff --git a/csharp/csharp.sln b/csharp/csharp.sln index 62ff78a8..87e98f32 100644 --- a/csharp/csharp.sln +++ b/csharp/csharp.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30804.86 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp", "csharp.csproj", "{176C0214-9136-4079-8DAB-11D7420C3881}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharpTests", "..\csharpTests\csharpTests.csproj", "{37C031AE-7CAF-45BF-B2C4-F5A037574D58}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,8 +17,15 @@ Global {176C0214-9136-4079-8DAB-11D7420C3881}.Debug|Any CPU.Build.0 = Debug|Any CPU {176C0214-9136-4079-8DAB-11D7420C3881}.Release|Any CPU.ActiveCfg = Release|Any CPU {176C0214-9136-4079-8DAB-11D7420C3881}.Release|Any CPU.Build.0 = Release|Any CPU + {37C031AE-7CAF-45BF-B2C4-F5A037574D58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37C031AE-7CAF-45BF-B2C4-F5A037574D58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37C031AE-7CAF-45BF-B2C4-F5A037574D58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37C031AE-7CAF-45BF-B2C4-F5A037574D58}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {01CFA026-4000-45ED-953B-BB77AE8707AE} + EndGlobalSection EndGlobal diff --git a/csharpTests/GildedRoseUnitTests.cs b/csharpTests/GildedRoseUnitTests.cs new file mode 100644 index 00000000..4b628c3d --- /dev/null +++ b/csharpTests/GildedRoseUnitTests.cs @@ -0,0 +1,69 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using csharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace csharp.Tests +{ + [TestClass()] + public class GildedRoseTests + { + + [TestMethod()] + public void DefaultTest() // Test that came with app + { + IList Items = new List { new Item { Name = "Aged Brie", SellIn = 0, Quality = 0 } }; + GildedRose app = new GildedRose(Items); + + app.UpdateQuality(); + + Assert.AreEqual("Aged Brie", Items[0].Name); + } + + [TestMethod()] + public void UpdateQualityTestForAgedBrie_SellDatePassed_IncreaseQualityByTwo() + { + IList Items = new List { new Item { Name = "Aged Brie", SellIn = 0, Quality = 0 } }; + GildedRose app = new GildedRose(Items); + + app.UpdateQuality(); + + Assert.AreEqual(2, Items[0].Quality); + } + + [TestMethod()] + public void UpdateQualityTest_SellDatePassed_DecreaseQualityTwice() + { + IList Items = new List { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 0, Quality = 2 } }; + GildedRose app = new GildedRose(Items); + + app.UpdateQuality(); + + Assert.AreEqual(0, Items[0].Quality); + } + + [TestMethod()] + public void UpdateQualityTest_QualityOfItemIsNeverNegative_MinimumValue() + { + IList Items = new List { new Item { Name = "+5 Dexterity Vest", SellIn = 0, Quality = 0 } }; + GildedRose app = new GildedRose(Items); + + app.UpdateQuality(); + + Assert.AreEqual(0, Items[0].Quality); + } + + public void UpdateQualityTest_QualityOfItemNeverAboveDefinedValue_MaximumValue() + { + IList Items = new List { new Item { Name = "+5 Dexterity Vest", SellIn = 0, Quality = 0 } }; + GildedRose app = new GildedRose(Items); + + app.UpdateQuality(); + + Assert.AreEqual(0, Items[0].Quality); + } + } +} \ No newline at end of file diff --git a/csharpTests/Properties/AssemblyInfo.cs b/csharpTests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..87a7ea5e --- /dev/null +++ b/csharpTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharpTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharpTests")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("37c031ae-7caf-45bf-b2c4-f5a037574d58")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/csharpTests/csharpTests.csproj b/csharpTests/csharpTests.csproj new file mode 100644 index 00000000..20a1c622 --- /dev/null +++ b/csharpTests/csharpTests.csproj @@ -0,0 +1,106 @@ + + + + + Debug + AnyCPU + {37C031AE-7CAF-45BF-B2C4-F5A037574D58} + Library + Properties + csharpTests + csharpTests + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\csharp\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\csharp\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + + + + + + {176C0214-9136-4079-8DAB-11D7420C3881} + csharp + + + + + + + False + + + False + + + False + + + False + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/csharpTests/packages.config b/csharpTests/packages.config new file mode 100644 index 00000000..3cf4963c --- /dev/null +++ b/csharpTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file