Exemple #1
0
        public void GetPricingStrategy_WhenSupplyRandomAndDemandLow_ShouldReturn5PerLess()
        {
            //Arrange
            double itemPrice = 10.0;
            var    manager = new PricingStrategyManager();
            char   supply = 'R', demand = 'L';
            double expectedResult = 11;

            //Act
            var obj = manager.GetPricingStrategy(supply, demand);
        }
Exemple #2
0
        public void GetPricingStrategy_GetCalled_ShouldReturnIPrcingStrategyType()
        {
            //Arrange
            var  manager = new PricingStrategyManager();
            char supply = 'H', demand = 'H';

            //Act
            var obj = manager.GetPricingStrategy(supply, demand);

            //Assert
            Assert.IsInstanceOfType(obj, obj.GetType());
        }
Exemple #3
0
        public void GetPricingStrategy_WhenSupplyLowAndDemandLow_ShouldReturn10PerMore()
        {
            //Arrange
            double itemPrice = 10.0;
            var    manager = new PricingStrategyManager();
            char   supply = 'L', demand = 'L';
            double expectedResult = 11;

            //Act
            var    obj          = manager.GetPricingStrategy(supply, demand);
            double actualResult = obj.GetPrice(itemPrice);

            //Assert
            Assert.AreEqual(expectedResult, actualResult, "On High Supply and High demand value should be same as price.");
        }
Exemple #4
0
        public static void Main()
        {
            Console.WriteLine("Input:");
            var strategyManager = new PricingStrategyManager();
            //Enter # of Products for which price to be find
            int noOfProducts = Convert.ToInt32(Console.ReadLine());

            //Add Product,  Supply and Demand
            List <Item> itemList = new List <Item>();

            for (int i = 0; i < noOfProducts; i++)
            {
                string command = Console.ReadLine();
                if (string.IsNullOrEmpty(command))
                {
                    throw new ArgumentNullException("command", "Command is not valid");
                }

                string[] commandSplit = command.Split(' ');

                if (commandSplit.Length == 3)
                {
                    char supply          = commandSplit[1][0];
                    char demand          = commandSplit[2][0];
                    var  pricingStrategy = strategyManager.GetPricingStrategy(supply, demand);
                    var  item            = new Item(pricingStrategy)
                    {
                        Name = commandSplit[0]
                    };
                    itemList.Add(item);
                }
            }

            int noOfSurveys = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < noOfSurveys; i++)
            {
                string command = Console.ReadLine();
                if (string.IsNullOrEmpty(command))
                {
                    throw new ArgumentNullException("command", "Command is not valid");
                }

                string[] commandSplit = command.Split(' ');

                if (commandSplit.Length == 3)
                {
                    string itemName    = commandSplit[0];
                    string surveyName  = commandSplit[1];
                    double surveyPrice = Convert.ToDouble(commandSplit[2]);
                    var    product     = itemList.FirstOrDefault(x => x.Name == itemName);
                    if (product != null)
                    {
                        product.AddSurvey(new ItemSurvey()
                        {
                            ItemName = itemName, Price = surveyPrice, SurveyName = surveyName
                        });
                    }
                }
            }

            Console.WriteLine("Output:");
            itemList.ForEach(x => { Console.WriteLine("{0} {1}", x.Name, x.Price); });
            Console.ReadLine();
        }