8790d0b01aa0 — MiyamotoAkira 11 months ago
Renamed file and completed tests for the basic rules
1 files changed, 141 insertions(+), 30 deletions(-)

M tests/GildedRose.Tests/UnitTest1.cs => tests/GildedRose.Tests/BaseRules.cs
M tests/GildedRose.Tests/UnitTest1.cs => tests/GildedRose.Tests/BaseRules.cs +141 -30
@@ 1,43 1,154 @@ 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using Xunit;
 using GildedRose.Console;
 
-
 namespace GildedRose.Tests
 {
-    public class UnitTest1
+    #pragma warning disable CS8321, xUnit1013
+    public class BaseRules
     {
-        public List<Item> baseItems = 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 = "Backstage passes to a TAFKAL80ETC concert",
-                                                      SellIn = 15,
-                                                      Quality = 20
-                                                  },
-                                              new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
-                                          };
+        public const string Brie = "Aged Brie";
+        public const string Vest = "+5 Dexterity Vest";
+        public const string Sulfuras = "Sulfuras, Hand of Ragnaros";
+        public const string Backstage = "Backstage passes to a TAFKAL80ETC concert";
+        
+        public Item FindItemByName(IList<Item> items, string name)
+        {
+            return items.First(x => x.Name.Equals(name));
+        }
+
+        public void StandardItemRules()
+        {
+            [Fact]
+            void VestItemDegradesQualityBeforeSellIn()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Vest, SellIn = 2, Quality = 20}}};
+                var item = FindItemByName(app.Items, Vest);
+                Assert.Equal(20, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(19, item.Quality);
+            }
+
+            [Fact]
+            void AnItemSellInGetsReduced()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Vest, SellIn = 2, Quality = 3}}};
+                var item = FindItemByName(app.Items, Vest);
+                Assert.Equal(2, item.SellIn);
+                app.UpdateQuality();
+                Assert.Equal(1, item.SellIn);
+            }
+
+            [Fact]
+            void ItemDegradesQualityTwiceAfterSellIn()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Vest, SellIn = 0, Quality = 3}}};
+                var item = FindItemByName(app.Items, Vest);
+                Assert.Equal(3, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(1, item.Quality);
+            }
+
+            [Fact]
+            void AnyItemDontGoBelowZeroQuality()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = "Test", SellIn = 1, Quality = 0}}};
+                var item = FindItemByName(app.Items, "Test");
+                Assert.Equal(0, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(0, item.Quality);
+            }
+        }
+
+        public void SulfurasRules()
+        {
+            [Fact]
+            void SulfurasQualityIsConstant()
+            {
+                var app = new Program() {Items = new List<Item> {new Item {Name = Sulfuras, SellIn = 0, Quality = 80}}};
+                var item = FindItemByName(app.Items, Sulfuras);
+                Assert.Equal(80, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(80, item.Quality);
+            }
 
-        public Program CreateProgram() {
-            return new Program()
-                          {
-                              Items = baseItems
-
-                          };
+            [Fact]
+            void SulfurasSellInIsAlwaysZero()
+            {
+                var app = new Program() {Items = new List<Item> {new Item {Name = Sulfuras, SellIn = 0, Quality = 80}}};
+                var item = FindItemByName(app.Items, Sulfuras);
+                Assert.Equal(0, item.SellIn);
+                app.UpdateQuality();
+                Assert.Equal(0, item.SellIn);
+            }
         }
-        
-        [Fact]
-        public void Test1()
+
+        public void BackstageRules()
         {
-            var app = CreateProgram();
-            baseItems.ForEach(item => System.Console.WriteLine(item));
-            app.UpdateQuality();
-            baseItems.ForEach(item => System.Console.WriteLine(item));
+            [Fact]
+            void BackstageGoesToZeroQualityAfterSellIn()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Backstage, SellIn = 0, Quality = 3}}};
+                var item = FindItemByName(app.Items, Backstage);
+                Assert.Equal(3, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(0, item.Quality);
+            }
+
+            [Fact]
+            void BackstageGoesQualityByTwoWith10OrLessDays()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Backstage, SellIn = 10, Quality = 3}}};
+                var item = FindItemByName(app.Items, Backstage);
+                Assert.Equal(3, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(5, item.Quality);
+            }
+
+            [Fact]
+            void BackstageGoesQualityByThreeWith5OrLessDays()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Backstage, SellIn = 5, Quality = 3}}};
+                var item = FindItemByName(app.Items, Backstage);
+                Assert.Equal(3, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(6, item.Quality);
+            }
         }
-    }
+
+        public void BrieRules()
+        {
+            [Fact]
+            void AgedBriesIncreasesQuality()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Brie, SellIn = 2, Quality = 0}}};
+                var item = FindItemByName(app.Items, Brie);
+                Assert.Equal(0, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(1, item.Quality);
+            }
+
+            [Fact]
+            void AgedBrieQualityDoesntGoOver50()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Brie, SellIn = 2, Quality = 50}}};
+                var item = FindItemByName(app.Items, Brie);
+                Assert.Equal(50, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(50, item.Quality);
+            }
+
+            [Fact]
+            void AgedBrieQualityDoesntIncreaseAfter50()
+            {
+                var app = new Program() { Items = new List<Item> {new Item {Name = Brie, SellIn = 2, Quality = 51}}};
+                var item = FindItemByName(app.Items, Brie);
+                Assert.Equal(51, item.Quality);
+                app.UpdateQuality();
+                Assert.Equal(51, item.Quality);
+            }
+        }
+     }
 }