public void BackstagePassTestDegradationBands()
 {
     var item =  new Item
         {
             Name = "Backstage passes to a TAFKAL80ETC concert",
             SellIn = 15,
             Quality = 21
         };
     UpdateQuality(item);
     Assert.Equal(item.Quality, 22);
     UpdateQuality(item); // 23
     UpdateQuality(item); // 24
     UpdateQuality(item); // 25
     UpdateQuality(item); // 26
     UpdateQuality(item); // 28
     UpdateQuality(item); // 30
     UpdateQuality(item); // 32
     Assert.Equal(item.Quality, 32);
     UpdateQuality(item); // 34
     UpdateQuality(item); // 36
     UpdateQuality(item); // 39
     UpdateQuality(item); // 42
     Assert.Equal(item.Quality, 42);
     UpdateQuality(item); // 45
     UpdateQuality(item); // 48
     UpdateQuality(item); // 50
     Assert.Equal(item.Quality, 50); // should be no more than 50!
     UpdateQuality(item); // 50
     UpdateQuality(item); // 0
     Assert.Equal(item.Quality, 0); // quality drops to zero now date has passed
 }
Beispiel #2
0
        private void ExpiredItemsUpdate(Item item)
        {
            item.SellIn--;

            if (item.SellIn < 0)
            {
                if (NormalItem.Contains(item.Name) && item.Quality > 0)
                {
                    item.Quality--;
                }

                if (item.Name == ConjuredCake)
                {
                    item.Quality -= 2;
                    if (item.Quality < 0)
                    {
                        item.Quality = 0;
                    }
                }

                if (item.Name == BackstagePass || item.Quality < 0)
                {
                    item.Quality = 0;
                }

                if (item.Name == AgedBrie && item.Quality < MaxQuality)
                {
                    item.Quality++;
                }
            }
        }
 private void UpdateQuality(Item item)
 {
     if (ItemChecker.IncreasesOverTime(item.Name))
         IncreaseQuality(item);
     else
         DecreaseQuality(item);
 }
 private void IncreaseQuality(Item item)
 {
     if (ItemChecker.IsBackStagePass(item.Name))
         UpdateBackStagePass(item);
     else
         item.Quality += UpdateCalculator.Increase(item);
 }
 public void QualityCannotExceedMaximumQuality()
 {
     Item goldenSunWatch = new Item{Name = "Golden Pocket Sun Watch", SellIn = 14, Quality = MAX_QUALITY};
     Store.Items.Add(goldenSunWatch);
     Store.UpdateQuality();
     Assert.That(goldenSunWatch.Quality, Is.LessThanOrEqualTo(MAX_QUALITY));
 }
 public void AgedBrieTestIncreasesInQuality()
 {
     var item = new Item { Name = "Aged Brie", SellIn = 2, Quality = 0 };
     UpdateQuality(item);
     Assert.Equal(item.Quality, 1);
     Assert.Equal(item.SellIn, 1);
 }
        public void UpgradeReturnsNewItem()
        {
            var item = new Item { SellIn = 10, Quality = 10 };
            var result = _itemUpgrade.Upgrade(item);

            Assert.That(item, Is.Not.SameAs(result));
        }
Beispiel #8
0
 public void UpdateQuality(Item item)
 {
     if (item.Quality > 0)
     {
         item.Quality -= 2;
     }
 }
 private void UpdateBackStagePass(Item item)
 {
     if (ItemChecker.BackStagePassExpired(item))
         item.Quality = 0;
     else
         item.Quality += UpdateCalculator.BackStagePassIncrease(item);
 }
Beispiel #10
0
        public void ConjuredItemsDegradeTwiceAsFast()
        {
            var item = new Item() { Name = CONJURED_MANA_CAKE, SellIn = 10, Quality = 10 };
            item = UpdateItemQuality(item);

            Assert.That(item.Quality, Is.EqualTo(8));
        }
Beispiel #11
0
 public virtual void UpdateInventory(Item item)
 {
     AdjustSellInDays(item);
     AdjustQuality(item);
     if (item.SellIn < 0)
         AdjustQuality(item);
 }
Beispiel #12
0
        public void AgedBrieIncreaseQualityAtTwiceTheRate()
        {
            var item = new Item() { Name = AGED_BRIE, SellIn = 0, Quality = 10 };
            item = UpdateItemQuality(item);

            Assert.That(item.Quality, Is.EqualTo(12));
        }
Beispiel #13
0
        public static Item UpdateQuality(Item item)
        {
            var program = new Program {Items = new List<Item> {item}};
            program.UpdateQuality();

            return item;
        }
Beispiel #14
0
        private void DecreaseQuality(Item item)
        {
            var decrease = UpdateCalculator.Decrease(item, ItemChecker.IsConjured(item.Name));

            if (item.Quality - decrease >= 0)
                item.Quality -= decrease;
        }
Beispiel #15
0
        public void BackstagePassesIncreaseInQuality()
        {
            var item = new Item() { Name = BACKSTAGE_PASSES, SellIn = 20, Quality = 10 };
            item = UpdateItemQuality(item);

            Assert.That(item.SellIn, Is.EqualTo(19));
            Assert.That(item.Quality, Is.EqualTo(11));
        }
