예제 #1
0
 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
 }
예제 #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++;
                }
            }
        }
예제 #3
0
 private void UpdateQuality(Item item)
 {
     if (ItemChecker.IncreasesOverTime(item.Name))
         IncreaseQuality(item);
     else
         DecreaseQuality(item);
 }
예제 #4
0
 private void IncreaseQuality(Item item)
 {
     if (ItemChecker.IsBackStagePass(item.Name))
         UpdateBackStagePass(item);
     else
         item.Quality += UpdateCalculator.Increase(item);
 }
예제 #5
0
 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));
 }
예제 #6
0
 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));
        }
예제 #8
0
 public void UpdateQuality(Item item)
 {
     if (item.Quality > 0)
     {
         item.Quality -= 2;
     }
 }
예제 #9
0
 private void UpdateBackStagePass(Item item)
 {
     if (ItemChecker.BackStagePassExpired(item))
         item.Quality = 0;
     else
         item.Quality += UpdateCalculator.BackStagePassIncrease(item);
 }
예제 #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));
        }
예제 #11
0
 public virtual void UpdateInventory(Item item)
 {
     AdjustSellInDays(item);
     AdjustQuality(item);
     if (item.SellIn < 0)
         AdjustQuality(item);
 }
예제 #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));
        }
예제 #13
0
        public static Item UpdateQuality(Item item)
        {
            var program = new Program {Items = new List<Item> {item}};
            program.UpdateQuality();

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

            if (item.Quality - decrease >= 0)
                item.Quality -= decrease;
        }
예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #18
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);
 }
예제 #19
0
        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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #24
0
        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));
        }
예제 #25
0
        private Item UpdateItemAsConjured(Item item)
        {
            item.Quality -= 2;

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

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

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

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

            item.Quality -= amountToDecreaseBy;

            if (item.Quality < 0)
            {
                item.Quality = 0;
            }
        }
예제 #28
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));
        }
예제 #29
0
        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));
        }
예제 #30
0
        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));
        }