コード例 #1
0
        public void Should_Never_Have_Quality_More_Than_50(string nameItem1, string nameItem2, string nameItem3)
        {
            IList <int> sellIns = new List <int> {
                0, -2, 3, 4, 5, -7, -6
            };
            IList <int> qualities = new List <int> {
                0, 0, 0, 5, 4, 1, 8
            };
            IList <Item> items       = new List <Item>();
            string       currentName = nameItem1;

            for (var i = 0; i < qualities.Count; i++)
            {
                if (currentName == nameItem1)
                {
                    if (i != 0)
                    {
                        currentName = nameItem2;
                    }
                }
                else if (currentName == nameItem2)
                {
                    currentName = nameItem3;
                }
                else
                {
                    currentName = nameItem1;
                }
                items.Add(new Item {
                    Name = currentName, SellIn = sellIns[i], Quality = qualities[i]
                });
            }

            GildedRose app = new GildedRose(items);

            app.UpdateQuality();

            foreach (var item in items)
            {
                Assert.True(item.Quality <= 50);
            }
        }
コード例 #2
0
        public void Should_Have_Sellin_Value_On_Each_Item(string nameItem1, string nameItem2, string nameItem3)
        {
            IList <int> sellIns = new List <int> {
                0, -2, 3, 4, 5, -7, -6
            };
            IList <int> qualities = new List <int> {
                0, 0, 0, 5, 4, 21, 38
            };
            IList <Item> items       = new List <Item>();
            string       currentName = nameItem1;

            for (var i = 0; i < qualities.Count; i++)
            {
                if (currentName == nameItem1)
                {
                    if (i != 0)
                    {
                        currentName = nameItem2;
                    }
                }
                else if (currentName == nameItem2)
                {
                    currentName = nameItem3;
                }
                else
                {
                    currentName = nameItem1;
                }
                items.Add(new Item {
                    Name = currentName, SellIn = sellIns[i], Quality = qualities[i]
                });
            }
            GildedRose app = new GildedRose(items);

            app.UpdateQuality();

            foreach (var item in items)
            {
                Assert.True(item.GetType().GetProperty("SellIn") != null);
            }
        }
コード例 #3
0
        public void Should_Degrade_Quality_Twice_After_SellIn_Zero(string nameItem1, string nameItem2, string nameItem3)
        {
            IList <int> beforeSellIns = new List <int> {
                4, 2, 5, 1, 0
            };
            IList <int> afterSellIns = new List <int> {
                -1, -9, -7, -6
            };
            IList <int> beforeSellinQualities = new List <int> {
                0, 2, 3, 5, 1
            };
            IList <int> afterSellinQualities = new List <int> {
                0, 2, 3, 5
            };
            IList <Item> items       = new List <Item>();
            string       currentName = nameItem1;

            for (var i = 0; i < beforeSellIns.Count; i++)
            {
                if (currentName == nameItem1)
                {
                    if (i != 0)
                    {
                        currentName = nameItem2;
                    }
                }
                else if (currentName == nameItem2)
                {
                    currentName = nameItem3;
                }
                else
                {
                    currentName = nameItem1;
                }
                items.Add(new Item {
                    Name = currentName, SellIn = beforeSellIns[i], Quality = beforeSellinQualities[i]
                });
            }
            for (var i = 0; i < afterSellIns.Count; i++)
            {
                if (currentName == nameItem1)
                {
                    if (i != 0)
                    {
                        currentName = nameItem2;
                    }
                }
                else if (currentName == nameItem2)
                {
                    currentName = nameItem3;
                }
                else
                {
                    currentName = nameItem1;
                }
                items.Add(new Item {
                    Name = currentName, SellIn = afterSellIns[i], Quality = afterSellinQualities[i]
                });
            }
            GildedRose app = new GildedRose(items);

            app.UpdateQuality();
            IList <int> updatedQualitiesBeforeSellIn = new List <int>();
            IList <int> updatedQualitiesAfterSellIn  = new List <int>();

            for (var i = 0; i < items.Count; i++)
            {
                if (i < 5)
                {
                    updatedQualitiesBeforeSellIn.Add(items[i].Quality);
                }
                else
                {
                    updatedQualitiesAfterSellIn.Add(items[i].Quality);
                }
            }

            for (var i = 0; i < beforeSellinQualities.Count; i++)
            {
                Assert.Equal(beforeSellinQualities[i] - updatedQualitiesBeforeSellIn[i], beforeSellinQualities[i] - updatedQualitiesBeforeSellIn[i]);
            }
            for (var i = 0; i < afterSellinQualities.Count; i++)
            {
                Assert.Equal((beforeSellinQualities[i] - updatedQualitiesBeforeSellIn[i]) * 2, afterSellinQualities[i] - updatedQualitiesAfterSellIn[i]);
            }
        }