Beispiel #16
0
        public void BackstagePassesIncreaseInAtTrippleRate()
        {
            var item = new Item() { Name = BACKSTAGE_PASSES, SellIn = 5, Quality = 10 };
            item = UpdateItemQuality(item);

            Assert.That(item.SellIn, Is.EqualTo(4));
            Assert.That(item.Quality, Is.EqualTo(13));
        }
Beispiel #17
0
        public void BackstagePassesExpire()
        {
            var item = new Item() { Name = BACKSTAGE_PASSES, SellIn = 0, Quality = 10 };
            item = UpdateItemQuality(item);

            Assert.That(item.SellIn, Is.EqualTo(-1));
            Assert.That(item.Quality, Is.EqualTo(0));
        }
 public void AgedBrieTestNoMoreThan50()
 {
     var item = new Item { Name = "Aged Brie", SellIn = 2, Quality = 48 };
     UpdateQuality(item);
     UpdateQuality(item);
     UpdateQuality(item);
     Assert.Equal(item.Quality, 50);
 }
        public void QualityCanNeverBeDecreasedBelowMinimumQuality()
        {
            Item deOideLederhosn = new Item { Name = "Lederhose", SellIn = 1000, Quality = MIN_QUALITY };
            Store.Items.Add(deOideLederhosn);
            Store.UpdateQuality();

            Assert.That(deOideLederhosn.Quality, Is.GreaterThanOrEqualTo(MIN_QUALITY));
        }
Beispiel #20
0
        public void when_updating_a_normal_item_past_its_sellby_date_should_degrade_two_quality()
        {
            var item = new Item { Name = "Item", Quality = 10, SellIn = 0 };

            var program = CreateProgram(item);
            program.UpdateQuality();

            Assert.That(item.Quality, Is.EqualTo(8));
        }
Beispiel #21
0
        public void when_updating_a_conjured_item_should_degrade_the_quality_twice_as_fast()
        {
            var item = new Item { Name = "Conjured Cloak", Quality = 30, SellIn = 5 };

            var program = CreateProgram(item);
            program.UpdateQuality();

            Assert.That(item.Quality, Is.EqualTo(28));
        }
Beispiel #22
0
        public void when_updating_aged_brie_with_50_quality_should_stay_at_50_quality()
        {
            var item = new Item { Name = "Aged Brie", Quality = 50, SellIn = 5 };

            var program = CreateProgram(item);
            program.UpdateQuality();

            Assert.That(item.Quality, Is.EqualTo(50));
        }
Beispiel #23
0
        public void when_updating_aged_brie_should_appreciate_one_quality()
        {
            var item = new Item { Name = "Aged Brie", Quality = 10, SellIn = 10 };

            var program = CreateProgram(item);
            program.UpdateQuality();

            Assert.That(item.Quality, Is.EqualTo(11));
        }
        public void CloneItem()
        {
            var item = new Item {SellIn = 10, Quality = 10};
            var result = _itemUpgrade.Clone(item);

            Assert.That(item, Is.Not.SameAs(result));
            Assert.That(item.Name, Is.EqualTo(result.Name));
            Assert.That(item.SellIn, Is.EqualTo(result.SellIn));
            Assert.That(item.Quality, Is.EqualTo(result.Quality));
        }
Beispiel #25
0
        private Item UpdateItemAsConjured(Item item)
        {
            item.Quality -= 2;

            if (item.Quality < 0)
                item.Quality = 0;

            item.SellIn -= 1;
            return item;
        }
Beispiel #26
0
        private int CalculateDecrease(Item item)
        {
           var amountToDecreaseBy = item.SellIn < 1 ? 2 : 1;

            if (IsConjured(item.Name))
            {
                amountToDecreaseBy *= 2;
            }

            return amountToDecreaseBy;
        }
Beispiel #27
0
        private void DecreaseQuality(Item item)
        {
            var amountToDecreaseBy = CalculateDecrease(item);

            item.Quality -= amountToDecreaseBy;

            if (item.Quality < 0)
            {
                item.Quality = 0;
            }
        }
        public void QuailityCanNeverBeMoreThanFifty()
        {
            var item = new Item { Name = "Aged Brie", SellIn = 2, Quality = 50 };
            var subject = new Program
            {
                Items = new List<Item> { item }
            };

            subject.UpdateQuality();
            Assert.That(item.Quality, Is.EqualTo(50));
        }
        public void QuailityDegradesByTwoWhenPastTheSellinPeriod()
        {
            var item = new Item { Name = "+5 Dexterity Vest", Quality = 20, SellIn = 0 };
            var subject = new Program
            {
                Items = new List<Item> { item }
            };

            subject.UpdateQuality();
            Assert.That(item.Quality, Is.EqualTo(18));
        }
        public void QuailityOfAnItemIsNeverNegative()
        {
            var item = new Item { Name = "+5 Dexterity Vest", Quality = 0, SellIn = 0 };
            var subject = new Program
            {
                Items = new List<Item> { item }
            };

            subject.UpdateQuality();
            Assert.That(item.Quality, Is.EqualTo(0));
        }