Exemplo n.º 1
0
        public void Success_CorrectlyFormedObjectCreated()
        {
            // Setup
            const string            objectName = "My new object";
            const int               sellIn     = 99;
            const int               quality    = 66;
            const QualityStrategy   expectedQualityStrategy = QualityStrategy.LinearDecrease;
            const ShelfLifeStrategy expectedSellByStrategy  = ShelfLifeStrategy.LinearDecrease;
            var factory = new ItemFactory(new Dictionary <string, StockManagementStrategy>()
            {
                { "Some Other object", new StockManagementStrategy(QualityStrategy.Stable, ShelfLifeStrategy.Stable) },
                { "Yet another object", new StockManagementStrategy(QualityStrategy.RapidDecrease, ShelfLifeStrategy.LinearDecrease) },
                { objectName, new StockManagementStrategy(expectedQualityStrategy, expectedSellByStrategy) },
            });

            // Execution
            var newItem = factory.Create(objectName, sellIn, quality);

            // Assert
            Assert.IsNotNull(newItem);
            Assert.AreEqual(objectName, newItem.Name);
            Assert.AreEqual(sellIn, newItem.SellIn);
            Assert.AreEqual(quality, newItem.Quality);
            Assert.AreEqual(expectedQualityStrategy, newItem.QualityStrategy);
            Assert.AreEqual(expectedSellByStrategy, newItem.ShelfLifeStrategy);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Represents an item of stock.
 /// </summary>
 /// <param name="name">The name of the item</param>
 /// <param name="sellIn">The number of days remaining before the item must be sold</param>
 /// <param name="quality">The quality metric associated with the item</param>
 /// <param name="qualityStrategy">The quality strategy to be used for this object</param>
 /// <param name="shelfLifeStrategy">The shelf life strategy to be used for this object</param>
 internal Item(string name, int sellIn, int quality, QualityStrategy qualityStrategy, ShelfLifeStrategy shelfLifeStrategy)
 {
     Name              = name;
     SellIn            = sellIn;
     Quality           = quality;
     QualityStrategy   = qualityStrategy;
     ShelfLifeStrategy = shelfLifeStrategy;
 }
 /// <summary>
 /// Creates a new algorithm based on the quality strategy provided
 /// </summary>
 /// <param name="strategyType">The strategy</param>
 /// <exception cref="ArgumentException">Indicates that the strategy type that was provided was invalid</exception>
 /// <exception cref="GildedRoseException">Indicates that the lookup list that was provided in the constructor
 /// was invalid</exception>
 /// <returns>The quality algorithm</returns>
 public IShelfLifeAlgorithm Create(ShelfLifeStrategy strategyType)
 {
     try
     {
         return(_genericFactory.Create(strategyType));
     }
     catch (ArgumentException ex)
     {
         // This exception means that the shelf life strategy did not exist in the lookup provided.
         // We don't rethrow here because the parameter name would make no sense to the caller.
         throw new ArgumentException(nameof(strategyType), ex);
     }
     catch (InvalidCastException)
     {
         // This means the type specified in the lookup list is not compatible with our return type
         // TODO: This should really be a custom exception type
         throw new GildedRoseException($"The lookup list item relating to '{strategyType}' was not compatible" +
                                       $"with the IShelfLifeAlgorithm return type.");
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initialises the stock management strategy
 /// </summary>
 /// <param name="qualityStrategy">The required quality strategy for this item type</param>
 /// <param name="shelfLifeStrategy">The required shelf life strategy for this item type</param>
 public StockManagementStrategy(QualityStrategy qualityStrategy, ShelfLifeStrategy shelfLifeStrategy)
 {
     QualityStrategy   = qualityStrategy;
     ShelfLifeStrategy = shelfLifeStrategy;
 }