diff --git a/csharp.NUnit/GildedRose.sln b/csharp.NUnit/GildedRose.sln index f2ce64a1..fc591ee5 100644 --- a/csharp.NUnit/GildedRose.sln +++ b/csharp.NUnit/GildedRose.sln @@ -1,11 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31424.327 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34916.146 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GildedRose", "GildedRose\GildedRose.csproj", "{D781C52B-92C0-48BF-8414-177495DF4174}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GildedRoseTests", "GildedRoseTests\GildedRoseTests.csproj", "{CB6715CE-A283-4C70-9C1B-F58822077731}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GildedRoseTests", "GildedRoseTests\GildedRoseTests.csproj", "{CB6715CE-A283-4C70-9C1B-F58822077731}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{848F53B4-A532-4386-9DC3-1A477E7D6FCF}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/csharp.NUnit/GildedRose/GildedRose.cs b/csharp.NUnit/GildedRose/GildedRose.cs index 7ec604b6..c08bf5f8 100644 --- a/csharp.NUnit/GildedRose/GildedRose.cs +++ b/csharp.NUnit/GildedRose/GildedRose.cs @@ -4,83 +4,83 @@ namespace GildedRoseKata; public class GildedRose { - private readonly IList _items; + IList Items; - public GildedRose(IList items) + public GildedRose(IList Items) { - _items = items; + this.Items = Items; } 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 { - 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 == "Backstage passes to a TAFKAL80ETC concert") + 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") + if (Items[i].Name != "Sulfuras, Hand of Ragnaros") { - _items[i].SellIn = _items[i].SellIn - 1; + 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; + Items[i].Quality = Items[i].Quality - Items[i].Quality; } } else { - if (_items[i].Quality < 50) + if (Items[i].Quality < 50) { - _items[i].Quality = _items[i].Quality + 1; + Items[i].Quality = Items[i].Quality + 1; } } } diff --git a/csharp.NUnit/GildedRose/GildedRose.csproj b/csharp.NUnit/GildedRose/GildedRose.csproj index ae2821ed..0e318c1b 100644 --- a/csharp.NUnit/GildedRose/GildedRose.csproj +++ b/csharp.NUnit/GildedRose/GildedRose.csproj @@ -1,7 +1,9 @@  + Exe + GildedRoseKata net8.0 - + \ No newline at end of file diff --git a/csharp.NUnit/GildedRoseTests/TextTestFixture.cs b/csharp.NUnit/GildedRose/Program.cs similarity index 93% rename from csharp.NUnit/GildedRoseTests/TextTestFixture.cs rename to csharp.NUnit/GildedRose/Program.cs index 89c48e79..1c71999e 100644 --- a/csharp.NUnit/GildedRoseTests/TextTestFixture.cs +++ b/csharp.NUnit/GildedRose/Program.cs @@ -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{ + IList items = new List + { 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}, diff --git a/csharp.NUnit/GildedRoseTests/ApprovalTest.cs b/csharp.NUnit/GildedRoseTests/ApprovalTest.cs index 1e63c4d1..32828859 100644 --- a/csharp.NUnit/GildedRoseTests/ApprovalTest.cs +++ b/csharp.NUnit/GildedRoseTests/ApprovalTest.cs @@ -1,10 +1,14 @@ +using GildedRoseKata; + using System; using System.IO; using System.Text; using System.Threading.Tasks; -using NUnit.Framework; + using VerifyNUnit; +using NUnit.Framework; + namespace GildedRoseTests; public class ApprovalTest @@ -16,7 +20,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); diff --git a/csharp.NUnit/GildedRoseTests/GildedRoseTests.csproj b/csharp.NUnit/GildedRoseTests/GildedRoseTests.csproj index 90c93df9..c84df6ce 100644 --- a/csharp.NUnit/GildedRoseTests/GildedRoseTests.csproj +++ b/csharp.NUnit/GildedRoseTests/GildedRoseTests.csproj @@ -1,24 +1,23 @@  - - Exe - net8.0 - GildedRoseTests.TextTestFixture - + + Exe + net8.0 + - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + - - - + + + \ No newline at end of file diff --git a/csharp.NUnit/README.md b/csharp.NUnit/README.md index b80b0c0a..8e1eaea9 100644 --- a/csharp.NUnit/README.md +++ b/csharp.NUnit/README.md @@ -1,23 +1,24 @@ -# Gilded Rose starting position in Csharp Core +# Gilded Rose starting position in C# NUnit ## Build the project -Use your normal build tools. +Use your normal build tools to build the projects in Debug mode. +For example, you can use the `dotnet` command line tool: -## Run the TextTest fixture from the Command-Line +``` cmd +dotnet build GildedRose.sln -c Debug +``` + +## Run the Gilded Rose Command-Line program For e.g. 10 days: -``` -GildedRoseTests/bin/Debug/net8.0/GildedRoseTests 10 +``` cmd +GildedRose/bin/Debug/net8.0/GildedRose 10 ``` -You should make sure the command shown above works when you execute it in a terminal before trying to use TextTest (see below). If your tooling has placed the executable somewhere else, you will need to adjust the path above. - - -## Run the TextTest approval test that comes with this project - -There are instructions in the [TextTest Readme](../texttests/README.md) for setting up TextTest. You will need to specify the GildedRoseTests executable and interpreter in [config.gr](../texttests/config.gr). Uncomment this line: - - executable:${TEXTTEST_HOME}/csharpcore/GildedRoseTests/bin/Debug/net8.0/GildedRoseTests +## Run all the unit tests +``` cmd +dotnet test +``` \ No newline at end of file diff --git a/csharp.NUnit/global.json b/csharp.NUnit/global.json deleted file mode 100644 index 7cd6a1f4..00000000 --- a/csharp.NUnit/global.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sdk": { - "version": "7.0.0", - "rollForward": "latestMajor", - "allowPrerelease": true - } -} \ No newline at end of file diff --git a/csharp.xUnit/GildedRose.sln b/csharp.xUnit/GildedRose.sln index f2ce64a1..59e41407 100644 --- a/csharp.xUnit/GildedRose.sln +++ b/csharp.xUnit/GildedRose.sln @@ -1,11 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31424.327 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34916.146 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GildedRose", "GildedRose\GildedRose.csproj", "{D781C52B-92C0-48BF-8414-177495DF4174}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GildedRoseTests", "GildedRoseTests\GildedRoseTests.csproj", "{CB6715CE-A283-4C70-9C1B-F58822077731}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GildedRoseTests", "GildedRoseTests\GildedRoseTests.csproj", "{CB6715CE-A283-4C70-9C1B-F58822077731}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C4DC2F6D-79E1-4AFB-8B3E-9305F18439CE}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/csharp.xUnit/GildedRose/GildedRose.cs b/csharp.xUnit/GildedRose/GildedRose.cs index ed7dc428..c08bf5f8 100644 --- a/csharp.xUnit/GildedRose/GildedRose.cs +++ b/csharp.xUnit/GildedRose/GildedRose.cs @@ -1,27 +1,79 @@ using System.Collections.Generic; -namespace GildedRoseKata -{ - public class GildedRose - { - IList Items; - public GildedRose(IList Items) - { - this.Items = Items; - } +namespace GildedRoseKata; - public void UpdateQuality() +public class GildedRose +{ + IList Items; + + public GildedRose(IList Items) + { + this.Items = Items; + } + + 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; + } + } + } + else + { + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + + if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") + { + if (Items[i].SellIn < 11) { - Items[i].Quality = Items[i].Quality - 1; + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + } } + + if (Items[i].SellIn < 6) + { + if (Items[i].Quality < 50) + { + 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].SellIn < 0) + { + if (Items[i].Name != "Aged Brie") + { + if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + { + if (Items[i].Quality > 0) + { + if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + { + Items[i].Quality = Items[i].Quality - 1; + } + } + } + else + { + Items[i].Quality = Items[i].Quality - Items[i].Quality; } } else @@ -29,61 +81,9 @@ namespace GildedRoseKata if (Items[i].Quality < 50) { 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].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } - - if (Items[i].SellIn < 6) - { - if (Items[i].Quality < 50) - { - 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].SellIn < 0) - { - if (Items[i].Name != "Aged Brie") - { - if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") - { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - 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; - } } } } } } -} +} \ No newline at end of file diff --git a/csharp.xUnit/GildedRose/GildedRose.csproj b/csharp.xUnit/GildedRose/GildedRose.csproj index e830fad1..0e318c1b 100644 --- a/csharp.xUnit/GildedRose/GildedRose.csproj +++ b/csharp.xUnit/GildedRose/GildedRose.csproj @@ -2,8 +2,8 @@ Exe + GildedRoseKata net8.0 - GildedRoseKata.Program - + \ No newline at end of file diff --git a/csharp.xUnit/GildedRose/Item.cs b/csharp.xUnit/GildedRose/Item.cs index 3d87cab4..5ad18dea 100644 --- a/csharp.xUnit/GildedRose/Item.cs +++ b/csharp.xUnit/GildedRose/Item.cs @@ -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; } +} \ No newline at end of file diff --git a/csharp.xUnit/GildedRose/Program.cs b/csharp.xUnit/GildedRose/Program.cs index 1367fe73..1c71999e 100644 --- a/csharp.xUnit/GildedRose/Program.cs +++ b/csharp.xUnit/GildedRose/Program.cs @@ -1,56 +1,61 @@ 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 items = new List { - Console.WriteLine("OMGHAI!"); - - IList Items = new List{ - 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); + + int days = 2; + if (args.Length > 0) + { + days = int.Parse(args[0]) + 1; + } + + for (var i = 0; i < days; 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(); } } -} +} \ No newline at end of file diff --git a/csharp.xUnit/GildedRoseTests/ApprovalTest.cs b/csharp.xUnit/GildedRoseTests/ApprovalTest.cs index ba8e701f..3020c86f 100644 --- a/csharp.xUnit/GildedRoseTests/ApprovalTest.cs +++ b/csharp.xUnit/GildedRoseTests/ApprovalTest.cs @@ -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{Environment.NewLine}")); - 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); } -} +} \ No newline at end of file diff --git a/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs b/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs index 16b7dd95..63fd7b1b 100644 --- a/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs +++ b/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs @@ -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 Items = new List { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; - GildedRose app = new GildedRose(Items); - app.UpdateQuality(); - Assert.Equal("fixme", Items[0].Name); - } + IList Items = new List { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; + GildedRose app = new GildedRose(Items); + app.UpdateQuality(); + Assert.Equal("fixme", Items[0].Name); } -} +} \ No newline at end of file diff --git a/csharp.xUnit/README.md b/csharp.xUnit/README.md new file mode 100644 index 00000000..92b3cb9e --- /dev/null +++ b/csharp.xUnit/README.md @@ -0,0 +1,24 @@ +# Gilded Rose starting position in C# xUnit + +## Build the project + +Use your normal build tools to build the projects in Debug mode. +For example, you can use the `dotnet` command line tool: + +``` cmd +dotnet build GildedRose.sln -c Debug +``` + +## Run the Gilded Rose Command-Line program + +For e.g. 10 days: + +``` cmd +GildedRose/bin/Debug/net8.0/GildedRose 10 +``` + +## Run all the unit tests + +``` cmd +dotnet test +``` \ No newline at end of file diff --git a/csharp.xUnit/global.json b/csharp.xUnit/global.json deleted file mode 100644 index 7cd6a1f4..00000000 --- a/csharp.xUnit/global.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sdk": { - "version": "7.0.0", - "rollForward": "latestMajor", - "allowPrerelease": true - } -} \ No newline at end of file