Ejemplo n.º 1
0
        /// <summary>
        /// Get the Supplies converting the Price into AUD given the exchange rate
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Supply> GetPriceInAUD()
        {
            // Check if the file exists before perfoming any operation
            if (!File.Exists(_filePath))
            {
                return(new List <Supply>());
            }

            // Read the file from the provided path
            var suppliesFromSource = FetchFromSource();

            // Check if there is a conversion required
            var requiresConversion = _currencyType != CurrencyType.AUD;

            if (requiresConversion)
            {
                // You cant perform Calculation on an IEnumerable (properties are Readonly)
                // pull it in memory only if there is a conversion required.
                suppliesFromSource = suppliesFromSource.ToList();

                foreach (var supply in suppliesFromSource)
                {
                    supply.PriceInAUD = PriceConverter.GetConvertedPrice(supply.PriceInDollar, _conversionRate);
                }
            }

            return(suppliesFromSource);
        }
Ejemplo n.º 2
0
        public void Is_Valid_Conversion()
        {
            // Arrage
            var price          = 200;
            var exchangeRate   = 0.7m;
            var expectedOutput = 140.0m;
            // Act
            var converterValue = PriceConverter.GetConvertedPrice(price, exchangeRate);

            // Assert
            Assert.AreEqual(converterValue, expectedOutput);
        }